@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,33 +1,33 @@
1
- const skipByDefault = [
2
- 'whitespace',
3
- '_start',
4
- 'newline',
5
- 'comment',
6
- ];
7
- export class AbstractMatcher {
8
- canSkip(node) {
9
- return skipByDefault.includes(node.type);
10
- }
11
- seekNext(cursor) {
12
- let node = cursor.node;
13
- while (this.canSkip(node)) {
14
- if (!cursor.right) {
15
- return cursor;
16
- }
17
- cursor = cursor.right;
18
- node = cursor.node;
19
- }
20
- return cursor;
21
- }
22
- moveRight(cursor) {
23
- const result = cursor.right;
24
- if (result) {
25
- return result;
26
- }
27
- throw new Error('Cursor error: move right');
28
- }
29
- nextMatch() {
30
- return null;
31
- }
32
- }
1
+ const skipByDefault = [
2
+ 'whitespace',
3
+ '_start',
4
+ 'newline',
5
+ 'comment',
6
+ ];
7
+ export class AbstractMatcher {
8
+ canSkip(node) {
9
+ return skipByDefault.includes(node.type);
10
+ }
11
+ seekNext(cursor) {
12
+ let node = cursor.node;
13
+ while (this.canSkip(node)) {
14
+ if (!cursor.right) {
15
+ return cursor;
16
+ }
17
+ cursor = cursor.right;
18
+ node = cursor.node;
19
+ }
20
+ return cursor;
21
+ }
22
+ moveRight(cursor) {
23
+ const result = cursor.right;
24
+ if (result) {
25
+ return result;
26
+ }
27
+ throw new Error('Cursor error: move right');
28
+ }
29
+ nextMatch() {
30
+ return null;
31
+ }
32
+ }
33
33
  //# sourceMappingURL=abstract-matcher.js.map
@@ -1,11 +1,11 @@
1
- import type { AltMatcherOptions, Checkpoint, Matcher } from '../types';
2
- import { AbstractMatcher } from './abstract-matcher';
3
- export declare class AltMatcher<Ctx> extends AbstractMatcher<Ctx> {
4
- readonly alts: Matcher<Ctx>[];
5
- private idx;
6
- private checkpoint;
7
- constructor({ matchers }: AltMatcherOptions<Ctx>);
8
- match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
9
- nextMatch(): Checkpoint<Ctx> | null;
10
- }
1
+ import type { AltMatcherOptions, Checkpoint, Matcher } from '../types';
2
+ import { AbstractMatcher } from './abstract-matcher';
3
+ export declare class AltMatcher<Ctx> extends AbstractMatcher<Ctx> {
4
+ readonly alts: Matcher<Ctx>[];
5
+ private idx;
6
+ private checkpoint;
7
+ constructor({ matchers }: AltMatcherOptions<Ctx>);
8
+ match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
9
+ nextMatch(): Checkpoint<Ctx> | null;
10
+ }
11
11
  //# sourceMappingURL=alt-matcher.d.ts.map
@@ -1,30 +1,30 @@
1
- import { AbstractMatcher } from './abstract-matcher';
2
- export class AltMatcher extends AbstractMatcher {
3
- constructor({ matchers }) {
4
- super();
5
- this.idx = -1;
6
- this.checkpoint = null;
7
- this.alts = matchers;
8
- }
9
- match(checkpoint) {
10
- this.checkpoint = checkpoint;
11
- this.idx = -1;
12
- return this.nextMatch();
13
- }
14
- nextMatch() {
15
- if (this.checkpoint) {
16
- this.idx += 1;
17
- let matcher = this.alts[this.idx];
18
- while (matcher) {
19
- const checkpoint = matcher.match(this.checkpoint);
20
- if (checkpoint) {
21
- return checkpoint;
22
- }
23
- this.idx += 1;
24
- matcher = this.alts[this.idx];
25
- }
26
- }
27
- return null;
28
- }
29
- }
1
+ import { AbstractMatcher } from './abstract-matcher';
2
+ export class AltMatcher extends AbstractMatcher {
3
+ constructor({ matchers }) {
4
+ super();
5
+ this.idx = -1;
6
+ this.checkpoint = null;
7
+ this.alts = matchers;
8
+ }
9
+ match(checkpoint) {
10
+ this.checkpoint = checkpoint;
11
+ this.idx = -1;
12
+ return this.nextMatch();
13
+ }
14
+ nextMatch() {
15
+ if (this.checkpoint) {
16
+ this.idx += 1;
17
+ let matcher = this.alts[this.idx];
18
+ while (matcher) {
19
+ const checkpoint = matcher.match(this.checkpoint);
20
+ if (checkpoint) {
21
+ return checkpoint;
22
+ }
23
+ this.idx += 1;
24
+ matcher = this.alts[this.idx];
25
+ }
26
+ }
27
+ return null;
28
+ }
29
+ }
30
30
  //# sourceMappingURL=alt-matcher.js.map
