@renovatebot/good-enough-parser 1.1.24 → 1.2.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.
Files changed (166) hide show
  1. package/README.md +6 -6
  2. package/dist/cjs/index.d.ts +4 -4
  3. package/dist/cjs/index.js +7 -7
  4. package/dist/cjs/lang/groovy.d.ts +6 -6
  5. package/dist/cjs/lang/groovy.js +83 -83
  6. package/dist/cjs/lang/index.d.ts +20 -20
  7. package/dist/cjs/lang/index.js +56 -56
  8. package/dist/cjs/lang/python.d.ts +6 -6
  9. package/dist/cjs/lang/python.js +73 -73
  10. package/dist/cjs/lang/scala.d.ts +6 -6
  11. package/dist/cjs/lang/scala.js +71 -71
  12. package/dist/cjs/lang/starlark.d.ts +6 -6
  13. package/dist/cjs/lang/starlark.js +58 -58
  14. package/dist/cjs/lang/types.d.ts +6 -6
  15. package/dist/cjs/lang/types.js +2 -2
  16. package/dist/cjs/lexer/bracket.d.ts +6 -6
  17. package/dist/cjs/lexer/bracket.js +57 -57
  18. package/dist/cjs/lexer/comment.d.ts +3 -3
  19. package/dist/cjs/lexer/comment.js +44 -44
  20. package/dist/cjs/lexer/index.d.ts +5 -5
  21. package/dist/cjs/lexer/index.js +155 -155
  22. package/dist/cjs/lexer/number.d.ts +2 -2
  23. package/dist/cjs/lexer/number.js +18 -18
  24. package/dist/cjs/lexer/operator.d.ts +2 -2
  25. package/dist/cjs/lexer/operator.js +24 -24
  26. package/dist/cjs/lexer/rules.d.ts +4 -4
  27. package/dist/cjs/lexer/rules.js +74 -74
  28. package/dist/cjs/lexer/string.d.ts +2 -2
  29. package/dist/cjs/lexer/string.js +181 -181
  30. package/dist/cjs/lexer/symbol.d.ts +2 -2
  31. package/dist/cjs/lexer/symbol.js +18 -18
  32. package/dist/cjs/lexer/token.d.ts +3 -3
  33. package/dist/cjs/lexer/token.js +64 -64
  34. package/dist/cjs/lexer/types.d.ts +142 -142
  35. package/dist/cjs/lexer/types.js +2 -2
  36. package/dist/cjs/parser/cursor.d.ts +2 -2
  37. package/dist/cjs/parser/cursor.js +13 -13
  38. package/dist/cjs/parser/index.d.ts +3 -3
  39. package/dist/cjs/parser/index.js +19 -19
  40. package/dist/cjs/parser/tree.d.ts +4 -4
  41. package/dist/cjs/parser/tree.js +246 -246
  42. package/dist/cjs/parser/types.d.ts +33 -33
  43. package/dist/cjs/parser/types.js +2 -2
  44. package/dist/cjs/query/builder.d.ts +144 -144
  45. package/dist/cjs/query/builder.js +332 -332
  46. package/dist/cjs/query/handler.d.ts +2 -2
  47. package/dist/cjs/query/handler.js +10 -10
  48. package/dist/cjs/query/index.d.ts +2 -2
  49. package/dist/cjs/query/index.js +32 -32
  50. package/dist/cjs/query/matchers/abstract-matcher.d.ts +9 -9
  51. package/dist/cjs/query/matchers/abstract-matcher.js +36 -36
  52. package/dist/cjs/query/matchers/alt-matcher.d.ts +10 -10
  53. package/dist/cjs/query/matchers/alt-matcher.js +33 -33
  54. package/dist/cjs/query/matchers/anchor-matcher.d.ts +17 -17
  55. package/dist/cjs/query/matchers/anchor-matcher.js +50 -50
  56. package/dist/cjs/query/matchers/comment-matcher.d.ts +10 -10
  57. package/dist/cjs/query/matchers/comment-matcher.js +39 -39
  58. package/dist/cjs/query/matchers/index.d.ts +6 -6
  59. package/dist/cjs/query/matchers/index.js +22 -22
  60. package/dist/cjs/query/matchers/many-matcher.d.ts +13 -13
  61. package/dist/cjs/query/matchers/many-matcher.js +61 -61
  62. package/dist/cjs/query/matchers/num-matcher.d.ts +8 -8
  63. package/dist/cjs/query/matchers/num-matcher.js +34 -34
  64. package/dist/cjs/query/matchers/op-matcher.d.ts +8 -8
  65. package/dist/cjs/query/matchers/op-matcher.js +34 -34
  66. package/dist/cjs/query/matchers/seq-matcher.d.ts +14 -14
  67. package/dist/cjs/query/matchers/seq-matcher.js +76 -76
  68. package/dist/cjs/query/matchers/str-matcher.d.ts +38 -38
  69. package/dist/cjs/query/matchers/str-matcher.js +108 -108
  70. package/dist/cjs/query/matchers/sym-matcher.d.ts +8 -8
  71. package/dist/cjs/query/matchers/sym-matcher.js +34 -34
  72. package/dist/cjs/query/matchers/tree-matcher.d.ts +23 -23
  73. package/dist/cjs/query/matchers/tree-matcher.js +121 -121
  74. package/dist/cjs/query/options.d.ts +10 -10
  75. package/dist/cjs/query/options.js +149 -149
  76. package/dist/cjs/query/regex.d.ts +1 -1
  77. package/dist/cjs/query/regex.js +13 -13
  78. package/dist/cjs/query/types.d.ts +100 -100
  79. package/dist/cjs/query/types.js +2 -2
  80. package/dist/cjs/util/clone.d.ts +1 -1
  81. package/dist/cjs/util/clone.js +5 -5
  82. package/dist/cjs/util/regex.d.ts +1 -1
  83. package/dist/cjs/util/regex.js +7 -7
  84. package/dist/esm/index.d.ts +4 -4
  85. package/dist/esm/index.js +8 -8
  86. package/dist/esm/lang/groovy.d.ts +6 -6
  87. package/dist/esm/lang/groovy.js +80 -80
  88. package/dist/esm/lang/index.d.ts +20 -20
  89. package/dist/esm/lang/index.js +37 -37
  90. package/dist/esm/lang/python.d.ts +6 -6
  91. package/dist/esm/lang/python.js +70 -70
  92. package/dist/esm/lang/scala.d.ts +6 -6
  93. package/dist/esm/lang/scala.js +68 -68
  94. package/dist/esm/lang/starlark.d.ts +6 -6
  95. package/dist/esm/lang/starlark.js +55 -55
  96. package/dist/esm/lang/types.d.ts +6 -6
  97. package/dist/esm/lang/types.js +1 -1
  98. package/dist/esm/lexer/bracket.d.ts +6 -6
  99. package/dist/esm/lexer/bracket.js +49 -49
  100. package/dist/esm/lexer/comment.d.ts +3 -3
  101. package/dist/esm/lexer/comment.js +39 -39
  102. package/dist/esm/lexer/index.d.ts +5 -5
  103. package/dist/esm/lexer/index.js +136 -136
  104. package/dist/esm/lexer/number.d.ts +2 -2
  105. package/dist/esm/lexer/number.js +14 -14
  106. package/dist/esm/lexer/operator.d.ts +2 -2
  107. package/dist/esm/lexer/operator.js +20 -20
  108. package/dist/esm/lexer/rules.d.ts +4 -4
  109. package/dist/esm/lexer/rules.js +69 -69
  110. package/dist/esm/lexer/string.d.ts +2 -2
  111. package/dist/esm/lexer/string.js +177 -177
  112. package/dist/esm/lexer/symbol.d.ts +2 -2
  113. package/dist/esm/lexer/symbol.js +14 -14
  114. package/dist/esm/lexer/token.d.ts +3 -3
  115. package/dist/esm/lexer/token.js +60 -60
  116. package/dist/esm/lexer/types.d.ts +142 -142
  117. package/dist/esm/lexer/types.js +1 -1
  118. package/dist/esm/parser/cursor.d.ts +2 -2
  119. package/dist/esm/parser/cursor.js +9 -9
  120. package/dist/esm/parser/index.d.ts +3 -3
  121. package/dist/esm/parser/index.js +3 -3
  122. package/dist/esm/parser/tree.d.ts +4 -4
  123. package/dist/esm/parser/tree.js +241 -241
  124. package/dist/esm/parser/types.d.ts +33 -33
  125. package/dist/esm/parser/types.js +1 -1
  126. package/dist/esm/query/builder.d.ts +144 -144
  127. package/dist/esm/query/builder.js +304 -304
  128. package/dist/esm/query/handler.d.ts +2 -2
  129. package/dist/esm/query/handler.js +6 -6
  130. package/dist/esm/query/index.d.ts +2 -2
  131. package/dist/esm/query/index.js +2 -2
  132. package/dist/esm/query/matchers/abstract-matcher.d.ts +9 -9
  133. package/dist/esm/query/matchers/abstract-matcher.js +32 -32
  134. package/dist/esm/query/matchers/alt-matcher.d.ts +10 -10
  135. package/dist/esm/query/matchers/alt-matcher.js +29 -29
  136. package/dist/esm/query/matchers/anchor-matcher.d.ts +17 -17
  137. package/dist/esm/query/matchers/anchor-matcher.js +44 -44
  138. package/dist/esm/query/matchers/comment-matcher.d.ts +10 -10
  139. package/dist/esm/query/matchers/comment-matcher.js +35 -35
  140. package/dist/esm/query/matchers/index.d.ts +6 -6
  141. package/dist/esm/query/matchers/index.js +6 -6
  142. package/dist/esm/query/matchers/many-matcher.d.ts +13 -13
  143. package/dist/esm/query/matchers/many-matcher.js +57 -57
  144. package/dist/esm/query/matchers/num-matcher.d.ts +8 -8
  145. package/dist/esm/query/matchers/num-matcher.js +30 -30
  146. package/dist/esm/query/matchers/op-matcher.d.ts +8 -8
  147. package/dist/esm/query/matchers/op-matcher.js +30 -30
  148. package/dist/esm/query/matchers/seq-matcher.d.ts +14 -14
  149. package/dist/esm/query/matchers/seq-matcher.js +72 -72
  150. package/dist/esm/query/matchers/str-matcher.d.ts +38 -38
  151. package/dist/esm/query/matchers/str-matcher.js +102 -102
  152. package/dist/esm/query/matchers/sym-matcher.d.ts +8 -8
  153. package/dist/esm/query/matchers/sym-matcher.js +30 -30
  154. package/dist/esm/query/matchers/tree-matcher.d.ts +23 -23
  155. package/dist/esm/query/matchers/tree-matcher.js +117 -117
  156. package/dist/esm/query/options.d.ts +10 -10
  157. package/dist/esm/query/options.js +139 -139
  158. package/dist/esm/query/regex.d.ts +1 -1
  159. package/dist/esm/query/regex.js +9 -9
  160. package/dist/esm/query/types.d.ts +100 -100
  161. package/dist/esm/query/types.js +1 -1
  162. package/dist/esm/util/clone.d.ts +1 -1
  163. package/dist/esm/util/clone.js +1 -1
  164. package/dist/esm/util/regex.d.ts +1 -1
  165. package/dist/esm/util/regex.js +3 -3
  166. package/package.json +3 -3
