@mirascript/textmate 0.1.82 → 0.1.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.c8rc.json +6 -0
- package/ava.config.js +4 -0
- package/dist/grammar.d.ts +14 -0
- package/dist/grammar.d.ts.map +1 -0
- package/dist/grammar.js +1129 -0
- package/dist/grammar.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -8
- package/dist/index.js.map +1 -0
- package/dist/language.d.ts +18 -0
- package/dist/language.d.ts.map +1 -0
- package/dist/language.js +15 -0
- package/dist/language.js.map +1 -0
- package/dist/mirascript-doc.tmLanguage.json +477 -86
- package/dist/mirascript-template.tmLanguage.json +422 -277
- package/dist/mirascript.tmLanguage.json +426 -272
- package/package.json +11 -13
- package/src/grammar.ts +1157 -0
- package/src/index.ts +10 -0
- package/src/language.ts +21 -0
- package/tests/_engine.ts +53 -0
- package/tests/grammar/documentation-comments.ts +157 -0
- package/tests/grammar/documentation-mode.ts +372 -0
- package/tests/grammar/language.ts +59 -0
- package/tests/grammar/strings.ts +35 -0
- package/tests/js-compatibility.ts +22 -0
- package/tests/language.ts +9 -0
- package/tests/tsconfig.json +3 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import { tokenize, expectScope } from '../_engine.ts';
|
|
3
|
+
|
|
4
|
+
test('classifies declarations, parameters, properties, calls, and Unicode identifiers', (t) => {
|
|
5
|
+
const tokens = tokenize('mod 数学 { fn 加法(mut 左, ..其余) { 对象.方法(左).属性 } }');
|
|
6
|
+
expectScope(t, tokens, 'mod', 'keyword.control.module.mira');
|
|
7
|
+
expectScope(t, tokens, '数学', 'entity.name.namespace.mira');
|
|
8
|
+
expectScope(t, tokens, '加法', 'entity.name.function.mira');
|
|
9
|
+
expectScope(t, tokens, '左', 'variable.emphasis.mira');
|
|
10
|
+
expectScope(t, tokens, '其余', 'variable.other.constant.emphasis.mira');
|
|
11
|
+
expectScope(t, tokens, '方法', 'entity.name.function.member.mira');
|
|
12
|
+
expectScope(t, tokens, '属性', 'variable.other.property.mira');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('classifies keyword and numeric families', (t) => {
|
|
16
|
+
const tokens = tokenize('if true and value not in global { let @常量 = 0xCA_FE; 1.5e+2 }');
|
|
17
|
+
expectScope(t, tokens, 'if', 'keyword.control.mira');
|
|
18
|
+
expectScope(t, tokens, 'true', 'constant.language.mira');
|
|
19
|
+
expectScope(t, tokens, 'and', 'keyword.operator.wordlike.mira');
|
|
20
|
+
expectScope(t, tokens, 'not', 'keyword.operator.wordlike.mira');
|
|
21
|
+
expectScope(t, tokens, 'in', 'keyword.operator.wordlike.mira');
|
|
22
|
+
expectScope(t, tokens, 'global', 'variable.language.mira');
|
|
23
|
+
expectScope(t, tokens, '@常量', 'variable.other.constant.mira');
|
|
24
|
+
expectScope(t, tokens, '0xCA_FE', 'constant.numeric.hex.mira');
|
|
25
|
+
expectScope(t, tokens, '1.5e+2', 'constant.numeric.float.mira');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('does not classify control keywords followed by parentheses as functions', (t) => {
|
|
29
|
+
const tokens = tokenize('if (condition) { case (value) { call(value) } }');
|
|
30
|
+
expectScope(t, tokens, 'if', 'keyword.control.mira');
|
|
31
|
+
expectScope(t, tokens, 'case', 'keyword.control.mira');
|
|
32
|
+
expectScope(t, tokens, 'call', 'entity.name.function.mira');
|
|
33
|
+
for (const keyword of ['if', 'case']) {
|
|
34
|
+
const token = tokens.find((candidate) => candidate.text === keyword);
|
|
35
|
+
t.false(token!.scopes.includes('entity.name.function.mira'));
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('only classifies type as a keyword in its two contextual forms', (t) => {
|
|
40
|
+
const tokens = tokenize('type(value); type Value; let type = 1; type + 1; object.type(); value::type();');
|
|
41
|
+
expectScope(t, tokens, 'type', 'keyword.operator.expression.mira', 0);
|
|
42
|
+
expectScope(t, tokens, 'type', 'keyword.operator.expression.mira', 1);
|
|
43
|
+
expectScope(t, tokens, 'type', 'variable.other.mira', 2);
|
|
44
|
+
expectScope(t, tokens, 'type', 'variable.other.mira', 3);
|
|
45
|
+
expectScope(t, tokens, 'type', 'entity.name.function.member.mira', 4);
|
|
46
|
+
expectScope(t, tokens, 'type', 'keyword.operator.expression.mira', 5);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('marks invalid numeric and escape sequences', (t) => {
|
|
50
|
+
const tokens = tokenize(String.raw`let a = 0xGG; let b = "\q";`);
|
|
51
|
+
expectScope(t, tokens, '0xGG', 'invalid.illegal.numeric.mira');
|
|
52
|
+
expectScope(t, tokens, String.raw`\q`, 'invalid.illegal.escape.mira');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('keeps multiline rule state', (t) => {
|
|
56
|
+
const tokens = tokenize('/* first\nsecond */\n"first ${\nvalue\n}"');
|
|
57
|
+
expectScope(t, tokens, 'second ', 'comment.block.mira');
|
|
58
|
+
expectScope(t, tokens, 'value', 'variable.other.mira');
|
|
59
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import { tokenize, expectScope } from '../_engine.ts';
|
|
3
|
+
|
|
4
|
+
test('handles nested interpolation and format strings', (t) => {
|
|
5
|
+
const tokens = tokenize('"value ${ if ok { fn_call((1 + 2)) } } / $(value:>8[.]2f)"');
|
|
6
|
+
expectScope(t, tokens, '${', 'punctuation.definition.template-expression.begin.mira');
|
|
7
|
+
expectScope(t, tokens, 'fn_call', 'entity.name.function.mira');
|
|
8
|
+
expectScope(t, tokens, '$(', 'punctuation.definition.template-expression.begin.mira');
|
|
9
|
+
expectScope(t, tokens, ':', 'punctuation.separator.format.mira');
|
|
10
|
+
expectScope(t, tokens, '>8', 'string.unquoted.format.mira');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('matches the exact interpolation width in verbatim strings', (t) => {
|
|
14
|
+
for (const width of [1, 2, 3, 16]) {
|
|
15
|
+
const ats = '@'.repeat(width);
|
|
16
|
+
const dollars = '$'.repeat(width);
|
|
17
|
+
const shorter = '$'.repeat(Math.max(1, width - 1));
|
|
18
|
+
const tokens = tokenize(`${ats}"literal ${shorter}name ${dollars}name"${ats}`);
|
|
19
|
+
expectScope(t, tokens, dollars, 'punctuation.definition.template-expression.begin.mira');
|
|
20
|
+
expectScope(t, tokens, 'name', 'variable.other.mira', width === 1 ? 1 : 0);
|
|
21
|
+
if (width > 1) {
|
|
22
|
+
const literal = tokens.find((token) => token.text.includes(`${shorter}name`));
|
|
23
|
+
t.true(literal!.scopes.includes('string.quoted.double.verbatim.mira'));
|
|
24
|
+
t.false(literal!.scopes.includes('meta.interpolation.simple.mira'));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('highlights template text and embedded MiraScript', (t) => {
|
|
30
|
+
const tokens = tokenize('Hello $name: ${ fn_call(1) }', 'mirascript-template');
|
|
31
|
+
expectScope(t, tokens, 'Hello ', 'string.unquoted.template.mira');
|
|
32
|
+
expectScope(t, tokens, '$', 'punctuation.definition.template-expression.begin.mira');
|
|
33
|
+
expectScope(t, tokens, 'name', 'variable.other.mira');
|
|
34
|
+
expectScope(t, tokens, 'fn_call', 'entity.name.function.mira');
|
|
35
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createHighlighterCore, type HighlighterCore } from 'shiki';
|
|
2
|
+
import { createJavaScriptRegexEngine } from 'shiki/engine-javascript.mjs';
|
|
3
|
+
import test from 'ava';
|
|
4
|
+
import { grammars } from '../src/index.ts';
|
|
5
|
+
|
|
6
|
+
test('grammars can be loaded', async (t) => {
|
|
7
|
+
const highlighter = await createHighlighterCore({
|
|
8
|
+
langs: grammars,
|
|
9
|
+
themes: [],
|
|
10
|
+
engine: createJavaScriptRegexEngine(),
|
|
11
|
+
});
|
|
12
|
+
const mirascript = highlighter.getLanguage('mirascript');
|
|
13
|
+
t.truthy(mirascript);
|
|
14
|
+
|
|
15
|
+
const mirascriptTemplate = highlighter.getLanguage('mirascript-template');
|
|
16
|
+
t.truthy(mirascriptTemplate);
|
|
17
|
+
|
|
18
|
+
const mirascriptDoc = highlighter.getLanguage('mirascript-doc');
|
|
19
|
+
t.truthy(mirascriptDoc);
|
|
20
|
+
|
|
21
|
+
highlighter.dispose();
|
|
22
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import { grammars } from '../src/index.ts';
|
|
3
|
+
import { mirascriptLanguage } from '../src/language.ts';
|
|
4
|
+
|
|
5
|
+
test('uses the shared MiraScript language metadata', (t) => {
|
|
6
|
+
t.is(grammars[0].name, mirascriptLanguage.name);
|
|
7
|
+
t.is(grammars[0].scopeName, mirascriptLanguage.scopeName);
|
|
8
|
+
t.deepEqual(grammars[0].aliases, mirascriptLanguage.aliases);
|
|
9
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
// 如果使用其他版本 TS,使用类似 "extends": "@cloudpss/tsconfig/4.2" 引入
|
|
3
|
+
"extends": "../../tsconfig.json",
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"allowImportingTsExtensions": true,
|
|
6
|
+
"rewriteRelativeImportExtensions": true,
|
|
7
|
+
"sourceMap": true,
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"declarationMap": true
|
|
10
|
+
}
|
|
11
|
+
}
|