@@ -1,18 +1,18 @@
1
- import type { Token } from '../../lexer/types';
2
- import type { Cursor, Tree } from '../../parser';
3
- import type { Checkpoint } from '../types';
4
- import { AbstractMatcher } from './abstract-matcher';
5
- export declare class BeginMatcher<Ctx> extends AbstractMatcher<Ctx> {
6
- match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
7
- }
8
- export declare class EndMatcher<Ctx> extends AbstractMatcher<Ctx> {
9
- match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
10
- }
11
- export declare class VoidMatcher<Ctx, T extends Tree | Token> extends AbstractMatcher<Ctx> {
12
- private handler;
13
- constructor(handler: (context: Ctx, t: T) => Ctx);
14
- match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
15
- moveRight(cursor: Cursor): Cursor;
16
- seekNext(cursor: Cursor): Cursor;
17
- }
1
+ import type { Token } from '../../lexer/types';
2
+ import type { Cursor, Tree } from '../../parser';
3
+ import type { Checkpoint } from '../types';
4
+ import { AbstractMatcher } from './abstract-matcher';
5
+ export declare class BeginMatcher<Ctx> extends AbstractMatcher<Ctx> {
6
+ match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
7
+ }
8
+ export declare class EndMatcher<Ctx> extends AbstractMatcher<Ctx> {
9
+ match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
10
+ }
11
+ export declare class VoidMatcher<Ctx, T extends Tree | Token> extends AbstractMatcher<Ctx> {
12
+ private handler;
13
+ constructor(handler: (context: Ctx, t: T) => Ctx);
14
+ match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
15
+ moveRight(cursor: Cursor): Cursor;
16
+ seekNext(cursor: Cursor): Cursor;
17
+ }
18
18
  //# sourceMappingURL=anchor-matcher.d.ts.map
@@ -1,45 +1,45 @@
1
- import { clone } from '../../util/clone';
2
- import { AbstractMatcher } from './abstract-matcher';
3
- export class BeginMatcher extends AbstractMatcher {
4
- match(checkpoint) {
5
- var _a;
6
- let { cursor } = checkpoint;
7
- if (((_a = cursor.node) === null || _a === void 0 ? void 0 : _a.type) === '_start') {
8
- cursor = this.moveRight(cursor);
9
- return { ...checkpoint, cursor };
10
- }
11
- return null;
12
- }
13
- }
14
- export class EndMatcher extends AbstractMatcher {
15
- match(checkpoint) {
16
- var _a;
17
- let { cursor } = checkpoint;
18
- cursor = this.seekNext(cursor);
19
- if (((_a = cursor.node) === null || _a === void 0 ? void 0 : _a.type) === '_end') {
20
- return checkpoint;
21
- }
22
- return null;
23
- }
24
- }
25
- export class VoidMatcher extends AbstractMatcher {
26
- constructor(handler) {
27
- super();
28
- this.handler = (context, t) => handler(clone(context), t);
29
- }
30
- match(checkpoint) {
31
- var _a;
32
- const { cursor, context } = checkpoint;
33
- const prevCursor = (_a = cursor.left) !== null && _a !== void 0 ? _a : cursor;
34
- const node = prevCursor.node;
35
- const newContext = this.handler(context, node);
36
- return { cursor, context: newContext };
37
- }
38
- moveRight(cursor) {
39
- return cursor;
40
- }
41
- seekNext(cursor) {
42
- return cursor;
43
- }
44
- }
1
+ import { clone } from '../../util/clone';
2
+ import { AbstractMatcher } from './abstract-matcher';
3
+ export class BeginMatcher extends AbstractMatcher {
4
+ match(checkpoint) {
5
+ var _a;
6
+ let { cursor } = checkpoint;
7
+ if (((_a = cursor.node) === null || _a === void 0 ? void 0 : _a.type) === '_start') {
8
+ cursor = this.moveRight(cursor);
9
+ return { ...checkpoint, cursor };
10
+ }
11
+ return null;
12
+ }
13
+ }
14
+ export class EndMatcher extends AbstractMatcher {
15
+ match(checkpoint) {
16
+ var _a;
17
+ let { cursor } = checkpoint;
18
+ cursor = this.seekNext(cursor);
19
+ if (((_a = cursor.node) === null || _a === void 0 ? void 0 : _a.type) === '_end') {
20
+ return checkpoint;
21
+ }
22
+ return null;
23
+ }
24
+ }
25
+ export class VoidMatcher extends AbstractMatcher {
26
+ constructor(handler) {
27
+ super();
28
+ this.handler = (context, t) => handler(clone(context), t);
29
+ }
30
+ match(checkpoint) {
31
+ var _a;
32
+ const { cursor, context } = checkpoint;
33
+ const prevCursor = (_a = cursor.left) !== null && _a !== void 0 ? _a : cursor;
34
+ const node = prevCursor.node;
35
+ const newContext = this.handler(context, node);
36
+ return { cursor, context: newContext };
37
+ }
38
+ moveRight(cursor) {
39
+ return cursor;
40
+ }
41
+ seekNext(cursor) {
42
+ return cursor;
43
+ }
44
+ }
45
45
  //# sourceMappingURL=anchor-matcher.js.map