@@ -1,56 +1,56 @@
1
- /**
2
- * @see https://github.com/bazelbuild/starlark/blob/master/spec.md#lexical-elements
3
- */
4
- const operators =
5
- /* prettier-ignore */ [
6
- '+', '-', '*', '//', '%', '**',
7
- '~', '&', '|', '^', '<<', '>>',
8
- '.', ',', '=', ';', ':',
9
- '<', '>', '>=', '<=', '==', '!=',
10
- '+=', '-=', '*=', '//=', '%=',
11
- '&=', '|=', '^=', '<<=', '>>=',
12
- ];
13
- const octdigit = '[0-7]';
14
- const digit = '[0-9]';
15
- const nonzerodigit = '[1-9]';
16
- const hexdigit = `(?:${digit}|[a-fA-F])`;
17
- const octinteger = `(?:0[oO](?:_?${octdigit})+)`;
18
- const hexinteger = `(?:0[xX](?:_?${hexdigit})+)`;
19
- const decinteger = `(?:${nonzerodigit}(?:_?${digit})*|0+(?:_?0)*)`;
20
- const integer = `(?:${decinteger}|${octinteger}|${hexinteger})`;
21
- const digitpart = `(?:${digit}(?:_?${digit})*)`;
22
- const fraction = `(?:\\.${digitpart})`;
23
- const exponent = `(?:[eE][-+]?${digitpart})`;
24
- const pointfloat = `(?:${digitpart}?${fraction}|${digitpart}\\.)`;
25
- const exponentfloat = `(?:(?:${digitpart}|${pointfloat})${exponent})`;
26
- const floatnumber = `(?:${pointfloat}|${exponentfloat})`;
27
- const numbers = new RegExp(`(?:${integer}|${floatnumber})`);
28
- export const lexer = {
29
- joinLines: '\\',
30
- comments: [{ type: 'line-comment', startsWith: '#' }],
31
- symbols: /[_a-zA-Z][_a-zA-Z0-9]*/,
32
- numbers,
33
- operators,
34
- brackets: [
35
- { startsWith: '{', endsWith: '}' },
36
- { startsWith: '[', endsWith: ']' },
37
- { startsWith: '(', endsWith: ')' },
38
- ],
39
- strings: [
40
- { startsWith: "'", escapeChar: '\\' },
41
- { startsWith: '"', escapeChar: '\\' },
42
- { startsWith: "'''", escapeChar: '\\' },
43
- { startsWith: '"""', escapeChar: '\\' },
44
- { startsWith: "r'", endsWith: "'" },
45
- { startsWith: 'r"', endsWith: '"' },
46
- { startsWith: "rb'", endsWith: "'" },
47
- { startsWith: 'rb"', endsWith: '"' },
48
- { startsWith: "br'", endsWith: "'" },
49
- { startsWith: 'br"', endsWith: '"' },
50
- ],
51
- };
52
- export const parser = {
53
- useIndentBlocks: true,
54
- };
55
- export const lang = { lexer, parser };
1
+ /**
2
+ * @see https://github.com/bazelbuild/starlark/blob/master/spec.md#lexical-elements
3
+ */
4
+ const operators =
5
+ /* prettier-ignore */ [
6
+ '+', '-', '*', '//', '%', '**',
7
+ '~', '&', '|', '^', '<<', '>>',
8
+ '.', ',', '=', ';', ':',
9
+ '<', '>', '>=', '<=', '==', '!=',
10
+ '+=', '-=', '*=', '//=', '%=',
11
+ '&=', '|=', '^=', '<<=', '>>=',
12
+ ];
13
+ const octdigit = '[0-7]';
14
+ const digit = '[0-9]';
15
+ const nonzerodigit = '[1-9]';
16
+ const hexdigit = `(?:${digit}|[a-fA-F])`;
17
+ const octinteger = `(?:0[oO](?:_?${octdigit})+)`;
18
+ const hexinteger = `(?:0[xX](?:_?${hexdigit})+)`;
19
+ const decinteger = `(?:${nonzerodigit}(?:_?${digit})*|0+(?:_?0)*)`;
20
+ const integer = `(?:${decinteger}|${octinteger}|${hexinteger})`;
21
+ const digitpart = `(?:${digit}(?:_?${digit})*)`;
22
+ const fraction = `(?:\\.${digitpart})`;
23
+ const exponent = `(?:[eE][-+]?${digitpart})`;
24
+ const pointfloat = `(?:${digitpart}?${fraction}|${digitpart}\\.)`;
25
+ const exponentfloat = `(?:(?:${digitpart}|${pointfloat})${exponent})`;
26
+ const floatnumber = `(?:${pointfloat}|${exponentfloat})`;
27
+ const numbers = new RegExp(`(?:${integer}|${floatnumber})`);
28
+ export const lexer = {
29
+ joinLines: '\\',
30
+ comments: [{ type: 'line-comment', startsWith: '#' }],
31
+ symbols: /[_a-zA-Z][_a-zA-Z0-9]*/,
32
+ numbers,
33
+ operators,
34
+ brackets: [
35
+ { startsWith: '{', endsWith: '}' },
36
+ { startsWith: '[', endsWith: ']' },
37
+ { startsWith: '(', endsWith: ')' },
38
+ ],
39
+ strings: [
40
+ { startsWith: "'", escapeChar: '\\' },
41
+ { startsWith: '"', escapeChar: '\\' },
42
+ { startsWith: "'''", escapeChar: '\\' },
43
+ { startsWith: '"""', escapeChar: '\\' },
44
+ { startsWith: "r'", endsWith: "'" },
45
+ { startsWith: 'r"', endsWith: '"' },
46
+ { startsWith: "rb'", endsWith: "'" },
47
+ { startsWith: 'rb"', endsWith: '"' },
48
+ { startsWith: "br'", endsWith: "'" },
49
+ { startsWith: 'br"', endsWith: '"' },
50
+ ],
51
+ };
52
+ export const parser = {
53
+ useIndentBlocks: true,
54
+ };
55
+ export const lang = { lexer, parser };
56
56
  //# sourceMappingURL=starlark.js.map
