@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,305 +1,305 @@
1
- import { AltMatcher, ManyMatcher, OpMatcher, SeqMatcher, SymMatcher, } from './matchers';
2
- import { BeginMatcher, EndMatcher, VoidMatcher, } from './matchers/anchor-matcher';
3
- import { CommentMatcher } from './matchers/comment-matcher';
4
- import { NumMatcher } from './matchers/num-matcher';
5
- import { StrContentMatcher, StrNodeMatcher, StrTplMatcher, } from './matchers/str-matcher';
6
- import { TreeMatcher } from './matchers/tree-matcher';
7
- import { coerceCommentOptions, coerceManyOptions, coerceNumOptions, coerceOpOptions, coerceStrOptions, coerceSymOptions, coerceTreeOptions, } from './options';
8
- import { isRegex } from './regex';
9
- class TerminalBuilder {
10
- handler(fn) {
11
- const voidMatcher = new VoidBuilder(fn);
12
- const builder = new SeqBuilder(this, voidMatcher);
13
- return builder;
14
- }
15
- }
16
- class AbstractBuilder extends TerminalBuilder {
17
- sym(arg1, arg2) {
18
- const opts = coerceSymOptions(arg1, arg2);
19
- const builder = new SymBuilder(opts);
20
- return new SeqBuilder(this, builder);
21
- }
22
- op(arg1, arg2) {
23
- const opts = coerceOpOptions(arg1, arg2);
24
- const builder = new OpBuilder(opts);
25
- return new SeqBuilder(this, builder);
26
- }
27
- comment(arg1, arg2) {
28
- const opts = coerceCommentOptions(arg1, arg2);
29
- const builder = new CommentBuilder(opts);
30
- return new SeqBuilder(this, builder);
31
- }
32
- num(arg1, arg2) {
33
- const opts = coerceNumOptions(arg1, arg2);
34
- const builder = new NumBuilder(opts);
35
- return new SeqBuilder(this, builder);
36
- }
37
- many(arg1, arg2, arg3) {
38
- const opts = coerceManyOptions(arg1, arg2, arg3);
39
- const builder = new ManyBuilder(opts);
40
- return new SeqBuilder(this, builder);
41
- }
42
- opt(innerBuilder) {
43
- const opts = coerceManyOptions(innerBuilder, 0, 1);
44
- const builder = new ManyBuilder(opts);
45
- return new SeqBuilder(this, builder);
46
- }
47
- alt(...alts) {
48
- const builder = new AltBuilder(alts);
49
- return new SeqBuilder(this, builder);
50
- }
51
- tree(arg1) {
52
- const opts = coerceTreeOptions(arg1);
53
- const builder = new TreeBuilder(opts);
54
- return new SeqBuilder(this, builder);
55
- }
56
- str(arg1, arg2) {
57
- const opts = coerceStrOptions(arg1, arg2);
58
- const builder = new StrBuilder(opts);
59
- return new SeqBuilder(this, builder);
60
- }
61
- end() {
62
- return new EndBuilder(this);
63
- }
64
- join(other) {
65
- const builder = new SeqBuilder(this, other);
66
- return builder;
67
- }
68
- }
69
- // Anchors
70
- export class BeginBuilder extends AbstractBuilder {
71
- build() {
72
- return new BeginMatcher();
73
- }
74
- }
75
- export class EndBuilder extends TerminalBuilder {
76
- constructor(builder) {
77
- super();
78
- this.builder = builder;
79
- }
80
- build() {
81
- const matcher = this.builder.build();
82
- const matchers = matcher instanceof SeqMatcher ? matcher.seq : [matcher];
83
- matchers.push(new EndMatcher());
84
- return new SeqMatcher({ matchers });
85
- }
86
- }
87
- export function begin() {
88
- return new BeginBuilder();
89
- }
90
- export class VoidBuilder extends AbstractBuilder {
91
- constructor(fn) {
92
- super();
93
- this.fn = fn;
94
- }
95
- build() {
96
- return new VoidMatcher(this.fn);
97
- }
98
- }
99
- export function handler(fn) {
100
- return new VoidBuilder(fn);
101
- }
102
- // Sequence
103
- export class SeqBuilder extends AbstractBuilder {
104
- constructor(prev, next) {
105
- super();
106
- const prevSeq = prev instanceof SeqBuilder
107
- ? prev.builders
108
- : [prev];
109
- const nextSeq = next instanceof SeqBuilder
110
- ? next.builders
111
- : [next];
112
- this.builders = [...prevSeq, ...nextSeq];
113
- }
114
- build() {
115
- const matchers = this.builders.map((builder) => builder.build());
116
- return new SeqMatcher({ matchers });
117
- }
118
- }
119
- export function join(first, second, ...others) {
120
- const seq = new SeqBuilder(first, second);
121
- if (!others.length) {
122
- return seq;
123
- }
124
- return others.reduce((res, query) => {
125
- return res.join(query);
126
- }, seq);
127
- }
128
- // Symbols
129
- export class SymBuilder extends AbstractBuilder {
130
- constructor(opts) {
131
- super();
132
- this.opts = opts;
133
- }
134
- build() {
135
- return new SymMatcher(this.opts);
136
- }
137
- }
138
- export function sym(arg1, arg2) {
139
- const opts = coerceSymOptions(arg1, arg2);
140
- return new SymBuilder(opts);
141
- }
142
- // Operators
143
- export class OpBuilder extends AbstractBuilder {
144
- constructor(opts) {
145
- super();
146
- this.opts = opts;
147
- }
148
- build() {
149
- return new OpMatcher(this.opts);
150
- }
151
- }
152
- export function op(arg1, arg2) {
153
- const opts = coerceOpOptions(arg1, arg2);
154
- return new OpBuilder(opts);
155
- }
156
- // Comments
157
- export class CommentBuilder extends AbstractBuilder {
158
- constructor(opts) {
159
- super();
160
- this.opts = opts;
161
- }
162
- build() {
163
- return new CommentMatcher(this.opts);
164
- }
165
- }
166
- export function comment(arg1, arg2) {
167
- const opts = coerceCommentOptions(arg1, arg2);
168
- return new CommentBuilder(opts);
169
- }
170
- // Numbers
171
- export class NumBuilder extends AbstractBuilder {
172
- constructor(opts) {
173
- super();
174
- this.opts = opts;
175
- }
176
- build() {
177
- return new NumMatcher(this.opts);
178
- }
179
- }
180
- export function num(arg1, arg2) {
181
- const opts = coerceNumOptions(arg1, arg2);
182
- return new NumBuilder(opts);
183
- }
184
- // Repetitive patterns
185
- export class ManyBuilder extends AbstractBuilder {
186
- constructor(opts) {
187
- super();
188
- this.opts = opts;
189
- }
190
- build() {
191
- const matcher = this.opts.builder.build();
192
- return new ManyMatcher({ ...this.opts, matcher });
193
- }
194
- }
195
- export function many(arg1, arg2, arg3) {
196
- const opts = coerceManyOptions(arg1, arg2, arg3);
197
- return new ManyBuilder(opts);
198
- }
199
- export function opt(builder) {
200
- const opts = coerceManyOptions(builder, 0, 1);
201
- return new ManyBuilder(opts);
202
- }
203
- // Alternatives
204
- export class AltBuilder extends AbstractBuilder {
205
- constructor(builders) {
206
- super();
207
- this.builders = builders;
208
- }
209
- build() {
210
- const matchers = this.builders.map((alt) => alt.build());
211
- return new AltMatcher({ matchers });
212
- }
213
- }
214
- export function alt(...builders) {
215
- return new AltBuilder(builders);
216
- }
217
- // Trees
218
- export class TreeBuilder extends AbstractBuilder {
219
- constructor(opts) {
220
- super();
221
- this.opts = opts;
222
- }
223
- build() {
224
- const builderOpts = this.opts;
225
- const matcher = builderOpts.search ? builderOpts.search.build() : null;
226
- const matcherOpts = { ...builderOpts, matcher };
227
- return new TreeMatcher(matcherOpts);
228
- }
229
- }
230
- export function tree(arg1) {
231
- const opts = coerceTreeOptions(arg1);
232
- return new TreeBuilder(opts);
233
- }
234
- // Strings
235
- export class StrBuilder extends AbstractBuilder {
236
- constructor(opts) {
237
- super();
238
- this.opts = opts;
239
- }
240
- build() {
241
- var _a, _b, _c, _d, _e, _f;
242
- if (this.opts.type === 'str-content') {
243
- return new StrNodeMatcher({
244
- matchers: [
245
- new StrContentMatcher({
246
- value: (_a = this.opts.match) !== null && _a !== void 0 ? _a : null,
247
- handler: (_b = this.opts.handler) !== null && _b !== void 0 ? _b : null,
248
- }),
249
- ],
250
- preHandler: null,
251
- postHandler: null,
252
- });
253
- }
254
- if (this.opts.match) {
255
- const matchers = [];
256
- this.opts.match.forEach((m) => {
257
- if (typeof m === 'string' || isRegex(m)) {
258
- const contentMatcher = new StrContentMatcher({
259
- value: m,
260
- handler: null,
261
- });
262
- matchers.push(contentMatcher);
263
- }
264
- else if (m instanceof StrBuilder) {
265
- const childStrMatcher = m.build();
266
- if (childStrMatcher.matchers) {
267
- matchers.push(...childStrMatcher.matchers);
268
- }
269
- }
270
- else if (m instanceof StrTplMatcher) {
271
- matchers.push(m);
272
- }
273
- else {
274
- const tplMatcher = new StrTplMatcher({
275
- matcher: m.build(),
276
- preHandler: null,
277
- postHandler: null,
278
- });
279
- matchers.push(tplMatcher);
280
- }
281
- });
282
- return new StrNodeMatcher({
283
- matchers: matchers,
284
- preHandler: (_c = this.opts.preHandler) !== null && _c !== void 0 ? _c : null,
285
- postHandler: (_d = this.opts.postHandler) !== null && _d !== void 0 ? _d : null,
286
- });
287
- }
288
- return new StrNodeMatcher({
289
- matchers: null,
290
- preHandler: (_e = this.opts.preHandler) !== null && _e !== void 0 ? _e : null,
291
- postHandler: (_f = this.opts.postHandler) !== null && _f !== void 0 ? _f : null,
292
- });
293
- }
294
- }
295
- export function str(arg1, arg2) {
296
- const opts = coerceStrOptions(arg1, arg2);
297
- return new StrBuilder(opts);
298
- }
299
- export function buildRoot(builder) {
300
- const matcher = builder.build();
301
- return matcher instanceof TreeMatcher && matcher.type === 'root-tree'
302
- ? matcher
303
- : new TreeMatcher({ matcher, type: 'root-tree' });
304
- }
1
+ import { AltMatcher, ManyMatcher, OpMatcher, SeqMatcher, SymMatcher, } from './matchers';
2
+ import { BeginMatcher, EndMatcher, VoidMatcher, } from './matchers/anchor-matcher';
3
+ import { CommentMatcher } from './matchers/comment-matcher';
4
+ import { NumMatcher } from './matchers/num-matcher';
5
+ import { StrContentMatcher, StrNodeMatcher, StrTplMatcher, } from './matchers/str-matcher';
6
+ import { TreeMatcher } from './matchers/tree-matcher';
7
+ import { coerceCommentOptions, coerceManyOptions, coerceNumOptions, coerceOpOptions, coerceStrOptions, coerceSymOptions, coerceTreeOptions, } from './options';
8
+ import { isRegex } from './regex';
9
+ class TerminalBuilder {
10
+ handler(fn) {
11
+ const voidMatcher = new VoidBuilder(fn);
12
+ const builder = new SeqBuilder(this, voidMatcher);
13
+ return builder;
14
+ }
15
+ }
16
+ class AbstractBuilder extends TerminalBuilder {
17
+ sym(arg1, arg2) {
18
+ const opts = coerceSymOptions(arg1, arg2);
19
+ const builder = new SymBuilder(opts);
20
+ return new SeqBuilder(this, builder);
21
+ }
22
+ op(arg1, arg2) {
23
+ const opts = coerceOpOptions(arg1, arg2);
24
+ const builder = new OpBuilder(opts);
25
+ return new SeqBuilder(this, builder);
26
+ }
27
+ comment(arg1, arg2) {
28
+ const opts = coerceCommentOptions(arg1, arg2);
29
+ const builder = new CommentBuilder(opts);
30
+ return new SeqBuilder(this, builder);
31
+ }
32
+ num(arg1, arg2) {
33
+ const opts = coerceNumOptions(arg1, arg2);
34
+ const builder = new NumBuilder(opts);
35
+ return new SeqBuilder(this, builder);
36
+ }
37
+ many(arg1, arg2, arg3) {
38
+ const opts = coerceManyOptions(arg1, arg2, arg3);
39
+ const builder = new ManyBuilder(opts);
40
+ return new SeqBuilder(this, builder);
41
+ }
42
+ opt(innerBuilder) {
43
+ const opts = coerceManyOptions(innerBuilder, 0, 1);
44
+ const builder = new ManyBuilder(opts);
45
+ return new SeqBuilder(this, builder);
46
+ }
47
+ alt(...alts) {
48
+ const builder = new AltBuilder(alts);
49
+ return new SeqBuilder(this, builder);
50
+ }
51
+ tree(arg1) {
52
+ const opts = coerceTreeOptions(arg1);
53
+ const builder = new TreeBuilder(opts);
54
+ return new SeqBuilder(this, builder);
55
+ }
56
+ str(arg1, arg2) {
57
+ const opts = coerceStrOptions(arg1, arg2);
58
+ const builder = new StrBuilder(opts);
59
+ return new SeqBuilder(this, builder);
60
+ }
61
+ end() {
62
+ return new EndBuilder(this);
63
+ }
64
+ join(other) {
65
+ const builder = new SeqBuilder(this, other);
66
+ return builder;
67
+ }
68
+ }
69
+ // Anchors
70
+ export class BeginBuilder extends AbstractBuilder {
71
+ build() {
72
+ return new BeginMatcher();
73
+ }
74
+ }
75
+ export class EndBuilder extends TerminalBuilder {
76
+ constructor(builder) {
77
+ super();
78
+ this.builder = builder;
79
+ }
80
+ build() {
81
+ const matcher = this.builder.build();
82
+ const matchers = matcher instanceof SeqMatcher ? matcher.seq : [matcher];
83
+ matchers.push(new EndMatcher());
84
+ return new SeqMatcher({ matchers });
85
+ }
86
+ }
87
+ export function begin() {
88
+ return new BeginBuilder();
89
+ }
90
+ export class VoidBuilder extends AbstractBuilder {
91
+ constructor(fn) {
92
+ super();
93
+ this.fn = fn;
94
+ }
95
+ build() {
96
+ return new VoidMatcher(this.fn);
97
+ }
98
+ }
99
+ export function handler(fn) {
100
+ return new VoidBuilder(fn);
101
+ }
102
+ // Sequence
103
+ export class SeqBuilder extends AbstractBuilder {
104
+ constructor(prev, next) {
105
+ super();
106
+ const prevSeq = prev instanceof SeqBuilder
107
+ ? prev.builders
108
+ : [prev];
109
+ const nextSeq = next instanceof SeqBuilder
110
+ ? next.builders
111
+ : [next];
112
+ this.builders = [...prevSeq, ...nextSeq];
113
+ }
114
+ build() {
115
+ const matchers = this.builders.map((builder) => builder.build());
116
+ return new SeqMatcher({ matchers });
117
+ }
118
+ }
119
+ export function join(first, second, ...others) {
120
+ const seq = new SeqBuilder(first, second);
121
+ if (!others.length) {
122
+ return seq;
123
+ }
124
+ return others.reduce((res, query) => {
125
+ return res.join(query);
126
+ }, seq);
127
+ }
128
+ // Symbols
129
+ export class SymBuilder extends AbstractBuilder {
130
+ constructor(opts) {
131
+ super();
132
+ this.opts = opts;
133
+ }
134
+ build() {
135
+ return new SymMatcher(this.opts);
136
+ }
137
+ }
138
+ export function sym(arg1, arg2) {
139
+ const opts = coerceSymOptions(arg1, arg2);
140
+ return new SymBuilder(opts);
141
+ }
142
+ // Operators
143
+ export class OpBuilder extends AbstractBuilder {
144
+ constructor(opts) {
145
+ super();
146
+ this.opts = opts;
147
+ }
148
+ build() {
149
+ return new OpMatcher(this.opts);
150
+ }
151
+ }
152
+ export function op(arg1, arg2) {
153
+ const opts = coerceOpOptions(arg1, arg2);
154
+ return new OpBuilder(opts);
155
+ }
156
+ // Comments
157
+ export class CommentBuilder extends AbstractBuilder {
158
+ constructor(opts) {
159
+ super();
160
+ this.opts = opts;
161
+ }
162
+ build() {
163
+ return new CommentMatcher(this.opts);
164
+ }
165
+ }
166
+ export function comment(arg1, arg2) {
167
+ const opts = coerceCommentOptions(arg1, arg2);
168
+ return new CommentBuilder(opts);
169
+ }
170
+ // Numbers
171
+ export class NumBuilder extends AbstractBuilder {
172
+ constructor(opts) {
173
+ super();
174
+ this.opts = opts;
175
+ }
176
+ build() {
177
+ return new NumMatcher(this.opts);
178
+ }
179
+ }
180
+ export function num(arg1, arg2) {
181
+ const opts = coerceNumOptions(arg1, arg2);
182
+ return new NumBuilder(opts);
183
+ }
184
+ // Repetitive patterns
185
+ export class ManyBuilder extends AbstractBuilder {
186
+ constructor(opts) {
187
+ super();
188
+ this.opts = opts;
189
+ }
190
+ build() {
191
+ const matcher = this.opts.builder.build();
192
+ return new ManyMatcher({ ...this.opts, matcher });
193
+ }
194
+ }
195
+ export function many(arg1, arg2, arg3) {
196
+ const opts = coerceManyOptions(arg1, arg2, arg3);
197
+ return new ManyBuilder(opts);
198
+ }
199
+ export function opt(builder) {
200
+ const opts = coerceManyOptions(builder, 0, 1);
201
+ return new ManyBuilder(opts);
202
+ }
203
+ // Alternatives
204
+ export class AltBuilder extends AbstractBuilder {
205
+ constructor(builders) {
206
+ super();
207
+ this.builders = builders;
208
+ }
209
+ build() {
210
+ const matchers = this.builders.map((alt) => alt.build());
211
+ return new AltMatcher({ matchers });
212
+ }
213
+ }
214
+ export function alt(...builders) {
215
+ return new AltBuilder(builders);
216
+ }
217
+ // Trees
218
+ export class TreeBuilder extends AbstractBuilder {
219
+ constructor(opts) {
220
+ super();
221
+ this.opts = opts;
222
+ }
223
+ build() {
224
+ const builderOpts = this.opts;
225
+ const matcher = builderOpts.search ? builderOpts.search.build() : null;
226
+ const matcherOpts = { ...builderOpts, matcher };
227
+ return new TreeMatcher(matcherOpts);
228
+ }
229
+ }
230
+ export function tree(arg1) {
231
+ const opts = coerceTreeOptions(arg1);
232
+ return new TreeBuilder(opts);
233
+ }
234
+ // Strings
235
+ export class StrBuilder extends AbstractBuilder {
236
+ constructor(opts) {
237
+ super();
238
+ this.opts = opts;
239
+ }
240
+ build() {
241
+ var _a, _b, _c, _d, _e, _f;
242
+ if (this.opts.type === 'str-content') {
243
+ return new StrNodeMatcher({
244
+ matchers: [
245
+ new StrContentMatcher({
246
+ value: (_a = this.opts.match) !== null && _a !== void 0 ? _a : null,
247
+ handler: (_b = this.opts.handler) !== null && _b !== void 0 ? _b : null,
248
+ }),
249
+ ],
250
+ preHandler: null,
251
+ postHandler: null,
252
+ });
253
+ }
254
+ if (this.opts.match) {
255
+ const matchers = [];
256
+ this.opts.match.forEach((m) => {
257
+ if (typeof m === 'string' || isRegex(m)) {
258
+ const contentMatcher = new StrContentMatcher({
259
+ value: m,
260
+ handler: null,
261
+ });
262
+ matchers.push(contentMatcher);
263
+ }
264
+ else if (m instanceof StrBuilder) {
265
+ const childStrMatcher = m.build();
266
+ if (childStrMatcher.matchers) {
267
+ matchers.push(...childStrMatcher.matchers);
268
+ }
269
+ }
270
+ else if (m instanceof StrTplMatcher) {
271
+ matchers.push(m);
272
+ }
273
+ else {
274
+ const tplMatcher = new StrTplMatcher({
275
+ matcher: m.build(),
276
+ preHandler: null,
277
+ postHandler: null,
278
+ });
279
+ matchers.push(tplMatcher);
280
+ }
281
+ });
282
+ return new StrNodeMatcher({
283
+ matchers: matchers,
284
+ preHandler: (_c = this.opts.preHandler) !== null && _c !== void 0 ? _c : null,
285
+ postHandler: (_d = this.opts.postHandler) !== null && _d !== void 0 ? _d : null,
286
+ });
287
+ }
288
+ return new StrNodeMatcher({
289
+ matchers: null,
290
+ preHandler: (_e = this.opts.preHandler) !== null && _e !== void 0 ? _e : null,
291
+ postHandler: (_f = this.opts.postHandler) !== null && _f !== void 0 ? _f : null,
292
+ });
293
+ }
294
+ }
295
+ export function str(arg1, arg2) {
296
+ const opts = coerceStrOptions(arg1, arg2);
297
+ return new StrBuilder(opts);
298
+ }
299
+ export function buildRoot(builder) {
300
+ const matcher = builder.build();
301
+ return matcher instanceof TreeMatcher && matcher.type === 'root-tree'
302
+ ? matcher
303
+ : new TreeMatcher({ matcher, type: 'root-tree' });
304
+ }
305
305
  //# sourceMappingURL=builder.js.map