@@ -1,11 +1,11 @@
1
- import type { Node } from '../../parser';
2
- import type { Checkpoint, CommentMatcherHandler, CommentMatcherOptions, CommentMatcherValue } from '../types';
3
- import { AbstractMatcher } from './abstract-matcher';
4
- export declare class CommentMatcher<Ctx> extends AbstractMatcher<Ctx> {
5
- readonly comment: CommentMatcherValue;
6
- readonly handler: CommentMatcherHandler<Ctx>;
7
- constructor({ value, handler }: CommentMatcherOptions<Ctx>);
8
- canSkip(node: Node): boolean;
9
- match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
10
- }
1
+ import type { Node } from '../../parser';
2
+ import type { Checkpoint, CommentMatcherHandler, CommentMatcherOptions, CommentMatcherValue } from '../types';
3
+ import { AbstractMatcher } from './abstract-matcher';
4
+ export declare class CommentMatcher<Ctx> extends AbstractMatcher<Ctx> {
5
+ readonly comment: CommentMatcherValue;
6
+ readonly handler: CommentMatcherHandler<Ctx>;
7
+ constructor({ value, handler }: CommentMatcherOptions<Ctx>);
8
+ canSkip(node: Node): boolean;
9
+ match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
10
+ }
11
11
  //# sourceMappingURL=comment-matcher.d.ts.map
