@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,31 +1,31 @@
1
- import { safeHandler } from '../handler';
2
- import { isRegex } from '../regex';
3
- import { AbstractMatcher } from './abstract-matcher';
4
- export class OpMatcher extends AbstractMatcher {
5
- constructor({ value, handler }) {
6
- super();
7
- this.op = 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) === 'operator') {
15
- let isMatched = true;
16
- if (typeof this.op === 'string') {
17
- isMatched = this.op === node.value;
18
- }
19
- else if (isRegex(this.op)) {
20
- isMatched = this.op.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 OpMatcher extends AbstractMatcher {
5
+ constructor({ value, handler }) {
6
+ super();
7
+ this.op = 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) === 'operator') {
15
+ let isMatched = true;
16
+ if (typeof this.op === 'string') {
17
+ isMatched = this.op === node.value;
18
+ }
19
+ else if (isRegex(this.op)) {
20
+ isMatched = this.op.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=op-matcher.js.map
@@ -1,15 +1,15 @@
1
- import type { Checkpoint, Matcher, SeqMatcherOptions } from '../types';
2
- import { AbstractMatcher } from './abstract-matcher';
3
- export declare class SeqMatcher<Ctx> extends AbstractMatcher<Ctx> {
4
- readonly seq: Matcher<Ctx>[];
5
- readonly length: number;
6
- private checkpoint;
7
- private idx;
8
- constructor({ matchers }: SeqMatcherOptions<Ctx>);
9
- private isMatchingComplete;
10
- private matchForward;
11
- private backtrack;
12
- match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
13
- nextMatch(): Checkpoint<Ctx> | null;
14
- }
1
+ import type { Checkpoint, Matcher, SeqMatcherOptions } from '../types';
2
+ import { AbstractMatcher } from './abstract-matcher';
3
+ export declare class SeqMatcher<Ctx> extends AbstractMatcher<Ctx> {
4
+ readonly seq: Matcher<Ctx>[];
5
+ readonly length: number;
6
+ private checkpoint;
7
+ private idx;
8
+ constructor({ matchers }: SeqMatcherOptions<Ctx>);
9
+ private isMatchingComplete;
10
+ private matchForward;
11
+ private backtrack;
12
+ match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
13
+ nextMatch(): Checkpoint<Ctx> | null;
14
+ }
15
15
  //# sourceMappingURL=seq-matcher.d.ts.map
@@ -1,73 +1,73 @@
1
- import { AbstractMatcher } from './abstract-matcher';
2
- export class SeqMatcher extends AbstractMatcher {
3
- constructor({ matchers }) {
4
- super();
5
- this.checkpoint = null;
6
- this.idx = 0;
7
- this.seq = matchers;
8
- this.length = this.seq.length;
9
- }
10
- isMatchingComplete() {
11
- return this.idx === this.length;
12
- }
13
- matchForward() {
14
- if (this.checkpoint) {
15
- while (this.idx < this.length) {
16
- const matcher = this.seq[this.idx];
17
- const checkpoint = matcher.match(this.checkpoint);
18
- if (!checkpoint) {
19
- break;
20
- }
21
- this.checkpoint = checkpoint;
22
- this.idx += 1;
23
- }
24
- if (this.isMatchingComplete()) {
25
- return this.checkpoint;
26
- }
27
- }
28
- return null;
29
- }
30
- backtrack() {
31
- while (this.idx > 0) {
32
- this.idx -= 1;
33
- const matcher = this.seq[this.idx];
34
- const match = matcher.nextMatch();
35
- if (match) {
36
- this.checkpoint = match;
37
- this.idx += 1;
38
- return match;
39
- }
40
- }
41
- return null;
42
- }
43
- match(checkpoint) {
44
- this.idx = 0;
45
- this.checkpoint = checkpoint;
46
- while (!this.isMatchingComplete()) {
47
- const forwardMatch = this.matchForward();
48
- if (!forwardMatch) {
49
- const backwardMatch = this.backtrack();
50
- if (!backwardMatch) {
51
- return null;
52
- }
53
- }
54
- }
55
- return this.checkpoint;
56
- }
57
- nextMatch() {
58
- if (!this.backtrack()) {
59
- return null;
60
- }
61
- while (!this.isMatchingComplete()) {
62
- const forwardMatch = this.matchForward();
63
- if (!forwardMatch) {
64
- const backwardMatch = this.backtrack();
65
- if (!backwardMatch) {
66
- return null;
67
- }
68
- }
69
- }
70
- return this.checkpoint;
71
- }
72
- }
1
+ import { AbstractMatcher } from './abstract-matcher';
2
+ export class SeqMatcher extends AbstractMatcher {
3
+ constructor({ matchers }) {
4
+ super();
5
+ this.checkpoint = null;
6
+ this.idx = 0;
7
+ this.seq = matchers;
8
+ this.length = this.seq.length;
9
+ }
10
+ isMatchingComplete() {
11
+ return this.idx === this.length;
12
+ }
13
+ matchForward() {
14
+ if (this.checkpoint) {
15
+ while (this.idx < this.length) {
16
+ const matcher = this.seq[this.idx];
17
+ const checkpoint = matcher.match(this.checkpoint);
18
+ if (!checkpoint) {
19
+ break;
20
+ }
21
+ this.checkpoint = checkpoint;
22
+ this.idx += 1;
23
+ }
24
+ if (this.isMatchingComplete()) {
25
+ return this.checkpoint;
26
+ }
27
+ }
28
+ return null;
29
+ }
30
+ backtrack() {
31
+ while (this.idx > 0) {
32
+ this.idx -= 1;
33
+ const matcher = this.seq[this.idx];
34
+ const match = matcher.nextMatch();
35
+ if (match) {
36
+ this.checkpoint = match;
37
+ this.idx += 1;
38
+ return match;
39
+ }
40
+ }
41
+ return null;
42
+ }
43
+ match(checkpoint) {
44
+ this.idx = 0;
45
+ this.checkpoint = checkpoint;
46
+ while (!this.isMatchingComplete()) {
47
+ const forwardMatch = this.matchForward();
48
+ if (!forwardMatch) {
49
+ const backwardMatch = this.backtrack();
50
+ if (!backwardMatch) {
51
+ return null;
52
+ }
53
+ }
54
+ }
55
+ return this.checkpoint;
56
+ }
57
+ nextMatch() {
58
+ if (!this.backtrack()) {
59
+ return null;
60
+ }
61
+ while (!this.isMatchingComplete()) {
62
+ const forwardMatch = this.matchForward();
63
+ if (!forwardMatch) {
64
+ const backwardMatch = this.backtrack();
65
+ if (!backwardMatch) {
66
+ return null;
67
+ }
68
+ }
69
+ }
70
+ return this.checkpoint;
71
+ }
72
+ }
73
73
  //# sourceMappingURL=seq-matcher.js.map
@@ -1,39 +1,39 @@
1
- import type { StringValueToken } from '../../lexer/types';
2
- import type { TemplateTree } from '../../parser/types';
3
- import type { Checkpoint, Matcher, NodeHandler, StrTplOptionsBase, StrTreeHandler, StrTreeOptionsBase } from '../types';
4
- import { AbstractMatcher } from './abstract-matcher';
5
- export type StrContentMatcherValue = string | RegExp | null;
6
- export type StrContentMatcherHandler<Ctx> = (ctx: Ctx, token: StringValueToken) => Ctx;
7
- export interface StrContentMatcherOptions<Ctx> {
8
- value: StrContentMatcherValue;
9
- handler: StrContentMatcherHandler<Ctx> | null;
10
- }
11
- export declare class StrContentMatcher<Ctx> extends AbstractMatcher<Ctx> {
12
- readonly content: StrContentMatcherValue;
13
- readonly handler: StrContentMatcherHandler<Ctx>;
14
- constructor({ value, handler }: StrContentMatcherOptions<Ctx>);
15
- match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
16
- }
17
- interface StrTplMatcherOptions<Ctx> extends StrTplOptionsBase<Ctx> {
18
- matcher: Matcher<Ctx>;
19
- }
20
- export declare class StrTplMatcher<Ctx> extends AbstractMatcher<Ctx> {
21
- readonly matcher: Matcher<Ctx>;
22
- readonly preHandler: NodeHandler<Ctx, TemplateTree>;
23
- readonly postHandler: NodeHandler<Ctx, TemplateTree>;
24
- constructor(config: StrTplMatcherOptions<Ctx>);
25
- match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
26
- }
27
- export type StrNodeChildMatcher<Ctx> = StrContentMatcher<Ctx> | StrTplMatcher<Ctx>;
28
- export interface StrMatcherOptions<Ctx> extends StrTreeOptionsBase<Ctx> {
29
- matchers: StrNodeChildMatcher<Ctx>[] | null;
30
- }
31
- export declare class StrNodeMatcher<Ctx> extends AbstractMatcher<Ctx> {
32
- matchers: StrNodeChildMatcher<Ctx>[] | null;
33
- readonly preHandler: StrTreeHandler<Ctx>;
34
- readonly postHandler: StrTreeHandler<Ctx>;
35
- constructor(opts: StrMatcherOptions<Ctx>);
36
- match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
37
- }
38
- export {};
1
+ import type { StringValueToken } from '../../lexer/types';
2
+ import type { TemplateTree } from '../../parser/types';
3
+ import type { Checkpoint, Matcher, NodeHandler, StrTplOptionsBase, StrTreeHandler, StrTreeOptionsBase } from '../types';
4
+ import { AbstractMatcher } from './abstract-matcher';
5
+ export type StrContentMatcherValue = string | RegExp | null;
6
+ export type StrContentMatcherHandler<Ctx> = (ctx: Ctx, token: StringValueToken) => Ctx;
7
+ export interface StrContentMatcherOptions<Ctx> {
8
+ value: StrContentMatcherValue;
9
+ handler: StrContentMatcherHandler<Ctx> | null;
10
+ }
11
+ export declare class StrContentMatcher<Ctx> extends AbstractMatcher<Ctx> {
12
+ readonly content: StrContentMatcherValue;
13
+ readonly handler: StrContentMatcherHandler<Ctx>;
14
+ constructor({ value, handler }: StrContentMatcherOptions<Ctx>);
15
+ match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
16
+ }
17
+ interface StrTplMatcherOptions<Ctx> extends StrTplOptionsBase<Ctx> {
18
+ matcher: Matcher<Ctx>;
19
+ }
20
+ export declare class StrTplMatcher<Ctx> extends AbstractMatcher<Ctx> {
21
+ readonly matcher: Matcher<Ctx>;
22
+ readonly preHandler: NodeHandler<Ctx, TemplateTree>;
23
+ readonly postHandler: NodeHandler<Ctx, TemplateTree>;
24
+ constructor(config: StrTplMatcherOptions<Ctx>);
25
+ match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
26
+ }
27
+ export type StrNodeChildMatcher<Ctx> = StrContentMatcher<Ctx> | StrTplMatcher<Ctx>;
28
+ export interface StrMatcherOptions<Ctx> extends StrTreeOptionsBase<Ctx> {
29
+ matchers: StrNodeChildMatcher<Ctx>[] | null;
30
+ }
31
+ export declare class StrNodeMatcher<Ctx> extends AbstractMatcher<Ctx> {
32
+ matchers: StrNodeChildMatcher<Ctx>[] | null;
33
+ readonly preHandler: StrTreeHandler<Ctx>;
34
+ readonly postHandler: StrTreeHandler<Ctx>;
35
+ constructor(opts: StrMatcherOptions<Ctx>);
36
+ match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
37
+ }
38
+ export {};
39
39
  //# sourceMappingURL=str-matcher.d.ts.map
@@ -1,103 +1,103 @@
1
- import { safeHandler } from '../handler';
2
- import { isRegex } from '../regex';
3
- import { AbstractMatcher } from './abstract-matcher';
4
- export class StrContentMatcher extends AbstractMatcher {
5
- constructor({ value, handler }) {
6
- super();
7
- this.content = value !== null && value !== void 0 ? value : null;
8
- this.handler = safeHandler(handler);
9
- }
10
- match(checkpoint) {
11
- let { cursor, context } = checkpoint;
12
- const node = cursor.node;
13
- if ((node === null || node === void 0 ? void 0 : node.type) === 'string-value') {
14
- let isMatched = true;
15
- if (typeof this.content === 'string') {
16
- isMatched = this.content === node.value;
17
- }
18
- else if (isRegex(this.content)) {
19
- isMatched = this.content.test(node.value);
20
- }
21
- if (isMatched) {
22
- context = this.handler(context, node);
23
- cursor = this.moveRight(cursor);
24
- return { cursor, context };
25
- }
26
- }
27
- return null;
28
- }
29
- }
30
- export class StrTplMatcher extends AbstractMatcher {
31
- constructor(config) {
32
- super();
33
- this.matcher = config.matcher;
34
- this.preHandler = safeHandler(config.preHandler);
35
- this.postHandler = safeHandler(config.postHandler);
36
- }
37
- match(checkpoint) {
38
- var _a;
39
- const { cursor: tplCursor, context: tplContext } = checkpoint;
40
- const rootNode = tplCursor.node;
41
- if ((rootNode === null || rootNode === void 0 ? void 0 : rootNode.type) === 'template-tree') {
42
- let cursor = checkpoint.cursor.down;
43
- if (cursor && cursor.node) {
44
- let context = this.preHandler(tplContext, rootNode);
45
- cursor = this.matcher.seekNext(cursor);
46
- const match = this.matcher.match({ context, cursor });
47
- if (match) {
48
- ({ cursor, context } = match);
49
- cursor = this.seekNext(cursor);
50
- if (((_a = cursor.node) === null || _a === void 0 ? void 0 : _a.type) === '_end') {
51
- context = this.postHandler(context, rootNode);
52
- cursor = this.moveRight(tplCursor);
53
- return { context, cursor };
54
- }
55
- }
56
- }
57
- }
58
- return null;
59
- }
60
- }
61
- export class StrNodeMatcher extends AbstractMatcher {
62
- constructor(opts) {
63
- var _a;
64
- super();
65
- this.matchers = (_a = opts.matchers) !== null && _a !== void 0 ? _a : null;
66
- this.preHandler = safeHandler(opts.preHandler);
67
- this.postHandler = safeHandler(opts.postHandler);
68
- }
69
- match(checkpoint) {
70
- var _a;
71
- const rootCursor = this.seekNext(checkpoint.cursor);
72
- const rootNode = rootCursor.node;
73
- if ((rootNode === null || rootNode === void 0 ? void 0 : rootNode.type) === 'string-tree') {
74
- let context = this.preHandler(checkpoint.context, rootNode);
75
- let cursor = rootCursor;
76
- if (this.matchers) {
77
- const tokensCount = cursor.children.length - 2;
78
- if (tokensCount !== this.matchers.length) {
79
- return null;
80
- }
81
- if (tokensCount > 0) {
82
- cursor = this.moveRight(cursor.down);
83
- for (const matcher of this.matchers) {
84
- const match = matcher.match({ context, cursor });
85
- if (!match) {
86
- return null;
87
- }
88
- ({ cursor, context } = match);
89
- }
90
- }
91
- }
92
- context = this.postHandler(context, rootNode);
93
- cursor = this.moveRight(rootCursor);
94
- return { context, cursor };
95
- }
96
- else if ((rootNode === null || rootNode === void 0 ? void 0 : rootNode.type) === 'string-value' && ((_a = this.matchers) === null || _a === void 0 ? void 0 : _a.length)) {
97
- const matcher = this.matchers[0];
98
- return matcher.match({ context: checkpoint.context, cursor: rootCursor });
99
- }
100
- return null;
101
- }
102
- }
1
+ import { safeHandler } from '../handler';
2
+ import { isRegex } from '../regex';
3
+ import { AbstractMatcher } from './abstract-matcher';
4
+ export class StrContentMatcher extends AbstractMatcher {
5
+ constructor({ value, handler }) {
6
+ super();
7
+ this.content = value !== null && value !== void 0 ? value : null;
8
+ this.handler = safeHandler(handler);
9
+ }
10
+ match(checkpoint) {
11
+ let { cursor, context } = checkpoint;
12
+ const node = cursor.node;
13
+ if ((node === null || node === void 0 ? void 0 : node.type) === 'string-value') {
14
+ let isMatched = true;
15
+ if (typeof this.content === 'string') {
16
+ isMatched = this.content === node.value;
17
+ }
18
+ else if (isRegex(this.content)) {
19
+ isMatched = this.content.test(node.value);
20
+ }
21
+ if (isMatched) {
22
+ context = this.handler(context, node);
23
+ cursor = this.moveRight(cursor);
24
+ return { cursor, context };
25
+ }
26
+ }
27
+ return null;
28
+ }
29
+ }
30
+ export class StrTplMatcher extends AbstractMatcher {
31
+ constructor(config) {
32
+ super();
33
+ this.matcher = config.matcher;
34
+ this.preHandler = safeHandler(config.preHandler);
35
+ this.postHandler = safeHandler(config.postHandler);
36
+ }
37
+ match(checkpoint) {
38
+ var _a;
39
+ const { cursor: tplCursor, context: tplContext } = checkpoint;
40
+ const rootNode = tplCursor.node;
41
+ if ((rootNode === null || rootNode === void 0 ? void 0 : rootNode.type) === 'template-tree') {
42
+ let cursor = checkpoint.cursor.down;
43
+ if (cursor && cursor.node) {
44
+ let context = this.preHandler(tplContext, rootNode);
45
+ cursor = this.matcher.seekNext(cursor);
46
+ const match = this.matcher.match({ context, cursor });
47
+ if (match) {
48
+ ({ cursor, context } = match);
49
+ cursor = this.seekNext(cursor);
50
+ if (((_a = cursor.node) === null || _a === void 0 ? void 0 : _a.type) === '_end') {
51
+ context = this.postHandler(context, rootNode);
52
+ cursor = this.moveRight(tplCursor);
53
+ return { context, cursor };
54
+ }
55
+ }
56
+ }
57
+ }
58
+ return null;
59
+ }
60
+ }
61
+ export class StrNodeMatcher extends AbstractMatcher {
62
+ constructor(opts) {
63
+ var _a;
64
+ super();
65
+ this.matchers = (_a = opts.matchers) !== null && _a !== void 0 ? _a : null;
66
+ this.preHandler = safeHandler(opts.preHandler);
67
+ this.postHandler = safeHandler(opts.postHandler);
68
+ }
69
+ match(checkpoint) {
70
+ var _a;
71
+ const rootCursor = this.seekNext(checkpoint.cursor);
72
+ const rootNode = rootCursor.node;
73
+ if ((rootNode === null || rootNode === void 0 ? void 0 : rootNode.type) === 'string-tree') {
74
+ let context = this.preHandler(checkpoint.context, rootNode);
75
+ let cursor = rootCursor;
76
+ if (this.matchers) {
77
+ const tokensCount = cursor.children.length - 2;
78
+ if (tokensCount !== this.matchers.length) {
79
+ return null;
80
+ }
81
+ if (tokensCount > 0) {
82
+ cursor = this.moveRight(cursor.down);
83
+ for (const matcher of this.matchers) {
84
+ const match = matcher.match({ context, cursor });
85
+ if (!match) {
86
+ return null;
87
+ }
88
+ ({ cursor, context } = match);
89
+ }
90
+ }
91
+ }
92
+ context = this.postHandler(context, rootNode);
93
+ cursor = this.moveRight(rootCursor);
94
+ return { context, cursor };
95
+ }
96
+ else if ((rootNode === null || rootNode === void 0 ? void 0 : rootNode.type) === 'string-value' && ((_a = this.matchers) === null || _a === void 0 ? void 0 : _a.length)) {
97
+ const matcher = this.matchers[0];
98
+ return matcher.match({ context: checkpoint.context, cursor: rootCursor });
99
+ }
100
+ return null;
101
+ }
102
+ }
103
103
  //# sourceMappingURL=str-matcher.js.map
@@ -1,9 +1,9 @@
1
- import type { Checkpoint, SymMatcherHandler, SymMatcherOptions, SymMatcherValue } from '../types';
2
- import { AbstractMatcher } from './abstract-matcher';
3
- export declare class SymMatcher<Ctx> extends AbstractMatcher<Ctx> {
4
- readonly sym: SymMatcherValue;
5
- readonly handler: SymMatcherHandler<Ctx>;
6
- constructor({ value, handler }: SymMatcherOptions<Ctx>);
7
- match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
8
- }
1
+ import type { Checkpoint, SymMatcherHandler, SymMatcherOptions, SymMatcherValue } from '../types';
2
+ import { AbstractMatcher } from './abstract-matcher';
3
+ export declare class SymMatcher<Ctx> extends AbstractMatcher<Ctx> {
4
+ readonly sym: SymMatcherValue;
5
+ readonly handler: SymMatcherHandler<Ctx>;
6
+ constructor({ value, handler }: SymMatcherOptions<Ctx>);
7
+ match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
8
+ }
9
9
  //# sourceMappingURL=sym-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 SymMatcher extends AbstractMatcher {
5
- constructor({ value, handler }) {
6
- super();
7
- this.sym = 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) === 'symbol') {
15
- let isMatched = true;
16
- if (typeof this.sym === 'string') {
17
- isMatched = this.sym === node.value;
18
- }
19
- else if (isRegex(this.sym)) {
20
- isMatched = this.sym.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 SymMatcher extends AbstractMatcher {
5
+ constructor({ value, handler }) {
6
+ super();
7
+ this.sym = 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) === 'symbol') {
15
+ let isMatched = true;
16
+ if (typeof this.sym === 'string') {
17
+ isMatched = this.sym === node.value;
18
+ }
19
+ else if (isRegex(this.sym)) {
20
+ isMatched = this.sym.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=sym-matcher.js.map
@@ -1,24 +1,24 @@
1
- import type { Cursor } from '../../parser/types';
2
- import type { Checkpoint, Matcher, TreeMatcherHandler, TreeMatcherType, TreeOptionsBase } from '../types';
3
- import { AbstractMatcher } from './abstract-matcher';
4
- interface TreeMatcherOptions<Ctx> extends TreeOptionsBase<Ctx> {
5
- matcher: Matcher<Ctx> | null;
6
- }
7
- export declare class TreeMatcher<Ctx> extends AbstractMatcher<Ctx> {
8
- readonly type: TreeMatcherType | null;
9
- readonly startsWithValue: string | null;
10
- readonly endsWithValue: string | null;
11
- readonly matcher: Matcher<Ctx> | null;
12
- readonly maxDepth: number;
13
- readonly maxMatches: number;
14
- readonly preHandler: TreeMatcherHandler<Ctx>;
15
- readonly postHandler: TreeMatcherHandler<Ctx>;
16
- private walkDepth;
17
- private matchCount;
18
- constructor(config: TreeMatcherOptions<Ctx>);
19
- walkToNextSignificantNode(cursor: Cursor): Cursor | undefined;
20
- walkToNextMatch(context: Ctx, cursor: Cursor | undefined): Checkpoint<Ctx> | undefined;
21
- match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
22
- }
23
- export {};
1
+ import type { Cursor } from '../../parser/types';
2
+ import type { Checkpoint, Matcher, TreeMatcherHandler, TreeMatcherType, TreeOptionsBase } from '../types';
3
+ import { AbstractMatcher } from './abstract-matcher';
4
+ interface TreeMatcherOptions<Ctx> extends TreeOptionsBase<Ctx> {
5
+ matcher: Matcher<Ctx> | null;
6
+ }
7
+ export declare class TreeMatcher<Ctx> extends AbstractMatcher<Ctx> {
8
+ readonly type: TreeMatcherType | null;
9
+ readonly startsWithValue: string | null;
10
+ readonly endsWithValue: string | null;
11
+ readonly matcher: Matcher<Ctx> | null;
12
+ readonly maxDepth: number;
13
+ readonly maxMatches: number;
14
+ readonly preHandler: TreeMatcherHandler<Ctx>;
15
+ readonly postHandler: TreeMatcherHandler<Ctx>;
16
+ private walkDepth;
17
+ private matchCount;
18
+ constructor(config: TreeMatcherOptions<Ctx>);
19
+ walkToNextSignificantNode(cursor: Cursor): Cursor | undefined;
20
+ walkToNextMatch(context: Ctx, cursor: Cursor | undefined): Checkpoint<Ctx> | undefined;
21
+ match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
22
+ }
23
+ export {};
24
24
  //# sourceMappingURL=tree-matcher.d.ts.map