@@ -1,7 +1,7 @@
1
- import type { LexerConfig } from '../lexer/types';
2
- import type { ParserConfig } from '../parser/types';
3
- export interface LanguageConfig {
4
- lexer: LexerConfig;
5
- parser: ParserConfig;
6
- }
1
+ import type { LexerConfig } from '../lexer/types';
2
+ import type { ParserConfig } from '../parser/types';
3
+ export interface LanguageConfig {
4
+ lexer: LexerConfig;
5
+ parser: ParserConfig;
6
+ }
7
7
  //# sourceMappingURL=types.d.ts.map
@@ -1,2 +1,2 @@
1
- export {};
1
+ export {};
2
2
  //# sourceMappingURL=types.js.map
@@ -1,7 +1,7 @@
1
- import type { BracketOption, StatesMap } from './types';
2
- export declare function isBracketKey(key: string): boolean;
3
- export declare function isLeftKey(key: string): boolean;
4
- export declare function isRightKey(key: string): boolean;
5
- export declare function getCounterpartBracketKey(rightKey: string): string | undefined;
6
- export declare function configBrackets(states: StatesMap, opts: BracketOption[]): StatesMap;
1
+ import type { BracketOption, StatesMap } from './types';
2
+ export declare function isBracketKey(key: string): boolean;
3
+ export declare function isLeftKey(key: string): boolean;
4
+ export declare function isRightKey(key: string): boolean;
5
+ export declare function getCounterpartBracketKey(rightKey: string): string | undefined;
6
+ export declare function configBrackets(states: StatesMap, opts: BracketOption[]): StatesMap;
7
7
  //# sourceMappingURL=bracket.d.ts.map