@@ -1,36 +1,36 @@
1
- import { safeHandler } from '../handler';
2
- import { isRegex } from '../regex';
3
- import { AbstractMatcher } from './abstract-matcher';
4
- const skipBeforeComment = ['whitespace', '_start', 'newline'];
5
- export class CommentMatcher extends AbstractMatcher {
6
- constructor({ value, handler }) {
7
- super();
8
- this.comment = value;
9
- this.handler = safeHandler(handler);
10
- }
11
- canSkip(node) {
12
- return skipBeforeComment.includes(node.type);
13
- }
14
- match(checkpoint) {
15
- var _a;
16
- const context = checkpoint.context;
17
- const cursor = this.seekNext(checkpoint.cursor);
18
- const node = cursor.node;
19
- if ((node === null || node === void 0 ? void 0 : node.type) === 'comment') {
20
- let isMatched = true;
21
- if (typeof this.comment === 'string') {
22
- isMatched = this.comment === node.value;
23
- }
24
- else if (isRegex(this.comment)) {
25
- isMatched = this.comment.test(node.value);
26
- }
27
- if (isMatched) {
28
- const nextContext = this.handler(context, node);
29
- const nextCursor = (_a = cursor.right) !== null && _a !== void 0 ? _a : cursor;
30
- return { context: nextContext, cursor: nextCursor };
31
- }
32
- }
33
- return null;
34
- }
35
- }
1
+ import { safeHandler } from '../handler';
2
+ import { isRegex } from '../regex';
3
+ import { AbstractMatcher } from './abstract-matcher';
4
+ const skipBeforeComment = ['whitespace', '_start', 'newline'];
5
+ export class CommentMatcher extends AbstractMatcher {
6
+ constructor({ value, handler }) {
7
+ super();
8
+ this.comment = value;
9
+ this.handler = safeHandler(handler);
10
+ }
11
+ canSkip(node) {
12
+ return skipBeforeComment.includes(node.type);
13
+ }
14
+ match(checkpoint) {
15
+ var _a;
16
+ const context = checkpoint.context;
17
+ const cursor = this.seekNext(checkpoint.cursor);
18
+ const node = cursor.node;
19
+ if ((node === null || node === void 0 ? void 0 : node.type) === 'comment') {
20
+ let isMatched = true;
21
+ if (typeof this.comment === 'string') {
22
+ isMatched = this.comment === node.value;
23
+ }
24
+ else if (isRegex(this.comment)) {
25
+ isMatched = this.comment.test(node.value);
26
+ }
27
+ if (isMatched) {
28
+ const nextContext = this.handler(context, node);
29
+ const nextCursor = (_a = cursor.right) !== null && _a !== void 0 ? _a : cursor;
30
+ return { context: nextContext, cursor: nextCursor };
31
+ }
32
+ }
33
+ return null;
34
+ }
35
+ }
36
36
  //# sourceMappingURL=comment-matcher.js.map
@@ -1,7 +1,7 @@
1
- export * from './abstract-matcher';
2
- export * from './alt-matcher';
3
- export * from './many-matcher';
4
- export * from './op-matcher';
5
- export * from './seq-matcher';
6
- export * from './sym-matcher';
1
+ export * from './abstract-matcher';
2
+ export * from './alt-matcher';
3
+ export * from './many-matcher';
4
+ export * from './op-matcher';
5
+ export * from './seq-matcher';
6
+ export * from './sym-matcher';
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1,7 +1,7 @@
1
- export * from './abstract-matcher';
2
- export * from './alt-matcher';
3
- export * from './many-matcher';
4
- export * from './op-matcher';
5
- export * from './seq-matcher';
6
- export * from './sym-matcher';
1
+ export * from './abstract-matcher';
2
+ export * from './alt-matcher';
3
+ export * from './many-matcher';
4
+ export * from './op-matcher';
5
+ export * from './seq-matcher';
6
+ export * from './sym-matcher';
7
7
  //# sourceMappingURL=index.js.map
@@ -1,14 +1,14 @@
1
- import type { Checkpoint, ManyMatcherOptions, Matcher } from '../types';
2
- import { AbstractMatcher } from './abstract-matcher';
3
- export declare class ManyMatcher<Ctx> extends AbstractMatcher<Ctx> {
4
- readonly manyOf: Matcher<Ctx>;
5
- readonly min: number;
6
- readonly max: number | null;
7
- private idx;
8
- private matches;
9
- constructor({ matcher, min, max }: ManyMatcherOptions<Ctx>);
10
- private nextRound;
11
- match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
12
- nextMatch(): Checkpoint<Ctx> | null;
13
- }
1
+ import type { Checkpoint, ManyMatcherOptions, Matcher } from '../types';
2
+ import { AbstractMatcher } from './abstract-matcher';
3
+ export declare class ManyMatcher<Ctx> extends AbstractMatcher<Ctx> {
4
+ readonly manyOf: Matcher<Ctx>;
5
+ readonly min: number;
6
+ readonly max: number | null;
7
+ private idx;
8
+ private matches;
9
+ constructor({ matcher, min, max }: ManyMatcherOptions<Ctx>);
10
+ private nextRound;
11
+ match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
12
+ nextMatch(): Checkpoint<Ctx> | null;
13
+ }
14
14
  //# sourceMappingURL=many-matcher.d.ts.map