@@ -1,3 +1,3 @@
1
- import type { Node } from '../parser/types';
2
- export declare function safeHandler<Ctx, T extends Node = Node>(handler: ((ctx: Ctx, token: T) => Ctx) | null | undefined): (ctx: Ctx, token: T) => Ctx;
1
+ import type { Node } from '../parser/types';
2
+ export declare function safeHandler<Ctx, T extends Node = Node>(handler: ((ctx: Ctx, token: T) => Ctx) | null | undefined): (ctx: Ctx, token: T) => Ctx;
3
3
  //# sourceMappingURL=handler.d.ts.map
@@ -1,7 +1,7 @@
1
- import { clone } from '../util/clone';
2
- export function safeHandler(handler) {
3
- return handler
4
- ? (context, token) => handler(clone(context), token)
5
- : (context, _) => context;
6
- }
1
+ import { clone } from '../util/clone';
2
+ export function safeHandler(handler) {
3
+ return handler
4
+ ? (context, token) => handler(clone(context), token)
5
+ : (context, _) => context;
6
+ }
7
7
  //# sourceMappingURL=handler.js.map
@@ -1,3 +1,3 @@
1
- export { begin, handler, join, sym, op, comment, num, many, opt, alt, tree, str, buildRoot, } from './builder';
2
- export * from './types';
1
+ export { begin, handler, join, sym, op, comment, num, many, opt, alt, tree, str, buildRoot, } from './builder';
2
+ export * from './types';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,3 +1,3 @@
1
- export { begin, handler, join, sym, op, comment, num, many, opt, alt, tree, str, buildRoot, } from './builder';
2
- export * from './types';
1
+ export { begin, handler, join, sym, op, comment, num, many, opt, alt, tree, str, buildRoot, } from './builder';
2
+ export * from './types';
3
3
  //# sourceMappingURL=index.js.map
@@ -1,10 +1,10 @@
1
- import type { Cursor, Node } from '../../parser';
2
- import type { Checkpoint, Matcher } from '../types';
3
- export declare abstract class AbstractMatcher<Ctx> implements Matcher<Ctx> {
4
- canSkip(node: Node): boolean;
5
- seekNext(cursor: Cursor): Cursor;
6
- moveRight(cursor: Cursor): Cursor;
7
- abstract match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
8
- nextMatch(): Checkpoint<Ctx> | null;
9
- }
1
+ import type { Cursor, Node } from '../../parser';
2
+ import type { Checkpoint, Matcher } from '../types';
3
+ export declare abstract class AbstractMatcher<Ctx> implements Matcher<Ctx> {
4
+ canSkip(node: Node): boolean;
5
+ seekNext(cursor: Cursor): Cursor;
6
+ moveRight(cursor: Cursor): Cursor;
7
+ abstract match(checkpoint: Checkpoint<Ctx>): Checkpoint<Ctx> | null;
8
+ nextMatch(): Checkpoint<Ctx> | null;
9
+ }
10
10
  //# sourceMappingURL=abstract-matcher.d.ts.map