@@ -1,50 +1,50 @@
1
- export function isBracketKey(key) {
2
- return key.startsWith('bracket$');
3
- }
4
- export function isLeftKey(key) {
5
- return key.endsWith('$left');
6
- }
7
- export function isRightKey(key) {
8
- return key.endsWith('$right');
9
- }
10
- export function getCounterpartBracketKey(rightKey) {
11
- const [tokenName, idx, side] = rightKey.split('$');
12
- const sides = new Set(['left', 'right']);
13
- let result;
14
- if (tokenName === 'bracket' && typeof side === 'string' && sides.has(side)) {
15
- sides.delete(side);
16
- const [counterpart] = [...sides];
17
- result = [tokenName, idx, counterpart].join('$');
18
- }
19
- return result;
20
- }
21
- export function configBrackets(states, opts) {
22
- const bracketDefs = {};
23
- opts.forEach((option, idx) => {
24
- const tokenKey = `bracket$${idx}`;
25
- const leftTokenKey = `${tokenKey}$left`;
26
- const leftTokenRule = {
27
- t: 'string',
28
- type: leftTokenKey,
29
- match: option.startsWith,
30
- chunk: option.startsWith,
31
- };
32
- const rightTokenKey = `${tokenKey}$right`;
33
- const rightTokenRule = {
34
- t: 'string',
35
- type: rightTokenKey,
36
- match: option.endsWith,
37
- chunk: option.endsWith,
38
- };
39
- bracketDefs[leftTokenKey] = leftTokenRule;
40
- bracketDefs[rightTokenKey] = rightTokenRule;
41
- });
42
- return {
43
- ...states,
44
- $: {
45
- ...states.$,
46
- ...bracketDefs,
47
- },
48
- };
49
- }
1
+ export function isBracketKey(key) {
2
+ return key.startsWith('bracket$');
3
+ }
4
+ export function isLeftKey(key) {
5
+ return key.endsWith('$left');
6
+ }
7
+ export function isRightKey(key) {
8
+ return key.endsWith('$right');
9
+ }
10
+ export function getCounterpartBracketKey(rightKey) {
11
+ const [tokenName, idx, side] = rightKey.split('$');
12
+ const sides = new Set(['left', 'right']);
13
+ let result;
14
+ if (tokenName === 'bracket' && typeof side === 'string' && sides.has(side)) {
15
+ sides.delete(side);
16
+ const [counterpart] = [...sides];
17
+ result = [tokenName, idx, counterpart].join('$');
18
+ }
19
+ return result;
20
+ }
21
+ export function configBrackets(states, opts) {
22
+ const bracketDefs = {};
23
+ opts.forEach((option, idx) => {
24
+ const tokenKey = `bracket$${idx}`;
25
+ const leftTokenKey = `${tokenKey}$left`;
26
+ const leftTokenRule = {
27
+ t: 'string',
28
+ type: leftTokenKey,
29
+ match: option.startsWith,
30
+ chunk: option.startsWith,
31
+ };
32
+ const rightTokenKey = `${tokenKey}$right`;
33
+ const rightTokenRule = {
34
+ t: 'string',
35
+ type: rightTokenKey,
36
+ match: option.endsWith,
37
+ chunk: option.endsWith,
38
+ };
39
+ bracketDefs[leftTokenKey] = leftTokenRule;
40
+ bracketDefs[rightTokenKey] = rightTokenRule;
41
+ });
42
+ return {
43
+ ...states,
44
+ $: {
45
+ ...states.$,
46
+ ...bracketDefs,
47
+ },
48
+ };
49
+ }
50
50
  //# sourceMappingURL=bracket.js.map
@@ -1,4 +1,4 @@
1
- import type { CommentOption, StatesMap } from './types';
2
- export declare function esc(input: string): string;
3
- export declare function configComments(states: StatesMap, opts: CommentOption[]): StatesMap;
1
+ import type { CommentOption, StatesMap } from './types';
2
+ export declare function esc(input: string): string;
3
+ export declare function configComments(states: StatesMap, opts: CommentOption[]): StatesMap;
4
4
  //# sourceMappingURL=comment.d.ts.map
@@ -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,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
@@ -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,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