@@ -1,58 +1,58 @@
1
- import { AbstractMatcher } from './abstract-matcher';
2
- export class ManyMatcher extends AbstractMatcher {
3
- constructor({ matcher, min, max }) {
4
- super();
5
- this.idx = 0;
6
- this.matches = [];
7
- if (min < 0) {
8
- throw new Error(`Invalid minimal bound: ${min}`);
9
- }
10
- if (max !== null && min > max) {
11
- throw new Error(`Invalid boundaries: ${min} > ${max}`);
12
- }
13
- this.manyOf = matcher;
14
- this.min = min;
15
- this.max = max;
16
- }
17
- nextRound(checkpoints) {
18
- const results = [];
19
- for (const oldCheckpoint of checkpoints) {
20
- const newCheckpoint = this.manyOf.match(oldCheckpoint);
21
- if (!newCheckpoint) {
22
- continue;
23
- }
24
- const matchResults = [newCheckpoint];
25
- let nextResult = this.manyOf.nextMatch();
26
- while (nextResult) {
27
- matchResults.push(nextResult);
28
- nextResult = this.manyOf.nextMatch();
29
- }
30
- results.unshift(...matchResults);
31
- }
32
- return results;
33
- }
34
- match(checkpoint) {
35
- var _a;
36
- this.idx = 0;
37
- let roundResults = [checkpoint];
38
- this.matches = this.min === 0 ? [checkpoint] : [];
39
- let round = 1;
40
- while (this.max !== null ? round <= this.max : true) {
41
- roundResults = this.nextRound(roundResults);
42
- if (roundResults.length) {
43
- this.matches.unshift(...roundResults);
44
- round += 1;
45
- }
46
- else {
47
- break;
48
- }
49
- }
50
- return (_a = this.matches[this.idx]) !== null && _a !== void 0 ? _a : null;
51
- }
52
- nextMatch() {
53
- var _a;
54
- this.idx += 1;
55
- return (_a = this.matches[this.idx]) !== null && _a !== void 0 ? _a : null;
56
- }
57
- }
1
+ import { AbstractMatcher } from './abstract-matcher';
2
+ export class ManyMatcher extends AbstractMatcher {
3
+ constructor({ matcher, min, max }) {
4
+ super();
5
+ this.idx = 0;
6
+ this.matches = [];
7
+ if (min < 0) {
8
+ throw new Error(`Invalid minimal bound: ${min}`);
9
+ }
10
+ if (max !== null && min > max) {
11
+ throw new Error(`Invalid boundaries: ${min} > ${max}`);
12
+ }
13
+ this.manyOf = matcher;
14
+ this.min = min;
15
+ this.max = max;
16
+ }
17
+ nextRound(checkpoints) {
18
+ const results = [];
19
+ for (const oldCheckpoint of checkpoints) {
20
+ const newCheckpoint = this.manyOf.match(oldCheckpoint);
21
+ if (!newCheckpoint) {
22
+ continue;
23
+ }
24
+ const matchResults = [newCheckpoint];
25
+ let nextResult = this.manyOf.nextMatch();
26
+ while (nextResult) {
27
+ matchResults.push(nextResult);
28
+ nextResult = this.manyOf.nextMatch();
29
+ }
30
+ results.unshift(...matchResults);
31
+ }
32
+ return results;
33
+ }
34
+ match(checkpoint) {
35
+ var _a;
36
+ this.idx = 0;
37
+ let roundResults = [checkpoint];
38
+ this.matches = this.min === 0 ? [checkpoint] : [];
39
+ let round = 1;
40
+ while (this.max !== null ? round <= this.max : true) {
41
+ roundResults = this.nextRound(roundResults);
42
+ if (roundResults.length) {
43
+ this.matches.unshift(...roundResults);
44
+ round += 1;
45
+ }
46
+ else {
47
+ break;
48
+ }
49
+ }
50
+ return (_a = this.matches[this.idx]) !== null && _a !== void 0 ? _a : null;
51
+ }
52
+ nextMatch() {
53
+ var _a;
54
+ this.idx += 1;
55
+ return (_a = this.matches[this.idx]) !== null && _a !== void 0 ? _a : null;
56
+ }
57
+ }
58
58
  //# sourceMappingURL=many-matcher.js.map
