@renovatebot/good-enough-parser 1.1.24 → 2.0.0
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/README.md +6 -6
- package/dist/cjs/index.d.ts +4 -4
- package/dist/cjs/index.js +7 -7
- package/dist/cjs/lang/groovy.d.ts +6 -6
- package/dist/cjs/lang/groovy.js +83 -83
- package/dist/cjs/lang/index.d.ts +20 -20
- package/dist/cjs/lang/index.js +56 -56
- package/dist/cjs/lang/index.js.map +1 -1
- package/dist/cjs/lang/python.d.ts +6 -6
- package/dist/cjs/lang/python.js +73 -73
- package/dist/cjs/lang/scala.d.ts +6 -6
- package/dist/cjs/lang/scala.js +71 -71
- package/dist/cjs/lang/starlark.d.ts +6 -6
- package/dist/cjs/lang/starlark.js +58 -58
- package/dist/cjs/lang/types.d.ts +6 -6
- package/dist/cjs/lang/types.js +2 -2
- package/dist/cjs/lexer/bracket.d.ts +6 -6
- package/dist/cjs/lexer/bracket.js +56 -57
- package/dist/cjs/lexer/bracket.js.map +1 -1
- package/dist/cjs/lexer/comment.d.ts +3 -3
- package/dist/cjs/lexer/comment.js +43 -44
- package/dist/cjs/lexer/comment.js.map +1 -1
- package/dist/cjs/lexer/index.d.ts +5 -5
- package/dist/cjs/lexer/index.js +154 -155
- package/dist/cjs/lexer/index.js.map +1 -1
- package/dist/cjs/lexer/number.d.ts +2 -2
- package/dist/cjs/lexer/number.js +17 -18
- package/dist/cjs/lexer/number.js.map +1 -1
- package/dist/cjs/lexer/operator.d.ts +2 -2
- package/dist/cjs/lexer/operator.js +23 -24
- package/dist/cjs/lexer/operator.js.map +1 -1
- package/dist/cjs/lexer/rules.d.ts +4 -4
- package/dist/cjs/lexer/rules.js +74 -74
- package/dist/cjs/lexer/rules.js.map +1 -1
- package/dist/cjs/lexer/string.d.ts +2 -2
- package/dist/cjs/lexer/string.js +180 -181
- package/dist/cjs/lexer/string.js.map +1 -1
- package/dist/cjs/lexer/symbol.d.ts +2 -2
- package/dist/cjs/lexer/symbol.js +17 -18
- package/dist/cjs/lexer/symbol.js.map +1 -1
- package/dist/cjs/lexer/token.d.ts +3 -3
- package/dist/cjs/lexer/token.js +63 -64
- package/dist/cjs/lexer/token.js.map +1 -1
- package/dist/cjs/lexer/types.d.ts +142 -142
- package/dist/cjs/lexer/types.js +2 -2
- package/dist/cjs/parser/cursor.d.ts +2 -2
- package/dist/cjs/parser/cursor.js +12 -13
- package/dist/cjs/parser/cursor.js.map +1 -1
- package/dist/cjs/parser/index.d.ts +3 -3
- package/dist/cjs/parser/index.js +19 -19
- package/dist/cjs/parser/tree.d.ts +4 -4
- package/dist/cjs/parser/tree.js +245 -246
- package/dist/cjs/parser/tree.js.map +1 -1
- package/dist/cjs/parser/types.d.ts +33 -33
- package/dist/cjs/parser/types.js +2 -2
- package/dist/cjs/query/builder.d.ts +144 -144
- package/dist/cjs/query/builder.d.ts.map +1 -1
- package/dist/cjs/query/builder.js +333 -332
- package/dist/cjs/query/builder.js.map +1 -1
- package/dist/cjs/query/handler.d.ts +2 -2
- package/dist/cjs/query/handler.js +9 -10
- package/dist/cjs/query/handler.js.map +1 -1
- package/dist/cjs/query/index.d.ts +2 -2
- package/dist/cjs/query/index.js +32 -32
- package/dist/cjs/query/matchers/abstract-matcher.d.ts +9 -9
- package/dist/cjs/query/matchers/abstract-matcher.js +36 -36
- package/dist/cjs/query/matchers/abstract-matcher.js.map +1 -1
- package/dist/cjs/query/matchers/alt-matcher.d.ts +10 -10
- package/dist/cjs/query/matchers/alt-matcher.js +33 -33
- package/dist/cjs/query/matchers/alt-matcher.js.map +1 -1
- package/dist/cjs/query/matchers/anchor-matcher.d.ts +17 -17
- package/dist/cjs/query/matchers/anchor-matcher.js +50 -50
- package/dist/cjs/query/matchers/anchor-matcher.js.map +1 -1
- package/dist/cjs/query/matchers/comment-matcher.d.ts +10 -10
- package/dist/cjs/query/matchers/comment-matcher.js +39 -39
- package/dist/cjs/query/matchers/comment-matcher.js.map +1 -1
- package/dist/cjs/query/matchers/index.d.ts +6 -6
- package/dist/cjs/query/matchers/index.js +22 -22
- package/dist/cjs/query/matchers/many-matcher.d.ts +13 -13
- package/dist/cjs/query/matchers/many-matcher.js +61 -61
- package/dist/cjs/query/matchers/many-matcher.js.map +1 -1
- package/dist/cjs/query/matchers/num-matcher.d.ts +8 -8
- package/dist/cjs/query/matchers/num-matcher.js +34 -34
- package/dist/cjs/query/matchers/num-matcher.js.map +1 -1
- package/dist/cjs/query/matchers/op-matcher.d.ts +8 -8
- package/dist/cjs/query/matchers/op-matcher.js +34 -34
- package/dist/cjs/query/matchers/op-matcher.js.map +1 -1
- package/dist/cjs/query/matchers/seq-matcher.d.ts +14 -14
- package/dist/cjs/query/matchers/seq-matcher.js +76 -76
- package/dist/cjs/query/matchers/seq-matcher.js.map +1 -1
- package/dist/cjs/query/matchers/str-matcher.d.ts +38 -38
- package/dist/cjs/query/matchers/str-matcher.js +108 -108
- package/dist/cjs/query/matchers/str-matcher.js.map +1 -1
- package/dist/cjs/query/matchers/sym-matcher.d.ts +8 -8
- package/dist/cjs/query/matchers/sym-matcher.js +34 -34
- package/dist/cjs/query/matchers/sym-matcher.js.map +1 -1
- package/dist/cjs/query/matchers/tree-matcher.d.ts +23 -23
- package/dist/cjs/query/matchers/tree-matcher.js +121 -121
- package/dist/cjs/query/matchers/tree-matcher.js.map +1 -1
- package/dist/cjs/query/options.d.ts +10 -10
- package/dist/cjs/query/options.js +148 -149
- package/dist/cjs/query/options.js.map +1 -1
- package/dist/cjs/query/regex.d.ts +1 -1
- package/dist/cjs/query/regex.js +12 -13
- package/dist/cjs/query/regex.js.map +1 -1
- package/dist/cjs/query/types.d.ts +100 -100
- package/dist/cjs/query/types.d.ts.map +1 -1
- package/dist/cjs/query/types.js +2 -2
- package/dist/cjs/util/clone.d.ts +1 -1
- package/dist/cjs/util/clone.js +5 -5
- package/dist/cjs/util/regex.d.ts +1 -1
- package/dist/cjs/util/regex.js +6 -7
- package/dist/cjs/util/regex.js.map +1 -1
- package/dist/esm/index.d.ts +4 -4
- package/dist/esm/index.js +8 -8
- package/dist/esm/lang/groovy.d.ts +6 -6
- package/dist/esm/lang/groovy.js +80 -80
- package/dist/esm/lang/index.d.ts +20 -20
- package/dist/esm/lang/index.js +37 -37
- package/dist/esm/lang/python.d.ts +6 -6
- package/dist/esm/lang/python.js +70 -70
- package/dist/esm/lang/scala.d.ts +6 -6
- package/dist/esm/lang/scala.js +68 -68
- package/dist/esm/lang/starlark.d.ts +6 -6
- package/dist/esm/lang/starlark.js +55 -55
- package/dist/esm/lang/types.d.ts +6 -6
- package/dist/esm/lang/types.js +1 -1
- package/dist/esm/lexer/bracket.d.ts +6 -6
- package/dist/esm/lexer/bracket.js +49 -49
- package/dist/esm/lexer/bracket.js.map +1 -1
- package/dist/esm/lexer/comment.d.ts +3 -3
- package/dist/esm/lexer/comment.js +39 -39
- package/dist/esm/lexer/comment.js.map +1 -1
- package/dist/esm/lexer/index.d.ts +5 -5
- package/dist/esm/lexer/index.js +136 -136
- package/dist/esm/lexer/index.js.map +1 -1
- package/dist/esm/lexer/number.d.ts +2 -2
- package/dist/esm/lexer/number.js +14 -14
- package/dist/esm/lexer/operator.d.ts +2 -2
- package/dist/esm/lexer/operator.js +20 -20
- package/dist/esm/lexer/rules.d.ts +4 -4
- package/dist/esm/lexer/rules.js +69 -69
- package/dist/esm/lexer/rules.js.map +1 -1
- package/dist/esm/lexer/string.d.ts +2 -2
- package/dist/esm/lexer/string.js +177 -177
- package/dist/esm/lexer/string.js.map +1 -1
- package/dist/esm/lexer/symbol.d.ts +2 -2
- package/dist/esm/lexer/symbol.js +14 -14
- package/dist/esm/lexer/token.d.ts +3 -3
- package/dist/esm/lexer/token.js +60 -60
- package/dist/esm/lexer/token.js.map +1 -1
- package/dist/esm/lexer/types.d.ts +142 -142
- package/dist/esm/lexer/types.js +1 -1
- package/dist/esm/parser/cursor.d.ts +2 -2
- package/dist/esm/parser/cursor.js +9 -9
- package/dist/esm/parser/index.d.ts +3 -3
- package/dist/esm/parser/index.js +3 -3
- package/dist/esm/parser/tree.d.ts +4 -4
- package/dist/esm/parser/tree.js +241 -241
- package/dist/esm/parser/tree.js.map +1 -1
- package/dist/esm/parser/types.d.ts +33 -33
- package/dist/esm/parser/types.js +1 -1
- package/dist/esm/query/builder.d.ts +144 -144
- package/dist/esm/query/builder.d.ts.map +1 -1
- package/dist/esm/query/builder.js +305 -304
- package/dist/esm/query/builder.js.map +1 -1
- package/dist/esm/query/handler.d.ts +2 -2
- package/dist/esm/query/handler.js +6 -6
- package/dist/esm/query/index.d.ts +2 -2
- package/dist/esm/query/index.js +2 -2
- package/dist/esm/query/matchers/abstract-matcher.d.ts +9 -9
- package/dist/esm/query/matchers/abstract-matcher.js +32 -32
- package/dist/esm/query/matchers/abstract-matcher.js.map +1 -1
- package/dist/esm/query/matchers/alt-matcher.d.ts +10 -10
- package/dist/esm/query/matchers/alt-matcher.js +29 -29
- package/dist/esm/query/matchers/alt-matcher.js.map +1 -1
- package/dist/esm/query/matchers/anchor-matcher.d.ts +17 -17
- package/dist/esm/query/matchers/anchor-matcher.js +44 -44
- package/dist/esm/query/matchers/anchor-matcher.js.map +1 -1
- package/dist/esm/query/matchers/comment-matcher.d.ts +10 -10
- package/dist/esm/query/matchers/comment-matcher.js +35 -35
- package/dist/esm/query/matchers/comment-matcher.js.map +1 -1
- package/dist/esm/query/matchers/index.d.ts +6 -6
- package/dist/esm/query/matchers/index.js +6 -6
- package/dist/esm/query/matchers/many-matcher.d.ts +13 -13
- package/dist/esm/query/matchers/many-matcher.js +57 -57
- package/dist/esm/query/matchers/many-matcher.js.map +1 -1
- package/dist/esm/query/matchers/num-matcher.d.ts +8 -8
- package/dist/esm/query/matchers/num-matcher.js +30 -30
- package/dist/esm/query/matchers/num-matcher.js.map +1 -1
- package/dist/esm/query/matchers/op-matcher.d.ts +8 -8
- package/dist/esm/query/matchers/op-matcher.js +30 -30
- package/dist/esm/query/matchers/op-matcher.js.map +1 -1
- package/dist/esm/query/matchers/seq-matcher.d.ts +14 -14
- package/dist/esm/query/matchers/seq-matcher.js +72 -72
- package/dist/esm/query/matchers/seq-matcher.js.map +1 -1
- package/dist/esm/query/matchers/str-matcher.d.ts +38 -38
- package/dist/esm/query/matchers/str-matcher.js +102 -102
- package/dist/esm/query/matchers/str-matcher.js.map +1 -1
- package/dist/esm/query/matchers/sym-matcher.d.ts +8 -8
- package/dist/esm/query/matchers/sym-matcher.js +30 -30
- package/dist/esm/query/matchers/sym-matcher.js.map +1 -1
- package/dist/esm/query/matchers/tree-matcher.d.ts +23 -23
- package/dist/esm/query/matchers/tree-matcher.js +117 -117
- package/dist/esm/query/matchers/tree-matcher.js.map +1 -1
- package/dist/esm/query/options.d.ts +10 -10
- package/dist/esm/query/options.js +139 -139
- package/dist/esm/query/options.js.map +1 -1
- package/dist/esm/query/regex.d.ts +1 -1
- package/dist/esm/query/regex.js +9 -9
- package/dist/esm/query/regex.js.map +1 -1
- package/dist/esm/query/types.d.ts +100 -100
- package/dist/esm/query/types.d.ts.map +1 -1
- package/dist/esm/query/types.js +1 -1
- package/dist/esm/util/clone.d.ts +1 -1
- package/dist/esm/util/clone.js +1 -1
- package/dist/esm/util/regex.d.ts +1 -1
- package/dist/esm/util/regex.js +3 -3
- package/package.json +42 -46
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
export function esc(input) {
|
|
2
|
-
return input.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&');
|
|
3
|
-
}
|
|
4
|
-
export function configComments(states, opts) {
|
|
5
|
-
const commentRules = {};
|
|
6
|
-
opts.forEach((option, idx) => {
|
|
7
|
-
const tokenName = `comment$${idx}`;
|
|
8
|
-
const start = esc(option.startsWith);
|
|
9
|
-
if (option.type === 'line-comment') {
|
|
10
|
-
const anyChars = '.*?';
|
|
11
|
-
const rule = {
|
|
12
|
-
t: 'regex',
|
|
13
|
-
type: tokenName,
|
|
14
|
-
match: new RegExp(`${start}${anyChars}$`),
|
|
15
|
-
chunk: option.startsWith,
|
|
16
|
-
};
|
|
17
|
-
commentRules[tokenName] = rule;
|
|
18
|
-
}
|
|
19
|
-
else if (option.type === 'multiline-comment') {
|
|
20
|
-
const anyChars = '[^]*?';
|
|
21
|
-
const end = esc(option.endsWith);
|
|
22
|
-
const rule = {
|
|
23
|
-
t: 'regex',
|
|
24
|
-
type: tokenName,
|
|
25
|
-
match: new RegExp(`${start}${anyChars}${end}`),
|
|
26
|
-
lineBreaks: true,
|
|
27
|
-
chunk: option.startsWith,
|
|
28
|
-
};
|
|
29
|
-
commentRules[tokenName] = rule;
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
return {
|
|
33
|
-
...states,
|
|
34
|
-
$: {
|
|
35
|
-
...states.$,
|
|
36
|
-
...commentRules,
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
}
|
|
1
|
+
export function esc(input) {
|
|
2
|
+
return input.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&');
|
|
3
|
+
}
|
|
4
|
+
export function configComments(states, opts) {
|
|
5
|
+
const commentRules = {};
|
|
6
|
+
opts.forEach((option, idx) => {
|
|
7
|
+
const tokenName = `comment$${idx}`;
|
|
8
|
+
const start = esc(option.startsWith);
|
|
9
|
+
if (option.type === 'line-comment') {
|
|
10
|
+
const anyChars = '.*?';
|
|
11
|
+
const rule = {
|
|
12
|
+
t: 'regex',
|
|
13
|
+
type: tokenName,
|
|
14
|
+
match: new RegExp(`${start}${anyChars}$`),
|
|
15
|
+
chunk: option.startsWith,
|
|
16
|
+
};
|
|
17
|
+
commentRules[tokenName] = rule;
|
|
18
|
+
}
|
|
19
|
+
else if (option.type === 'multiline-comment') {
|
|
20
|
+
const anyChars = '[^]*?';
|
|
21
|
+
const end = esc(option.endsWith);
|
|
22
|
+
const rule = {
|
|
23
|
+
t: 'regex',
|
|
24
|
+
type: tokenName,
|
|
25
|
+
match: new RegExp(`${start}${anyChars}${end}`),
|
|
26
|
+
lineBreaks: true,
|
|
27
|
+
chunk: option.startsWith,
|
|
28
|
+
};
|
|
29
|
+
commentRules[tokenName] = rule;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
...states,
|
|
34
|
+
$: {
|
|
35
|
+
...states.$,
|
|
36
|
+
...commentRules,
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
40
|
//# sourceMappingURL=comment.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comment.js","sourceRoot":"","sources":["../../../lib/lexer/comment.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,GAAG,CAAC,KAAa;IAC/B,OAAO,KAAK,CAAC,OAAO,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,MAAiB,EACjB,IAAqB;IAErB,MAAM,YAAY,GAAoB,EAAE,CAAC;IACzC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;QAC3B,MAAM,SAAS,GAAG,WAAW,GAAG,EAAE,CAAC;QACnC,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACrC,IAAI,MAAM,CAAC,IAAI,KAAK,cAAc,EAAE;
|
|
1
|
+
{"version":3,"file":"comment.js","sourceRoot":"","sources":["../../../lib/lexer/comment.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,GAAG,CAAC,KAAa;IAC/B,OAAO,KAAK,CAAC,OAAO,CAAC,uBAAuB,EAAE,MAAM,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,MAAiB,EACjB,IAAqB;IAErB,MAAM,YAAY,GAAoB,EAAE,CAAC;IACzC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;QAC3B,MAAM,SAAS,GAAG,WAAW,GAAG,EAAE,CAAC;QACnC,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACrC,IAAI,MAAM,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;YACnC,MAAM,QAAQ,GAAG,KAAK,CAAC;YACvB,MAAM,IAAI,GAAc;gBACtB,CAAC,EAAE,OAAO;gBACV,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE,IAAI,MAAM,CAAC,GAAG,KAAK,GAAG,QAAQ,GAAG,CAAC;gBACzC,KAAK,EAAE,MAAM,CAAC,UAAU;aACzB,CAAC;YACF,YAAY,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC;QACjC,CAAC;aAAM,IAAI,MAAM,CAAC,IAAI,KAAK,mBAAmB,EAAE,CAAC;YAC/C,MAAM,QAAQ,GAAG,OAAO,CAAC;YACzB,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YACjC,MAAM,IAAI,GAAc;gBACtB,CAAC,EAAE,OAAO;gBACV,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE,IAAI,MAAM,CAAC,GAAG,KAAK,GAAG,QAAQ,GAAG,GAAG,EAAE,CAAC;gBAC9C,UAAU,EAAE,IAAI;gBAChB,KAAK,EAAE,MAAM,CAAC,UAAU;aACzB,CAAC;YACF,YAAY,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC;QACjC,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,MAAM;QACT,CAAC,EAAE;YACD,GAAG,MAAM,CAAC,CAAC;YACX,GAAG,YAAY;SAChB;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Lexer, LexerConfig, OrderedStatesMap } from './types';
|
|
2
|
-
export * from './token';
|
|
3
|
-
export * from './types';
|
|
4
|
-
export declare function configureLexerRules(lexerConfig: LexerConfig): OrderedStatesMap;
|
|
5
|
-
export declare function createLexer(options: LexerConfig): Lexer;
|
|
1
|
+
import type { Lexer, LexerConfig, OrderedStatesMap } from './types';
|
|
2
|
+
export * from './token';
|
|
3
|
+
export * from './types';
|
|
4
|
+
export declare function configureLexerRules(lexerConfig: LexerConfig): OrderedStatesMap;
|
|
5
|
+
export declare function createLexer(options: LexerConfig): Lexer;
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/lexer/index.js
CHANGED
|
@@ -1,137 +1,137 @@
|
|
|
1
|
-
import { compile as mooCompile, states as mooStates, } from 'moo';
|
|
2
|
-
import { configBrackets } from './bracket';
|
|
3
|
-
import { configComments } from './comment';
|
|
4
|
-
import { configNumbers } from './number';
|
|
5
|
-
import { configOperators } from './operator';
|
|
6
|
-
import { createOrderedStateMap, fallbackRule } from './rules';
|
|
7
|
-
import { configStrings } from './string';
|
|
8
|
-
import { configSymbols } from './symbol';
|
|
9
|
-
import { coerceToken } from './token';
|
|
10
|
-
export * from './token';
|
|
11
|
-
export * from './types';
|
|
12
|
-
export function configureLexerRules(lexerConfig) {
|
|
13
|
-
const whitespace = lexerConfig.joinLines
|
|
14
|
-
? {
|
|
15
|
-
t: 'regex',
|
|
16
|
-
type: 'whitespace',
|
|
17
|
-
match: new RegExp(`(?:${lexerConfig.joinLines}\\r?\\n|[ \\t\\r])+`),
|
|
18
|
-
lineBreaks: true,
|
|
19
|
-
chunk: null,
|
|
20
|
-
}
|
|
21
|
-
: {
|
|
22
|
-
t: 'regex',
|
|
23
|
-
type: 'whitespace',
|
|
24
|
-
match: /[ \t\r]+/,
|
|
25
|
-
chunk: null,
|
|
26
|
-
};
|
|
27
|
-
let result = {
|
|
28
|
-
$: {
|
|
29
|
-
whitespace,
|
|
30
|
-
newline: {
|
|
31
|
-
t: 'regex',
|
|
32
|
-
type: 'newline',
|
|
33
|
-
match: /\r?\n/,
|
|
34
|
-
chunk: null,
|
|
35
|
-
lineBreaks: true,
|
|
36
|
-
},
|
|
37
|
-
_: { ...fallbackRule, type: '_' },
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
const { comments, symbols, operators, brackets, strings, numbers } = lexerConfig;
|
|
41
|
-
result = configComments(result, comments);
|
|
42
|
-
result = configSymbols(result, { match: symbols });
|
|
43
|
-
result = configOperators(result, operators);
|
|
44
|
-
result = configBrackets(result, brackets);
|
|
45
|
-
result = configStrings(result, strings);
|
|
46
|
-
result = configNumbers(result, { match: numbers });
|
|
47
|
-
const orderedResult = createOrderedStateMap(result);
|
|
48
|
-
return orderedResult;
|
|
49
|
-
}
|
|
50
|
-
function isVarToken(key) {
|
|
51
|
-
return typeof key === 'string' && /^str\$\d+\$tpl\$\d+\$token$/.test(key);
|
|
52
|
-
}
|
|
53
|
-
function getVarEndToken({ type, value, offset, line, col, lineBreaks, }) {
|
|
54
|
-
return {
|
|
55
|
-
type: type === null || type === void 0 ? void 0 : type.replace(/\$[^$]+$/, '$end'),
|
|
56
|
-
value: '',
|
|
57
|
-
text: '',
|
|
58
|
-
offset: offset + value.length,
|
|
59
|
-
line: line + lineBreaks,
|
|
60
|
-
col: col + value.length,
|
|
61
|
-
lineBreaks: 0,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
function getSubLexers(states) {
|
|
65
|
-
const result = {};
|
|
66
|
-
for (const [key, rules] of Object.entries(states)) {
|
|
67
|
-
if (isVarToken(key)) {
|
|
68
|
-
result[key] = mooCompile(rules);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return result;
|
|
72
|
-
}
|
|
73
|
-
export function createLexer(options) {
|
|
74
|
-
const rules = configureLexerRules(options);
|
|
75
|
-
const subLexers = getSubLexers(rules);
|
|
76
|
-
const mainLexer = mooStates(rules);
|
|
77
|
-
let subLexer;
|
|
78
|
-
let subLexerToken;
|
|
79
|
-
const result = {
|
|
80
|
-
reset(input) {
|
|
81
|
-
Object.values(subLexers).forEach((subLexer) => subLexer.reset());
|
|
82
|
-
subLexer = undefined;
|
|
83
|
-
subLexerToken = undefined;
|
|
84
|
-
if (typeof input === 'undefined' || input === null) {
|
|
85
|
-
mainLexer.reset();
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
mainLexer.reset(input);
|
|
89
|
-
}
|
|
90
|
-
return result;
|
|
91
|
-
},
|
|
92
|
-
[Symbol.iterator]() {
|
|
93
|
-
const next = () => {
|
|
94
|
-
const mooLexer = subLexer !== null && subLexer !== void 0 ? subLexer : mainLexer;
|
|
95
|
-
const mooIter = mooLexer[Symbol.iterator]();
|
|
96
|
-
const nextElem = mooIter.next();
|
|
97
|
-
if (nextElem.done) {
|
|
98
|
-
if (subLexer && subLexerToken) {
|
|
99
|
-
const subLexerType = subLexerToken.type;
|
|
100
|
-
mooLexer.reset();
|
|
101
|
-
if (isVarToken(subLexerType)) {
|
|
102
|
-
const x = getVarEndToken(subLexerToken);
|
|
103
|
-
const value = coerceToken(x);
|
|
104
|
-
subLexer = undefined;
|
|
105
|
-
subLexerToken = undefined;
|
|
106
|
-
return { done: false, value };
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
subLexer = undefined;
|
|
110
|
-
subLexerToken = undefined;
|
|
111
|
-
return next();
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
return { done: true, value: null };
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
const mooToken = nextElem.value;
|
|
119
|
-
if (!subLexer) {
|
|
120
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
121
|
-
const mooTokenType = mooToken.type;
|
|
122
|
-
subLexer = subLexers[mooTokenType];
|
|
123
|
-
if (subLexer) {
|
|
124
|
-
subLexerToken = mooToken;
|
|
125
|
-
subLexer.reset(mooToken.value);
|
|
126
|
-
return next();
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
const value = coerceToken(mooToken, subLexerToken);
|
|
130
|
-
return { done: false, value };
|
|
131
|
-
};
|
|
132
|
-
return { next };
|
|
133
|
-
},
|
|
134
|
-
};
|
|
135
|
-
return result;
|
|
136
|
-
}
|
|
1
|
+
import { compile as mooCompile, states as mooStates, } from 'moo';
|
|
2
|
+
import { configBrackets } from './bracket';
|
|
3
|
+
import { configComments } from './comment';
|
|
4
|
+
import { configNumbers } from './number';
|
|
5
|
+
import { configOperators } from './operator';
|
|
6
|
+
import { createOrderedStateMap, fallbackRule } from './rules';
|
|
7
|
+
import { configStrings } from './string';
|
|
8
|
+
import { configSymbols } from './symbol';
|
|
9
|
+
import { coerceToken } from './token';
|
|
10
|
+
export * from './token';
|
|
11
|
+
export * from './types';
|
|
12
|
+
export function configureLexerRules(lexerConfig) {
|
|
13
|
+
const whitespace = lexerConfig.joinLines
|
|
14
|
+
? {
|
|
15
|
+
t: 'regex',
|
|
16
|
+
type: 'whitespace',
|
|
17
|
+
match: new RegExp(`(?:${lexerConfig.joinLines}\\r?\\n|[ \\t\\r])+`),
|
|
18
|
+
lineBreaks: true,
|
|
19
|
+
chunk: null,
|
|
20
|
+
}
|
|
21
|
+
: {
|
|
22
|
+
t: 'regex',
|
|
23
|
+
type: 'whitespace',
|
|
24
|
+
match: /[ \t\r]+/,
|
|
25
|
+
chunk: null,
|
|
26
|
+
};
|
|
27
|
+
let result = {
|
|
28
|
+
$: {
|
|
29
|
+
whitespace,
|
|
30
|
+
newline: {
|
|
31
|
+
t: 'regex',
|
|
32
|
+
type: 'newline',
|
|
33
|
+
match: /\r?\n/,
|
|
34
|
+
chunk: null,
|
|
35
|
+
lineBreaks: true,
|
|
36
|
+
},
|
|
37
|
+
_: { ...fallbackRule, type: '_' },
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
const { comments, symbols, operators, brackets, strings, numbers } = lexerConfig;
|
|
41
|
+
result = configComments(result, comments);
|
|
42
|
+
result = configSymbols(result, { match: symbols });
|
|
43
|
+
result = configOperators(result, operators);
|
|
44
|
+
result = configBrackets(result, brackets);
|
|
45
|
+
result = configStrings(result, strings);
|
|
46
|
+
result = configNumbers(result, { match: numbers });
|
|
47
|
+
const orderedResult = createOrderedStateMap(result);
|
|
48
|
+
return orderedResult;
|
|
49
|
+
}
|
|
50
|
+
function isVarToken(key) {
|
|
51
|
+
return typeof key === 'string' && /^str\$\d+\$tpl\$\d+\$token$/.test(key);
|
|
52
|
+
}
|
|
53
|
+
function getVarEndToken({ type, value, offset, line, col, lineBreaks, }) {
|
|
54
|
+
return {
|
|
55
|
+
type: type === null || type === void 0 ? void 0 : type.replace(/\$[^$]+$/, '$end'),
|
|
56
|
+
value: '',
|
|
57
|
+
text: '',
|
|
58
|
+
offset: offset + value.length,
|
|
59
|
+
line: line + lineBreaks,
|
|
60
|
+
col: col + value.length,
|
|
61
|
+
lineBreaks: 0,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function getSubLexers(states) {
|
|
65
|
+
const result = {};
|
|
66
|
+
for (const [key, rules] of Object.entries(states)) {
|
|
67
|
+
if (isVarToken(key)) {
|
|
68
|
+
result[key] = mooCompile(rules);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
export function createLexer(options) {
|
|
74
|
+
const rules = configureLexerRules(options);
|
|
75
|
+
const subLexers = getSubLexers(rules);
|
|
76
|
+
const mainLexer = mooStates(rules);
|
|
77
|
+
let subLexer;
|
|
78
|
+
let subLexerToken;
|
|
79
|
+
const result = {
|
|
80
|
+
reset(input) {
|
|
81
|
+
Object.values(subLexers).forEach((subLexer) => subLexer.reset());
|
|
82
|
+
subLexer = undefined;
|
|
83
|
+
subLexerToken = undefined;
|
|
84
|
+
if (typeof input === 'undefined' || input === null) {
|
|
85
|
+
mainLexer.reset();
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
mainLexer.reset(input);
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
},
|
|
92
|
+
[Symbol.iterator]() {
|
|
93
|
+
const next = () => {
|
|
94
|
+
const mooLexer = subLexer !== null && subLexer !== void 0 ? subLexer : mainLexer;
|
|
95
|
+
const mooIter = mooLexer[Symbol.iterator]();
|
|
96
|
+
const nextElem = mooIter.next();
|
|
97
|
+
if (nextElem.done) {
|
|
98
|
+
if (subLexer && subLexerToken) {
|
|
99
|
+
const subLexerType = subLexerToken.type;
|
|
100
|
+
mooLexer.reset();
|
|
101
|
+
if (isVarToken(subLexerType)) {
|
|
102
|
+
const x = getVarEndToken(subLexerToken);
|
|
103
|
+
const value = coerceToken(x);
|
|
104
|
+
subLexer = undefined;
|
|
105
|
+
subLexerToken = undefined;
|
|
106
|
+
return { done: false, value };
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
subLexer = undefined;
|
|
110
|
+
subLexerToken = undefined;
|
|
111
|
+
return next();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
return { done: true, value: null };
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const mooToken = nextElem.value;
|
|
119
|
+
if (!subLexer) {
|
|
120
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
121
|
+
const mooTokenType = mooToken.type;
|
|
122
|
+
subLexer = subLexers[mooTokenType];
|
|
123
|
+
if (subLexer) {
|
|
124
|
+
subLexerToken = mooToken;
|
|
125
|
+
subLexer.reset(mooToken.value);
|
|
126
|
+
return next();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const value = coerceToken(mooToken, subLexerToken);
|
|
130
|
+
return { done: false, value };
|
|
131
|
+
};
|
|
132
|
+
return { next };
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
137
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/lexer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,OAAO,IAAI,UAAU,EACrB,MAAM,IAAI,SAAS,GACpB,MAAM,KAAK,CAAC;AACb,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,O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EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;YAChC,CAAC,CAAC;YAEF,OAAO,EAAE,IAAI,EAAE,CAAC;QAClB,CAAC;KACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { NumberOption, StatesMap } from './types';
|
|
2
|
-
export declare function configNumbers(states: StatesMap, { match }: NumberOption): StatesMap;
|
|
1
|
+
import type { NumberOption, StatesMap } from './types';
|
|
2
|
+
export declare function configNumbers(states: StatesMap, { match }: NumberOption): StatesMap;
|
|
3
3
|
//# sourceMappingURL=number.d.ts.map
|
package/dist/esm/lexer/number.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export function configNumbers(states, { match }) {
|
|
2
|
-
return {
|
|
3
|
-
...states,
|
|
4
|
-
$: {
|
|
5
|
-
...states.$,
|
|
6
|
-
number: {
|
|
7
|
-
t: 'regex',
|
|
8
|
-
type: 'number',
|
|
9
|
-
match,
|
|
10
|
-
chunk: null,
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
}
|
|
1
|
+
export function configNumbers(states, { match }) {
|
|
2
|
+
return {
|
|
3
|
+
...states,
|
|
4
|
+
$: {
|
|
5
|
+
...states.$,
|
|
6
|
+
number: {
|
|
7
|
+
t: 'regex',
|
|
8
|
+
type: 'number',
|
|
9
|
+
match,
|
|
10
|
+
chunk: null,
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
15
|
//# sourceMappingURL=number.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { OperatorOption, StatesMap } from './types';
|
|
2
|
-
export declare function configOperators(states: StatesMap, operators: OperatorOption[]): StatesMap;
|
|
1
|
+
import type { OperatorOption, StatesMap } from './types';
|
|
2
|
+
export declare function configOperators(states: StatesMap, operators: OperatorOption[]): StatesMap;
|
|
3
3
|
//# sourceMappingURL=operator.d.ts.map
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
export function configOperators(states, operators) {
|
|
2
|
-
const operatorRules = {};
|
|
3
|
-
operators.map((op, idx) => {
|
|
4
|
-
const tokenName = `op$${idx}`;
|
|
5
|
-
const tokenRule = {
|
|
6
|
-
t: 'string',
|
|
7
|
-
type: tokenName,
|
|
8
|
-
match: op,
|
|
9
|
-
chunk: op,
|
|
10
|
-
};
|
|
11
|
-
operatorRules[tokenName] = tokenRule;
|
|
12
|
-
});
|
|
13
|
-
return {
|
|
14
|
-
...states,
|
|
15
|
-
$: {
|
|
16
|
-
...states.$,
|
|
17
|
-
...operatorRules,
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
}
|
|
1
|
+
export function configOperators(states, operators) {
|
|
2
|
+
const operatorRules = {};
|
|
3
|
+
operators.map((op, idx) => {
|
|
4
|
+
const tokenName = `op$${idx}`;
|
|
5
|
+
const tokenRule = {
|
|
6
|
+
t: 'string',
|
|
7
|
+
type: tokenName,
|
|
8
|
+
match: op,
|
|
9
|
+
chunk: op,
|
|
10
|
+
};
|
|
11
|
+
operatorRules[tokenName] = tokenRule;
|
|
12
|
+
});
|
|
13
|
+
return {
|
|
14
|
+
...states,
|
|
15
|
+
$: {
|
|
16
|
+
...states.$,
|
|
17
|
+
...operatorRules,
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
21
|
//# sourceMappingURL=operator.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { FallbackRule, LexerRule, OrderedStatesMap, StatesMap } from './types';
|
|
2
|
-
export declare const fallbackRule: Omit<FallbackRule, 'type'>;
|
|
3
|
-
export declare function sortLexerRules(state: LexerRule[]): LexerRule[];
|
|
4
|
-
export declare function createOrderedStateMap(statesMap: StatesMap): OrderedStatesMap;
|
|
1
|
+
import type { FallbackRule, LexerRule, OrderedStatesMap, StatesMap } from './types';
|
|
2
|
+
export declare const fallbackRule: Omit<FallbackRule, 'type'>;
|
|
3
|
+
export declare function sortLexerRules(state: LexerRule[]): LexerRule[];
|
|
4
|
+
export declare function createOrderedStateMap(statesMap: StatesMap): OrderedStatesMap;
|
|
5
5
|
//# sourceMappingURL=rules.d.ts.map
|
package/dist/esm/lexer/rules.js
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import { fallback as mooFallback } from 'moo';
|
|
2
|
-
export const fallbackRule = {
|
|
3
|
-
...mooFallback,
|
|
4
|
-
t: 'fallback',
|
|
5
|
-
chunk: null,
|
|
6
|
-
};
|
|
7
|
-
function compareChunksByValue(x, y) {
|
|
8
|
-
if (typeof x.chunk === 'string' && typeof y.chunk === 'string') {
|
|
9
|
-
const xChunk = x.chunk;
|
|
10
|
-
const yChunk = y.chunk;
|
|
11
|
-
if (yChunk < xChunk) {
|
|
12
|
-
return 1;
|
|
13
|
-
}
|
|
14
|
-
else if (xChunk < yChunk) {
|
|
15
|
-
return -1;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return 0;
|
|
19
|
-
}
|
|
20
|
-
function compareChunksByInclusion(x, y) {
|
|
21
|
-
if (typeof x.chunk === 'string' && typeof y.chunk === 'string') {
|
|
22
|
-
const xChunk = x.chunk;
|
|
23
|
-
const yChunk = y.chunk;
|
|
24
|
-
if (yChunk.startsWith(xChunk)) {
|
|
25
|
-
return 1;
|
|
26
|
-
}
|
|
27
|
-
else if (xChunk.startsWith(yChunk)) {
|
|
28
|
-
return -1;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return 0;
|
|
32
|
-
}
|
|
33
|
-
export function sortLexerRules(state) {
|
|
34
|
-
const values = Object.values(state);
|
|
35
|
-
if (values.length < 2) {
|
|
36
|
-
return state;
|
|
37
|
-
}
|
|
38
|
-
const fallbackRules = [];
|
|
39
|
-
const numberRules = [];
|
|
40
|
-
const chunkRules = [];
|
|
41
|
-
const otherRules = [];
|
|
42
|
-
for (const rule of values) {
|
|
43
|
-
if (rule.t === 'fallback') {
|
|
44
|
-
fallbackRules.push(rule);
|
|
45
|
-
}
|
|
46
|
-
else if (rule.type === 'number') {
|
|
47
|
-
numberRules.push(rule);
|
|
48
|
-
}
|
|
49
|
-
else if (typeof rule.chunk === 'string') {
|
|
50
|
-
chunkRules.push(rule);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
otherRules.push(rule);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
chunkRules.sort((x, y) => compareChunksByValue(x, y));
|
|
57
|
-
chunkRules.sort((x, y) => compareChunksByInclusion(x, y));
|
|
58
|
-
const res = [...numberRules, ...chunkRules, ...otherRules, ...fallbackRules];
|
|
59
|
-
return res;
|
|
60
|
-
}
|
|
61
|
-
export function createOrderedStateMap(statesMap) {
|
|
62
|
-
const result = { $: [] };
|
|
63
|
-
for (const [stateName, state] of Object.entries(statesMap)) {
|
|
64
|
-
const stateValues = Object.values(state);
|
|
65
|
-
const orderedStateValues = sortLexerRules(stateValues);
|
|
66
|
-
result[stateName] = orderedStateValues;
|
|
67
|
-
}
|
|
68
|
-
return result;
|
|
69
|
-
}
|
|
1
|
+
import { fallback as mooFallback } from 'moo';
|
|
2
|
+
export const fallbackRule = {
|
|
3
|
+
...mooFallback,
|
|
4
|
+
t: 'fallback',
|
|
5
|
+
chunk: null,
|
|
6
|
+
};
|
|
7
|
+
function compareChunksByValue(x, y) {
|
|
8
|
+
if (typeof x.chunk === 'string' && typeof y.chunk === 'string') {
|
|
9
|
+
const xChunk = x.chunk;
|
|
10
|
+
const yChunk = y.chunk;
|
|
11
|
+
if (yChunk < xChunk) {
|
|
12
|
+
return 1;
|
|
13
|
+
}
|
|
14
|
+
else if (xChunk < yChunk) {
|
|
15
|
+
return -1;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
function compareChunksByInclusion(x, y) {
|
|
21
|
+
if (typeof x.chunk === 'string' && typeof y.chunk === 'string') {
|
|
22
|
+
const xChunk = x.chunk;
|
|
23
|
+
const yChunk = y.chunk;
|
|
24
|
+
if (yChunk.startsWith(xChunk)) {
|
|
25
|
+
return 1;
|
|
26
|
+
}
|
|
27
|
+
else if (xChunk.startsWith(yChunk)) {
|
|
28
|
+
return -1;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
export function sortLexerRules(state) {
|
|
34
|
+
const values = Object.values(state);
|
|
35
|
+
if (values.length < 2) {
|
|
36
|
+
return state;
|
|
37
|
+
}
|
|
38
|
+
const fallbackRules = [];
|
|
39
|
+
const numberRules = [];
|
|
40
|
+
const chunkRules = [];
|
|
41
|
+
const otherRules = [];
|
|
42
|
+
for (const rule of values) {
|
|
43
|
+
if (rule.t === 'fallback') {
|
|
44
|
+
fallbackRules.push(rule);
|
|
45
|
+
}
|
|
46
|
+
else if (rule.type === 'number') {
|
|
47
|
+
numberRules.push(rule);
|
|
48
|
+
}
|
|
49
|
+
else if (typeof rule.chunk === 'string') {
|
|
50
|
+
chunkRules.push(rule);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
otherRules.push(rule);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
chunkRules.sort((x, y) => compareChunksByValue(x, y));
|
|
57
|
+
chunkRules.sort((x, y) => compareChunksByInclusion(x, y));
|
|
58
|
+
const res = [...numberRules, ...chunkRules, ...otherRules, ...fallbackRules];
|
|
59
|
+
return res;
|
|
60
|
+
}
|
|
61
|
+
export function createOrderedStateMap(statesMap) {
|
|
62
|
+
const result = { $: [] };
|
|
63
|
+
for (const [stateName, state] of Object.entries(statesMap)) {
|
|
64
|
+
const stateValues = Object.values(state);
|
|
65
|
+
const orderedStateValues = sortLexerRules(stateValues);
|
|
66
|
+
result[stateName] = orderedStateValues;
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
70
|
//# sourceMappingURL=rules.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules.js","sourceRoot":"","sources":["../../../lib/lexer/rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,WAAW,EAAE,MAAM,KAAK,CAAC;AAQ9C,MAAM,CAAC,MAAM,YAAY,GAA+B;IACtD,GAAG,WAAW;IACd,CAAC,EAAE,UAAU;IACb,KAAK,EAAE,IAAI;CACZ,CAAC;AAEF,SAAS,oBAAoB,CAAC,CAAY,EAAE,CAAY;IACtD,IAAI,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ,EAAE;
|
|
1
|
+
{"version":3,"file":"rules.js","sourceRoot":"","sources":["../../../lib/lexer/rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,WAAW,EAAE,MAAM,KAAK,CAAC;AAQ9C,MAAM,CAAC,MAAM,YAAY,GAA+B;IACtD,GAAG,WAAW;IACd,CAAC,EAAE,UAAU;IACb,KAAK,EAAE,IAAI;CACZ,CAAC;AAEF,SAAS,oBAAoB,CAAC,CAAY,EAAE,CAAY;IACtD,IAAI,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC/D,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC;QACvB,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC;QACvB,IAAI,MAAM,GAAG,MAAM,EAAE,CAAC;YACpB,OAAO,CAAC,CAAC;QACX,CAAC;aAAM,IAAI,MAAM,GAAG,MAAM,EAAE,CAAC;YAC3B,OAAO,CAAC,CAAC,CAAC;QACZ,CAAC;IACH,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,SAAS,wBAAwB,CAAC,CAAY,EAAE,CAAY;IAC1D,IAAI,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;Q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