@@ -1,9 +1,9 @@
1
- import type { Checkpoint, NumMatcherHandler, NumMatcherOptions, NumMatcherValue } from '../types';
2
- import { AbstractMatcher } from './abstract-matcher';
3
- export declare class NumMatcher<Ctx> extends AbstractMatcher<Ctx> {
4
- readonly num: NumMatcherValue;
5
- readonly handler: NumMatcherHandler<Ctx>;
6
- constructor({ value, handler }: NumMatcherOptions<Ctx>);
7
- match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
8
- }
1
+ import type { Checkpoint, NumMatcherHandler, NumMatcherOptions, NumMatcherValue } from '../types';
2
+ import { AbstractMatcher } from './abstract-matcher';
3
+ export declare class NumMatcher<Ctx> extends AbstractMatcher<Ctx> {
4
+ readonly num: NumMatcherValue;
5
+ readonly handler: NumMatcherHandler<Ctx>;
6
+ constructor({ value, handler }: NumMatcherOptions<Ctx>);
7
+ match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
8
+ }
9
9
  //# sourceMappingURL=num-matcher.d.ts.map
@@ -1,31 +1,31 @@
1
- import { safeHandler } from '../handler';
2
- import { isRegex } from '../regex';
3
- import { AbstractMatcher } from './abstract-matcher';
4
- export class NumMatcher extends AbstractMatcher {
5
- constructor({ value, handler }) {
6
- super();
7
- this.num = value;
8
- this.handler = safeHandler(handler);
9
- }
10
- match(checkpoint) {
11
- let context = checkpoint.context;
12
- let cursor = this.seekNext(checkpoint.cursor);
13
- const node = cursor.node;
14
- if ((node === null || node === void 0 ? void 0 : node.type) === 'number') {
15
- let isMatched = true;
16
- if (typeof this.num === 'string') {
17
- isMatched = this.num === node.value;
18
- }
19
- else if (isRegex(this.num)) {
20
- isMatched = this.num.test(node.value);
21
- }
22
- if (isMatched) {
23
- context = this.handler(context, node);
24
- cursor = this.moveRight(cursor);
25
- return { cursor, context };
26
- }
27
- }
28
- return null;
29
- }
30
- }
1
+ import { safeHandler } from '../handler';
2
+ import { isRegex } from '../regex';
3
+ import { AbstractMatcher } from './abstract-matcher';
4
+ export class NumMatcher extends AbstractMatcher {
5
+ constructor({ value, handler }) {
6
+ super();
7
+ this.num = value;
8
+ this.handler = safeHandler(handler);
9
+ }
10
+ match(checkpoint) {
11
+ let context = checkpoint.context;
12
+ let cursor = this.seekNext(checkpoint.cursor);
13
+ const node = cursor.node;
14
+ if ((node === null || node === void 0 ? void 0 : node.type) === 'number') {
15
+ let isMatched = true;
16
+ if (typeof this.num === 'string') {
17
+ isMatched = this.num === node.value;
18
+ }
19
+ else if (isRegex(this.num)) {
20
+ isMatched = this.num.test(node.value);
21
+ }
22
+ if (isMatched) {
23
+ context = this.handler(context, node);
24
+ cursor = this.moveRight(cursor);
25
+ return { cursor, context };
26
+ }
27
+ }
28
+ return null;
29
+ }
30
+ }
31
31
  //# sourceMappingURL=num-matcher.js.map
@@ -1,9 +1,9 @@
1
- import type { Checkpoint, OpMatcherHandler, OpMatcherOptions, OpMatcherValue } from '../types';
2
- import { AbstractMatcher } from './abstract-matcher';
3
- export declare class OpMatcher<Ctx> extends AbstractMatcher<Ctx> {
4
- readonly op: OpMatcherValue;
5
- readonly handler: OpMatcherHandler<Ctx>;
6
- constructor({ value, handler }: OpMatcherOptions<Ctx>);
7
- match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
8
- }
1
+ import type { Checkpoint, OpMatcherHandler, OpMatcherOptions, OpMatcherValue } from '../types';
2
+ import { AbstractMatcher } from './abstract-matcher';
3
+ export declare class OpMatcher<Ctx> extends AbstractMatcher<Ctx> {
4
+ readonly op: OpMatcherValue;
5
+ readonly handler: OpMatcherHandler<Ctx>;
6
+ constructor({ value, handler }: OpMatcherOptions<Ctx>);
7
+ match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
8
+ }
9
9
  //# sourceMappingURL=op-matcher.d.ts.map