@chr33s/pdf-dfa 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +91 -0
  2. package/dfa.d.ts +44 -0
  3. package/dist/compile.d.ts +6 -0
  4. package/dist/compile.js +22 -0
  5. package/dist/compile.js.map +1 -0
  6. package/dist/dfa.d.ts +16 -0
  7. package/dist/dfa.js +81 -0
  8. package/dist/dfa.js.map +1 -0
  9. package/dist/grammar.d.ts +11 -0
  10. package/dist/grammar.js +1266 -0
  11. package/dist/grammar.js.map +1 -0
  12. package/dist/index.d.ts +3 -0
  13. package/dist/index.js +4 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/nodes.d.ts +113 -0
  16. package/dist/nodes.js +241 -0
  17. package/dist/nodes.js.map +1 -0
  18. package/dist/state-machine.d.ts +29 -0
  19. package/dist/state-machine.js +71 -0
  20. package/dist/state-machine.js.map +1 -0
  21. package/dist/symbol-table.d.ts +17 -0
  22. package/dist/symbol-table.js +64 -0
  23. package/dist/symbol-table.js.map +1 -0
  24. package/dist/utils.d.ts +12 -0
  25. package/dist/utils.js +34 -0
  26. package/dist/utils.js.map +1 -0
  27. package/package.json +41 -0
  28. package/scripts/build-grammar.ts +33 -0
  29. package/src/compile.ts +31 -0
  30. package/src/dfa.ts +104 -0
  31. package/src/grammar.js +1312 -0
  32. package/src/grammar.peg +72 -0
  33. package/src/index.ts +9 -0
  34. package/src/nodes.ts +308 -0
  35. package/src/state-machine.ts +94 -0
  36. package/src/symbol-table.ts +78 -0
  37. package/src/utils.ts +38 -0
  38. package/test/compile.test.ts +131 -0
  39. package/test/dfa.test.ts +87 -0
  40. package/test/nodes.test.ts +324 -0
  41. package/test/parse-build.test.ts +50 -0
  42. package/test/state-machine.test.ts +132 -0
  43. package/test/symbol-table.test.ts +69 -0
  44. package/test/utils.test.ts +108 -0
  45. package/tsconfig.json +16 -0
  46. package/tsconfig.test.json +8 -0
  47. package/tsconfig.typecheck.json +16 -0
  48. package/vitest.config.ts +8 -0
@@ -0,0 +1,1266 @@
1
+ // @ts-nocheck
2
+ // This file is generated by scripts/build-grammar.ts. Do not edit by hand.
3
+ // @generated by Peggy 5.0.6.
4
+ //
5
+ // https://peggyjs.org/
6
+ class peg$SyntaxError extends SyntaxError {
7
+ constructor(message, expected, found, location) {
8
+ super(message);
9
+ this.expected = expected;
10
+ this.found = found;
11
+ this.location = location;
12
+ this.name = "SyntaxError";
13
+ }
14
+ format(sources) {
15
+ let str = "Error: " + this.message;
16
+ if (this.location) {
17
+ let src = null;
18
+ const st = sources.find(s => s.source === this.location.source);
19
+ if (st) {
20
+ src = st.text.split(/\r\n|\n|\r/g);
21
+ }
22
+ const s = this.location.start;
23
+ const offset_s = (this.location.source && (typeof this.location.source.offset === "function"))
24
+ ? this.location.source.offset(s)
25
+ : s;
26
+ const loc = this.location.source + ":" + offset_s.line + ":" + offset_s.column;
27
+ if (src) {
28
+ const e = this.location.end;
29
+ const filler = "".padEnd(offset_s.line.toString().length, " ");
30
+ const line = src[s.line - 1];
31
+ const last = s.line === e.line ? e.column : line.length + 1;
32
+ const hatLen = (last - s.column) || 1;
33
+ str += "\n --> " + loc + "\n"
34
+ + filler + " |\n"
35
+ + offset_s.line + " | " + line + "\n"
36
+ + filler + " | " + "".padEnd(s.column - 1, " ")
37
+ + "".padEnd(hatLen, "^");
38
+ }
39
+ else {
40
+ str += "\n at " + loc;
41
+ }
42
+ }
43
+ return str;
44
+ }
45
+ static buildMessage(expected, found) {
46
+ function hex(ch) {
47
+ return ch.codePointAt(0).toString(16).toUpperCase();
48
+ }
49
+ const nonPrintable = Object.prototype.hasOwnProperty.call(RegExp.prototype, "unicode")
50
+ ? new RegExp("[\\p{C}\\p{Mn}\\p{Mc}]", "gu")
51
+ : null;
52
+ function unicodeEscape(s) {
53
+ if (nonPrintable) {
54
+ return s.replace(nonPrintable, ch => "\\u{" + hex(ch) + "}");
55
+ }
56
+ return s;
57
+ }
58
+ function literalEscape(s) {
59
+ return unicodeEscape(s
60
+ .replace(/\\/g, "\\\\")
61
+ .replace(/"/g, "\\\"")
62
+ .replace(/\0/g, "\\0")
63
+ .replace(/\t/g, "\\t")
64
+ .replace(/\n/g, "\\n")
65
+ .replace(/\r/g, "\\r")
66
+ .replace(/[\x00-\x0F]/g, ch => "\\x0" + hex(ch))
67
+ .replace(/[\x10-\x1F\x7F-\x9F]/g, ch => "\\x" + hex(ch)));
68
+ }
69
+ function classEscape(s) {
70
+ return unicodeEscape(s
71
+ .replace(/\\/g, "\\\\")
72
+ .replace(/\]/g, "\\]")
73
+ .replace(/\^/g, "\\^")
74
+ .replace(/-/g, "\\-")
75
+ .replace(/\0/g, "\\0")
76
+ .replace(/\t/g, "\\t")
77
+ .replace(/\n/g, "\\n")
78
+ .replace(/\r/g, "\\r")
79
+ .replace(/[\x00-\x0F]/g, ch => "\\x0" + hex(ch))
80
+ .replace(/[\x10-\x1F\x7F-\x9F]/g, ch => "\\x" + hex(ch)));
81
+ }
82
+ const DESCRIBE_EXPECTATION_FNS = {
83
+ literal(expectation) {
84
+ return "\"" + literalEscape(expectation.text) + "\"";
85
+ },
86
+ class(expectation) {
87
+ const escapedParts = expectation.parts.map(part => (Array.isArray(part)
88
+ ? classEscape(part[0]) + "-" + classEscape(part[1])
89
+ : classEscape(part)));
90
+ return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]" + (expectation.unicode ? "u" : "");
91
+ },
92
+ any() {
93
+ return "any character";
94
+ },
95
+ end() {
96
+ return "end of input";
97
+ },
98
+ other(expectation) {
99
+ return expectation.description;
100
+ },
101
+ };
102
+ function describeExpectation(expectation) {
103
+ return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
104
+ }
105
+ function describeExpected(expected) {
106
+ const descriptions = expected.map(describeExpectation);
107
+ descriptions.sort();
108
+ if (descriptions.length > 0) {
109
+ let j = 1;
110
+ for (let i = 1; i < descriptions.length; i++) {
111
+ if (descriptions[i - 1] !== descriptions[i]) {
112
+ descriptions[j] = descriptions[i];
113
+ j++;
114
+ }
115
+ }
116
+ descriptions.length = j;
117
+ }
118
+ switch (descriptions.length) {
119
+ case 1:
120
+ return descriptions[0];
121
+ case 2:
122
+ return descriptions[0] + " or " + descriptions[1];
123
+ default:
124
+ return descriptions.slice(0, -1).join(", ")
125
+ + ", or "
126
+ + descriptions[descriptions.length - 1];
127
+ }
128
+ }
129
+ function describeFound(found) {
130
+ return found ? "\"" + literalEscape(found) + "\"" : "end of input";
131
+ }
132
+ return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
133
+ }
134
+ }
135
+ function peg$parse(input, options) {
136
+ options = options !== undefined ? options : {};
137
+ const peg$FAILED = {};
138
+ const peg$source = options.grammarSource;
139
+ const peg$startRuleFunctions = {
140
+ rules: peg$parserules,
141
+ };
142
+ let peg$startRuleFunction = peg$parserules;
143
+ const peg$c0 = "#";
144
+ const peg$c1 = "=";
145
+ const peg$c2 = ";";
146
+ const peg$c3 = "|";
147
+ const peg$c4 = ":";
148
+ const peg$c5 = "*";
149
+ const peg$c6 = "?";
150
+ const peg$c7 = "+";
151
+ const peg$c8 = "{";
152
+ const peg$c9 = "}";
153
+ const peg$c10 = ",";
154
+ const peg$c11 = "(";
155
+ const peg$c12 = ")";
156
+ const peg$r0 = /^[^\r\n]/;
157
+ const peg$r1 = /^[\r\n]/;
158
+ const peg$r2 = /^[A-Z_a-z]/;
159
+ const peg$r3 = /^[0-9A-Z_a-z]/;
160
+ const peg$r4 = /^[0-9]/;
161
+ const peg$r5 = /^[ \t\r\n]/;
162
+ const peg$e0 = peg$literalExpectation("#", false);
163
+ const peg$e1 = peg$classExpectation(["\r", "\n"], true, false, false);
164
+ const peg$e2 = peg$classExpectation(["\r", "\n"], false, false, false);
165
+ const peg$e3 = peg$literalExpectation("=", false);
166
+ const peg$e4 = peg$literalExpectation(";", false);
167
+ const peg$e5 = peg$literalExpectation("|", false);
168
+ const peg$e6 = peg$literalExpectation(":", false);
169
+ const peg$e7 = peg$literalExpectation("*", false);
170
+ const peg$e8 = peg$literalExpectation("?", false);
171
+ const peg$e9 = peg$literalExpectation("+", false);
172
+ const peg$e10 = peg$literalExpectation("{", false);
173
+ const peg$e11 = peg$literalExpectation("}", false);
174
+ const peg$e12 = peg$literalExpectation(",", false);
175
+ const peg$e13 = peg$literalExpectation("(", false);
176
+ const peg$e14 = peg$literalExpectation(")", false);
177
+ const peg$e15 = peg$classExpectation([["A", "Z"], "_", ["a", "z"]], false, false, false);
178
+ const peg$e16 = peg$classExpectation([["0", "9"], ["A", "Z"], "_", ["a", "z"]], false, false, false);
179
+ const peg$e17 = peg$classExpectation([["0", "9"]], false, false, false);
180
+ const peg$e18 = peg$classExpectation([" ", "\t", "\r", "\n"], false, false, false);
181
+ function peg$f0(s) { return s; }
182
+ function peg$f1(v) { return new n.Comment(v.join('')); }
183
+ function peg$f2(v, e) { return new n.Assignment(v, e); }
184
+ function peg$f3(v) { return new n.Variable(v); }
185
+ function peg$f4(a, b) { return new n.Alternation(a, b); }
186
+ function peg$f5(a, b) { return new n.Concatenation(a, b); }
187
+ function peg$f6(t, e) { return new n.Concatenation(e, new n.Tag(t)); }
188
+ function peg$f7(t) { return new n.Repeat(t, '*'); }
189
+ function peg$f8(t) { return new n.Repeat(t, '?'); }
190
+ function peg$f9(t) { return new n.Repeat(t, '+'); }
191
+ function peg$f10(t, m) { return n.buildRepetition(t, m, m); }
192
+ function peg$f11(t, min) { return n.buildRepetition(t, min, Infinity); }
193
+ function peg$f12(t, max) { return n.buildRepetition(t, 0, max); }
194
+ function peg$f13(t, min, max) { return n.buildRepetition(t, min, max); }
195
+ function peg$f14(x) { return new n.Literal(x); }
196
+ function peg$f15(e) { return e; }
197
+ function peg$f16(a, b) { return a + b.join(''); }
198
+ function peg$f17(num) { return parseInt(num.join('')); }
199
+ let peg$currPos = options.peg$currPos | 0;
200
+ let peg$savedPos = peg$currPos;
201
+ const peg$posDetailsCache = [{ line: 1, column: 1 }];
202
+ let peg$maxFailPos = peg$currPos;
203
+ let peg$maxFailExpected = options.peg$maxFailExpected || [];
204
+ let peg$silentFails = options.peg$silentFails | 0;
205
+ let peg$resultsCache = {};
206
+ let peg$result;
207
+ if (options.startRule) {
208
+ if (!(options.startRule in peg$startRuleFunctions)) {
209
+ throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
210
+ }
211
+ peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
212
+ }
213
+ function text() {
214
+ return input.substring(peg$savedPos, peg$currPos);
215
+ }
216
+ function offset() {
217
+ return peg$savedPos;
218
+ }
219
+ function range() {
220
+ return {
221
+ source: peg$source,
222
+ start: peg$savedPos,
223
+ end: peg$currPos,
224
+ };
225
+ }
226
+ function location() {
227
+ return peg$computeLocation(peg$savedPos, peg$currPos);
228
+ }
229
+ function expected(description, location) {
230
+ location = location !== undefined
231
+ ? location
232
+ : peg$computeLocation(peg$savedPos, peg$currPos);
233
+ throw peg$buildStructuredError([peg$otherExpectation(description)], input.substring(peg$savedPos, peg$currPos), location);
234
+ }
235
+ function error(message, location) {
236
+ location = location !== undefined
237
+ ? location
238
+ : peg$computeLocation(peg$savedPos, peg$currPos);
239
+ throw peg$buildSimpleError(message, location);
240
+ }
241
+ function peg$getUnicode(pos = peg$currPos) {
242
+ const cp = input.codePointAt(pos);
243
+ if (cp === undefined) {
244
+ return "";
245
+ }
246
+ return String.fromCodePoint(cp);
247
+ }
248
+ function peg$literalExpectation(text, ignoreCase) {
249
+ return { type: "literal", text, ignoreCase };
250
+ }
251
+ function peg$classExpectation(parts, inverted, ignoreCase, unicode) {
252
+ return { type: "class", parts, inverted, ignoreCase, unicode };
253
+ }
254
+ function peg$anyExpectation() {
255
+ return { type: "any" };
256
+ }
257
+ function peg$endExpectation() {
258
+ return { type: "end" };
259
+ }
260
+ function peg$otherExpectation(description) {
261
+ return { type: "other", description };
262
+ }
263
+ function peg$computePosDetails(pos) {
264
+ let details = peg$posDetailsCache[pos];
265
+ let p;
266
+ if (details) {
267
+ return details;
268
+ }
269
+ else {
270
+ if (pos >= peg$posDetailsCache.length) {
271
+ p = peg$posDetailsCache.length - 1;
272
+ }
273
+ else {
274
+ p = pos;
275
+ while (!peg$posDetailsCache[--p]) { }
276
+ }
277
+ details = peg$posDetailsCache[p];
278
+ details = {
279
+ line: details.line,
280
+ column: details.column,
281
+ };
282
+ while (p < pos) {
283
+ if (input.charCodeAt(p) === 10) {
284
+ details.line++;
285
+ details.column = 1;
286
+ }
287
+ else {
288
+ details.column++;
289
+ }
290
+ p++;
291
+ }
292
+ peg$posDetailsCache[pos] = details;
293
+ return details;
294
+ }
295
+ }
296
+ function peg$computeLocation(startPos, endPos, offset) {
297
+ const startPosDetails = peg$computePosDetails(startPos);
298
+ const endPosDetails = peg$computePosDetails(endPos);
299
+ const res = {
300
+ source: peg$source,
301
+ start: {
302
+ offset: startPos,
303
+ line: startPosDetails.line,
304
+ column: startPosDetails.column,
305
+ },
306
+ end: {
307
+ offset: endPos,
308
+ line: endPosDetails.line,
309
+ column: endPosDetails.column,
310
+ },
311
+ };
312
+ if (offset && peg$source && (typeof peg$source.offset === "function")) {
313
+ res.start = peg$source.offset(res.start);
314
+ res.end = peg$source.offset(res.end);
315
+ }
316
+ return res;
317
+ }
318
+ function peg$fail(expected) {
319
+ if (peg$currPos < peg$maxFailPos) {
320
+ return;
321
+ }
322
+ if (peg$currPos > peg$maxFailPos) {
323
+ peg$maxFailPos = peg$currPos;
324
+ peg$maxFailExpected = [];
325
+ }
326
+ peg$maxFailExpected.push(expected);
327
+ }
328
+ function peg$buildSimpleError(message, location) {
329
+ return new peg$SyntaxError(message, null, null, location);
330
+ }
331
+ function peg$buildStructuredError(expected, found, location) {
332
+ return new peg$SyntaxError(peg$SyntaxError.buildMessage(expected, found), expected, found, location);
333
+ }
334
+ function peg$parserules() {
335
+ let s0, s1;
336
+ const key = peg$currPos * 15 + 0;
337
+ const cached = peg$resultsCache[key];
338
+ if (cached) {
339
+ peg$currPos = cached.nextPos;
340
+ return cached.result;
341
+ }
342
+ s0 = [];
343
+ s1 = peg$parsestatement();
344
+ if (s1 !== peg$FAILED) {
345
+ while (s1 !== peg$FAILED) {
346
+ s0.push(s1);
347
+ s1 = peg$parsestatement();
348
+ }
349
+ }
350
+ else {
351
+ s0 = peg$FAILED;
352
+ }
353
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
354
+ return s0;
355
+ }
356
+ function peg$parsestatement() {
357
+ let s0, s1, s2;
358
+ const key = peg$currPos * 15 + 1;
359
+ const cached = peg$resultsCache[key];
360
+ if (cached) {
361
+ peg$currPos = cached.nextPos;
362
+ return cached.result;
363
+ }
364
+ s0 = peg$currPos;
365
+ s1 = peg$parsestatement_type();
366
+ if (s1 !== peg$FAILED) {
367
+ s2 = peg$parse_();
368
+ peg$savedPos = s0;
369
+ s0 = peg$f0(s1);
370
+ }
371
+ else {
372
+ peg$currPos = s0;
373
+ s0 = peg$FAILED;
374
+ }
375
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
376
+ return s0;
377
+ }
378
+ function peg$parsestatement_type() {
379
+ let s0;
380
+ const key = peg$currPos * 15 + 2;
381
+ const cached = peg$resultsCache[key];
382
+ if (cached) {
383
+ peg$currPos = cached.nextPos;
384
+ return cached.result;
385
+ }
386
+ s0 = peg$parseassignment();
387
+ if (s0 === peg$FAILED) {
388
+ s0 = peg$parsecomment();
389
+ }
390
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
391
+ return s0;
392
+ }
393
+ function peg$parsecomment() {
394
+ let s0, s1, s2, s3;
395
+ const key = peg$currPos * 15 + 3;
396
+ const cached = peg$resultsCache[key];
397
+ if (cached) {
398
+ peg$currPos = cached.nextPos;
399
+ return cached.result;
400
+ }
401
+ s0 = peg$currPos;
402
+ if (input.charCodeAt(peg$currPos) === 35) {
403
+ s1 = peg$c0;
404
+ peg$currPos++;
405
+ }
406
+ else {
407
+ s1 = peg$FAILED;
408
+ if (peg$silentFails === 0) {
409
+ peg$fail(peg$e0);
410
+ }
411
+ }
412
+ if (s1 !== peg$FAILED) {
413
+ s2 = [];
414
+ s3 = input.charAt(peg$currPos);
415
+ if (peg$r0.test(s3)) {
416
+ peg$currPos++;
417
+ }
418
+ else {
419
+ s3 = peg$FAILED;
420
+ if (peg$silentFails === 0) {
421
+ peg$fail(peg$e1);
422
+ }
423
+ }
424
+ while (s3 !== peg$FAILED) {
425
+ s2.push(s3);
426
+ s3 = input.charAt(peg$currPos);
427
+ if (peg$r0.test(s3)) {
428
+ peg$currPos++;
429
+ }
430
+ else {
431
+ s3 = peg$FAILED;
432
+ if (peg$silentFails === 0) {
433
+ peg$fail(peg$e1);
434
+ }
435
+ }
436
+ }
437
+ s3 = input.charAt(peg$currPos);
438
+ if (peg$r1.test(s3)) {
439
+ peg$currPos++;
440
+ }
441
+ else {
442
+ s3 = peg$FAILED;
443
+ if (peg$silentFails === 0) {
444
+ peg$fail(peg$e2);
445
+ }
446
+ }
447
+ if (s3 !== peg$FAILED) {
448
+ peg$savedPos = s0;
449
+ s0 = peg$f1(s2);
450
+ }
451
+ else {
452
+ peg$currPos = s0;
453
+ s0 = peg$FAILED;
454
+ }
455
+ }
456
+ else {
457
+ peg$currPos = s0;
458
+ s0 = peg$FAILED;
459
+ }
460
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
461
+ return s0;
462
+ }
463
+ function peg$parseassignment() {
464
+ let s0, s1, s2, s3, s4, s5, s6, s7;
465
+ const key = peg$currPos * 15 + 4;
466
+ const cached = peg$resultsCache[key];
467
+ if (cached) {
468
+ peg$currPos = cached.nextPos;
469
+ return cached.result;
470
+ }
471
+ s0 = peg$currPos;
472
+ s1 = peg$parsevariable();
473
+ if (s1 !== peg$FAILED) {
474
+ s2 = peg$parse_();
475
+ if (input.charCodeAt(peg$currPos) === 61) {
476
+ s3 = peg$c1;
477
+ peg$currPos++;
478
+ }
479
+ else {
480
+ s3 = peg$FAILED;
481
+ if (peg$silentFails === 0) {
482
+ peg$fail(peg$e3);
483
+ }
484
+ }
485
+ if (s3 !== peg$FAILED) {
486
+ s4 = peg$parse_();
487
+ s5 = peg$parsealternation();
488
+ if (s5 !== peg$FAILED) {
489
+ s6 = peg$parse_();
490
+ if (input.charCodeAt(peg$currPos) === 59) {
491
+ s7 = peg$c2;
492
+ peg$currPos++;
493
+ }
494
+ else {
495
+ s7 = peg$FAILED;
496
+ if (peg$silentFails === 0) {
497
+ peg$fail(peg$e4);
498
+ }
499
+ }
500
+ if (s7 !== peg$FAILED) {
501
+ peg$savedPos = s0;
502
+ s0 = peg$f2(s1, s5);
503
+ }
504
+ else {
505
+ peg$currPos = s0;
506
+ s0 = peg$FAILED;
507
+ }
508
+ }
509
+ else {
510
+ peg$currPos = s0;
511
+ s0 = peg$FAILED;
512
+ }
513
+ }
514
+ else {
515
+ peg$currPos = s0;
516
+ s0 = peg$FAILED;
517
+ }
518
+ }
519
+ else {
520
+ peg$currPos = s0;
521
+ s0 = peg$FAILED;
522
+ }
523
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
524
+ return s0;
525
+ }
526
+ function peg$parsevariable() {
527
+ let s0, s1;
528
+ const key = peg$currPos * 15 + 5;
529
+ const cached = peg$resultsCache[key];
530
+ if (cached) {
531
+ peg$currPos = cached.nextPos;
532
+ return cached.result;
533
+ }
534
+ s0 = peg$currPos;
535
+ s1 = peg$parsename();
536
+ if (s1 !== peg$FAILED) {
537
+ peg$savedPos = s0;
538
+ s1 = peg$f3(s1);
539
+ }
540
+ s0 = s1;
541
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
542
+ return s0;
543
+ }
544
+ function peg$parsealternation() {
545
+ let s0, s1, s2, s3, s4, s5;
546
+ const key = peg$currPos * 15 + 6;
547
+ const cached = peg$resultsCache[key];
548
+ if (cached) {
549
+ peg$currPos = cached.nextPos;
550
+ return cached.result;
551
+ }
552
+ s0 = peg$currPos;
553
+ s1 = peg$parseconcatenation();
554
+ if (s1 !== peg$FAILED) {
555
+ s2 = peg$parse_();
556
+ if (input.charCodeAt(peg$currPos) === 124) {
557
+ s3 = peg$c3;
558
+ peg$currPos++;
559
+ }
560
+ else {
561
+ s3 = peg$FAILED;
562
+ if (peg$silentFails === 0) {
563
+ peg$fail(peg$e5);
564
+ }
565
+ }
566
+ if (s3 !== peg$FAILED) {
567
+ s4 = peg$parse_();
568
+ s5 = peg$parsealternation();
569
+ if (s5 !== peg$FAILED) {
570
+ peg$savedPos = s0;
571
+ s0 = peg$f4(s1, s5);
572
+ }
573
+ else {
574
+ peg$currPos = s0;
575
+ s0 = peg$FAILED;
576
+ }
577
+ }
578
+ else {
579
+ peg$currPos = s0;
580
+ s0 = peg$FAILED;
581
+ }
582
+ }
583
+ else {
584
+ peg$currPos = s0;
585
+ s0 = peg$FAILED;
586
+ }
587
+ if (s0 === peg$FAILED) {
588
+ s0 = peg$parseconcatenation();
589
+ }
590
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
591
+ return s0;
592
+ }
593
+ function peg$parseconcatenation() {
594
+ let s0, s1, s2, s3;
595
+ const key = peg$currPos * 15 + 7;
596
+ const cached = peg$resultsCache[key];
597
+ if (cached) {
598
+ peg$currPos = cached.nextPos;
599
+ return cached.result;
600
+ }
601
+ s0 = peg$currPos;
602
+ s1 = peg$parserepeat();
603
+ if (s1 !== peg$FAILED) {
604
+ s2 = peg$parse_();
605
+ s3 = peg$parseconcatenation();
606
+ if (s3 !== peg$FAILED) {
607
+ peg$savedPos = s0;
608
+ s0 = peg$f5(s1, s3);
609
+ }
610
+ else {
611
+ peg$currPos = s0;
612
+ s0 = peg$FAILED;
613
+ }
614
+ }
615
+ else {
616
+ peg$currPos = s0;
617
+ s0 = peg$FAILED;
618
+ }
619
+ if (s0 === peg$FAILED) {
620
+ s0 = peg$parserepeat();
621
+ }
622
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
623
+ return s0;
624
+ }
625
+ function peg$parserepeat() {
626
+ let s0, s1, s2, s3, s4, s5, s6;
627
+ const key = peg$currPos * 15 + 8;
628
+ const cached = peg$resultsCache[key];
629
+ if (cached) {
630
+ peg$currPos = cached.nextPos;
631
+ return cached.result;
632
+ }
633
+ s0 = peg$currPos;
634
+ s1 = peg$parsename();
635
+ if (s1 !== peg$FAILED) {
636
+ if (input.charCodeAt(peg$currPos) === 58) {
637
+ s2 = peg$c4;
638
+ peg$currPos++;
639
+ }
640
+ else {
641
+ s2 = peg$FAILED;
642
+ if (peg$silentFails === 0) {
643
+ peg$fail(peg$e6);
644
+ }
645
+ }
646
+ if (s2 !== peg$FAILED) {
647
+ s3 = peg$parserepeat();
648
+ if (s3 !== peg$FAILED) {
649
+ peg$savedPos = s0;
650
+ s0 = peg$f6(s1, s3);
651
+ }
652
+ else {
653
+ peg$currPos = s0;
654
+ s0 = peg$FAILED;
655
+ }
656
+ }
657
+ else {
658
+ peg$currPos = s0;
659
+ s0 = peg$FAILED;
660
+ }
661
+ }
662
+ else {
663
+ peg$currPos = s0;
664
+ s0 = peg$FAILED;
665
+ }
666
+ if (s0 === peg$FAILED) {
667
+ s0 = peg$currPos;
668
+ s1 = peg$parseterm();
669
+ if (s1 !== peg$FAILED) {
670
+ if (input.charCodeAt(peg$currPos) === 42) {
671
+ s2 = peg$c5;
672
+ peg$currPos++;
673
+ }
674
+ else {
675
+ s2 = peg$FAILED;
676
+ if (peg$silentFails === 0) {
677
+ peg$fail(peg$e7);
678
+ }
679
+ }
680
+ if (s2 !== peg$FAILED) {
681
+ peg$savedPos = s0;
682
+ s0 = peg$f7(s1);
683
+ }
684
+ else {
685
+ peg$currPos = s0;
686
+ s0 = peg$FAILED;
687
+ }
688
+ }
689
+ else {
690
+ peg$currPos = s0;
691
+ s0 = peg$FAILED;
692
+ }
693
+ if (s0 === peg$FAILED) {
694
+ s0 = peg$currPos;
695
+ s1 = peg$parseterm();
696
+ if (s1 !== peg$FAILED) {
697
+ if (input.charCodeAt(peg$currPos) === 63) {
698
+ s2 = peg$c6;
699
+ peg$currPos++;
700
+ }
701
+ else {
702
+ s2 = peg$FAILED;
703
+ if (peg$silentFails === 0) {
704
+ peg$fail(peg$e8);
705
+ }
706
+ }
707
+ if (s2 !== peg$FAILED) {
708
+ peg$savedPos = s0;
709
+ s0 = peg$f8(s1);
710
+ }
711
+ else {
712
+ peg$currPos = s0;
713
+ s0 = peg$FAILED;
714
+ }
715
+ }
716
+ else {
717
+ peg$currPos = s0;
718
+ s0 = peg$FAILED;
719
+ }
720
+ if (s0 === peg$FAILED) {
721
+ s0 = peg$currPos;
722
+ s1 = peg$parseterm();
723
+ if (s1 !== peg$FAILED) {
724
+ if (input.charCodeAt(peg$currPos) === 43) {
725
+ s2 = peg$c7;
726
+ peg$currPos++;
727
+ }
728
+ else {
729
+ s2 = peg$FAILED;
730
+ if (peg$silentFails === 0) {
731
+ peg$fail(peg$e9);
732
+ }
733
+ }
734
+ if (s2 !== peg$FAILED) {
735
+ peg$savedPos = s0;
736
+ s0 = peg$f9(s1);
737
+ }
738
+ else {
739
+ peg$currPos = s0;
740
+ s0 = peg$FAILED;
741
+ }
742
+ }
743
+ else {
744
+ peg$currPos = s0;
745
+ s0 = peg$FAILED;
746
+ }
747
+ if (s0 === peg$FAILED) {
748
+ s0 = peg$currPos;
749
+ s1 = peg$parseterm();
750
+ if (s1 !== peg$FAILED) {
751
+ if (input.charCodeAt(peg$currPos) === 123) {
752
+ s2 = peg$c8;
753
+ peg$currPos++;
754
+ }
755
+ else {
756
+ s2 = peg$FAILED;
757
+ if (peg$silentFails === 0) {
758
+ peg$fail(peg$e10);
759
+ }
760
+ }
761
+ if (s2 !== peg$FAILED) {
762
+ s3 = peg$parsenumber();
763
+ if (s3 !== peg$FAILED) {
764
+ if (input.charCodeAt(peg$currPos) === 125) {
765
+ s4 = peg$c9;
766
+ peg$currPos++;
767
+ }
768
+ else {
769
+ s4 = peg$FAILED;
770
+ if (peg$silentFails === 0) {
771
+ peg$fail(peg$e11);
772
+ }
773
+ }
774
+ if (s4 !== peg$FAILED) {
775
+ peg$savedPos = s0;
776
+ s0 = peg$f10(s1, s3);
777
+ }
778
+ else {
779
+ peg$currPos = s0;
780
+ s0 = peg$FAILED;
781
+ }
782
+ }
783
+ else {
784
+ peg$currPos = s0;
785
+ s0 = peg$FAILED;
786
+ }
787
+ }
788
+ else {
789
+ peg$currPos = s0;
790
+ s0 = peg$FAILED;
791
+ }
792
+ }
793
+ else {
794
+ peg$currPos = s0;
795
+ s0 = peg$FAILED;
796
+ }
797
+ if (s0 === peg$FAILED) {
798
+ s0 = peg$currPos;
799
+ s1 = peg$parseterm();
800
+ if (s1 !== peg$FAILED) {
801
+ if (input.charCodeAt(peg$currPos) === 123) {
802
+ s2 = peg$c8;
803
+ peg$currPos++;
804
+ }
805
+ else {
806
+ s2 = peg$FAILED;
807
+ if (peg$silentFails === 0) {
808
+ peg$fail(peg$e10);
809
+ }
810
+ }
811
+ if (s2 !== peg$FAILED) {
812
+ s3 = peg$parsenumber();
813
+ if (s3 !== peg$FAILED) {
814
+ if (input.charCodeAt(peg$currPos) === 44) {
815
+ s4 = peg$c10;
816
+ peg$currPos++;
817
+ }
818
+ else {
819
+ s4 = peg$FAILED;
820
+ if (peg$silentFails === 0) {
821
+ peg$fail(peg$e12);
822
+ }
823
+ }
824
+ if (s4 !== peg$FAILED) {
825
+ if (input.charCodeAt(peg$currPos) === 125) {
826
+ s5 = peg$c9;
827
+ peg$currPos++;
828
+ }
829
+ else {
830
+ s5 = peg$FAILED;
831
+ if (peg$silentFails === 0) {
832
+ peg$fail(peg$e11);
833
+ }
834
+ }
835
+ if (s5 !== peg$FAILED) {
836
+ peg$savedPos = s0;
837
+ s0 = peg$f11(s1, s3);
838
+ }
839
+ else {
840
+ peg$currPos = s0;
841
+ s0 = peg$FAILED;
842
+ }
843
+ }
844
+ else {
845
+ peg$currPos = s0;
846
+ s0 = peg$FAILED;
847
+ }
848
+ }
849
+ else {
850
+ peg$currPos = s0;
851
+ s0 = peg$FAILED;
852
+ }
853
+ }
854
+ else {
855
+ peg$currPos = s0;
856
+ s0 = peg$FAILED;
857
+ }
858
+ }
859
+ else {
860
+ peg$currPos = s0;
861
+ s0 = peg$FAILED;
862
+ }
863
+ if (s0 === peg$FAILED) {
864
+ s0 = peg$currPos;
865
+ s1 = peg$parseterm();
866
+ if (s1 !== peg$FAILED) {
867
+ if (input.charCodeAt(peg$currPos) === 123) {
868
+ s2 = peg$c8;
869
+ peg$currPos++;
870
+ }
871
+ else {
872
+ s2 = peg$FAILED;
873
+ if (peg$silentFails === 0) {
874
+ peg$fail(peg$e10);
875
+ }
876
+ }
877
+ if (s2 !== peg$FAILED) {
878
+ if (input.charCodeAt(peg$currPos) === 44) {
879
+ s3 = peg$c10;
880
+ peg$currPos++;
881
+ }
882
+ else {
883
+ s3 = peg$FAILED;
884
+ if (peg$silentFails === 0) {
885
+ peg$fail(peg$e12);
886
+ }
887
+ }
888
+ if (s3 !== peg$FAILED) {
889
+ s4 = peg$parsenumber();
890
+ if (s4 !== peg$FAILED) {
891
+ if (input.charCodeAt(peg$currPos) === 125) {
892
+ s5 = peg$c9;
893
+ peg$currPos++;
894
+ }
895
+ else {
896
+ s5 = peg$FAILED;
897
+ if (peg$silentFails === 0) {
898
+ peg$fail(peg$e11);
899
+ }
900
+ }
901
+ if (s5 !== peg$FAILED) {
902
+ peg$savedPos = s0;
903
+ s0 = peg$f12(s1, s4);
904
+ }
905
+ else {
906
+ peg$currPos = s0;
907
+ s0 = peg$FAILED;
908
+ }
909
+ }
910
+ else {
911
+ peg$currPos = s0;
912
+ s0 = peg$FAILED;
913
+ }
914
+ }
915
+ else {
916
+ peg$currPos = s0;
917
+ s0 = peg$FAILED;
918
+ }
919
+ }
920
+ else {
921
+ peg$currPos = s0;
922
+ s0 = peg$FAILED;
923
+ }
924
+ }
925
+ else {
926
+ peg$currPos = s0;
927
+ s0 = peg$FAILED;
928
+ }
929
+ if (s0 === peg$FAILED) {
930
+ s0 = peg$currPos;
931
+ s1 = peg$parseterm();
932
+ if (s1 !== peg$FAILED) {
933
+ if (input.charCodeAt(peg$currPos) === 123) {
934
+ s2 = peg$c8;
935
+ peg$currPos++;
936
+ }
937
+ else {
938
+ s2 = peg$FAILED;
939
+ if (peg$silentFails === 0) {
940
+ peg$fail(peg$e10);
941
+ }
942
+ }
943
+ if (s2 !== peg$FAILED) {
944
+ s3 = peg$parsenumber();
945
+ if (s3 !== peg$FAILED) {
946
+ if (input.charCodeAt(peg$currPos) === 44) {
947
+ s4 = peg$c10;
948
+ peg$currPos++;
949
+ }
950
+ else {
951
+ s4 = peg$FAILED;
952
+ if (peg$silentFails === 0) {
953
+ peg$fail(peg$e12);
954
+ }
955
+ }
956
+ if (s4 !== peg$FAILED) {
957
+ s5 = peg$parsenumber();
958
+ if (s5 !== peg$FAILED) {
959
+ if (input.charCodeAt(peg$currPos) === 125) {
960
+ s6 = peg$c9;
961
+ peg$currPos++;
962
+ }
963
+ else {
964
+ s6 = peg$FAILED;
965
+ if (peg$silentFails === 0) {
966
+ peg$fail(peg$e11);
967
+ }
968
+ }
969
+ if (s6 !== peg$FAILED) {
970
+ peg$savedPos = s0;
971
+ s0 = peg$f13(s1, s3, s5);
972
+ }
973
+ else {
974
+ peg$currPos = s0;
975
+ s0 = peg$FAILED;
976
+ }
977
+ }
978
+ else {
979
+ peg$currPos = s0;
980
+ s0 = peg$FAILED;
981
+ }
982
+ }
983
+ else {
984
+ peg$currPos = s0;
985
+ s0 = peg$FAILED;
986
+ }
987
+ }
988
+ else {
989
+ peg$currPos = s0;
990
+ s0 = peg$FAILED;
991
+ }
992
+ }
993
+ else {
994
+ peg$currPos = s0;
995
+ s0 = peg$FAILED;
996
+ }
997
+ }
998
+ else {
999
+ peg$currPos = s0;
1000
+ s0 = peg$FAILED;
1001
+ }
1002
+ if (s0 === peg$FAILED) {
1003
+ s0 = peg$parseterm();
1004
+ }
1005
+ }
1006
+ }
1007
+ }
1008
+ }
1009
+ }
1010
+ }
1011
+ }
1012
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1013
+ return s0;
1014
+ }
1015
+ function peg$parseterm() {
1016
+ let s0, s1, s2, s3;
1017
+ const key = peg$currPos * 15 + 9;
1018
+ const cached = peg$resultsCache[key];
1019
+ if (cached) {
1020
+ peg$currPos = cached.nextPos;
1021
+ return cached.result;
1022
+ }
1023
+ s0 = peg$parsevariable();
1024
+ if (s0 === peg$FAILED) {
1025
+ s0 = peg$currPos;
1026
+ s1 = peg$parsenumber();
1027
+ if (s1 !== peg$FAILED) {
1028
+ peg$savedPos = s0;
1029
+ s1 = peg$f14(s1);
1030
+ }
1031
+ s0 = s1;
1032
+ if (s0 === peg$FAILED) {
1033
+ s0 = peg$currPos;
1034
+ if (input.charCodeAt(peg$currPos) === 40) {
1035
+ s1 = peg$c11;
1036
+ peg$currPos++;
1037
+ }
1038
+ else {
1039
+ s1 = peg$FAILED;
1040
+ if (peg$silentFails === 0) {
1041
+ peg$fail(peg$e13);
1042
+ }
1043
+ }
1044
+ if (s1 !== peg$FAILED) {
1045
+ s2 = peg$parsealternation();
1046
+ if (s2 !== peg$FAILED) {
1047
+ if (input.charCodeAt(peg$currPos) === 41) {
1048
+ s3 = peg$c12;
1049
+ peg$currPos++;
1050
+ }
1051
+ else {
1052
+ s3 = peg$FAILED;
1053
+ if (peg$silentFails === 0) {
1054
+ peg$fail(peg$e14);
1055
+ }
1056
+ }
1057
+ if (s3 !== peg$FAILED) {
1058
+ peg$savedPos = s0;
1059
+ s0 = peg$f15(s2);
1060
+ }
1061
+ else {
1062
+ peg$currPos = s0;
1063
+ s0 = peg$FAILED;
1064
+ }
1065
+ }
1066
+ else {
1067
+ peg$currPos = s0;
1068
+ s0 = peg$FAILED;
1069
+ }
1070
+ }
1071
+ else {
1072
+ peg$currPos = s0;
1073
+ s0 = peg$FAILED;
1074
+ }
1075
+ }
1076
+ }
1077
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1078
+ return s0;
1079
+ }
1080
+ function peg$parsename() {
1081
+ let s0, s1, s2, s3;
1082
+ const key = peg$currPos * 15 + 10;
1083
+ const cached = peg$resultsCache[key];
1084
+ if (cached) {
1085
+ peg$currPos = cached.nextPos;
1086
+ return cached.result;
1087
+ }
1088
+ s0 = peg$currPos;
1089
+ s1 = peg$parsename_start_char();
1090
+ if (s1 !== peg$FAILED) {
1091
+ s2 = [];
1092
+ s3 = peg$parsename_char();
1093
+ while (s3 !== peg$FAILED) {
1094
+ s2.push(s3);
1095
+ s3 = peg$parsename_char();
1096
+ }
1097
+ peg$savedPos = s0;
1098
+ s0 = peg$f16(s1, s2);
1099
+ }
1100
+ else {
1101
+ peg$currPos = s0;
1102
+ s0 = peg$FAILED;
1103
+ }
1104
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1105
+ return s0;
1106
+ }
1107
+ function peg$parsename_start_char() {
1108
+ let s0;
1109
+ const key = peg$currPos * 15 + 11;
1110
+ const cached = peg$resultsCache[key];
1111
+ if (cached) {
1112
+ peg$currPos = cached.nextPos;
1113
+ return cached.result;
1114
+ }
1115
+ s0 = input.charAt(peg$currPos);
1116
+ if (peg$r2.test(s0)) {
1117
+ peg$currPos++;
1118
+ }
1119
+ else {
1120
+ s0 = peg$FAILED;
1121
+ if (peg$silentFails === 0) {
1122
+ peg$fail(peg$e15);
1123
+ }
1124
+ }
1125
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1126
+ return s0;
1127
+ }
1128
+ function peg$parsename_char() {
1129
+ let s0;
1130
+ const key = peg$currPos * 15 + 12;
1131
+ const cached = peg$resultsCache[key];
1132
+ if (cached) {
1133
+ peg$currPos = cached.nextPos;
1134
+ return cached.result;
1135
+ }
1136
+ s0 = input.charAt(peg$currPos);
1137
+ if (peg$r3.test(s0)) {
1138
+ peg$currPos++;
1139
+ }
1140
+ else {
1141
+ s0 = peg$FAILED;
1142
+ if (peg$silentFails === 0) {
1143
+ peg$fail(peg$e16);
1144
+ }
1145
+ }
1146
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1147
+ return s0;
1148
+ }
1149
+ function peg$parsenumber() {
1150
+ let s0, s1, s2;
1151
+ const key = peg$currPos * 15 + 13;
1152
+ const cached = peg$resultsCache[key];
1153
+ if (cached) {
1154
+ peg$currPos = cached.nextPos;
1155
+ return cached.result;
1156
+ }
1157
+ s0 = peg$currPos;
1158
+ s1 = [];
1159
+ s2 = input.charAt(peg$currPos);
1160
+ if (peg$r4.test(s2)) {
1161
+ peg$currPos++;
1162
+ }
1163
+ else {
1164
+ s2 = peg$FAILED;
1165
+ if (peg$silentFails === 0) {
1166
+ peg$fail(peg$e17);
1167
+ }
1168
+ }
1169
+ if (s2 !== peg$FAILED) {
1170
+ while (s2 !== peg$FAILED) {
1171
+ s1.push(s2);
1172
+ s2 = input.charAt(peg$currPos);
1173
+ if (peg$r4.test(s2)) {
1174
+ peg$currPos++;
1175
+ }
1176
+ else {
1177
+ s2 = peg$FAILED;
1178
+ if (peg$silentFails === 0) {
1179
+ peg$fail(peg$e17);
1180
+ }
1181
+ }
1182
+ }
1183
+ }
1184
+ else {
1185
+ s1 = peg$FAILED;
1186
+ }
1187
+ if (s1 !== peg$FAILED) {
1188
+ peg$savedPos = s0;
1189
+ s1 = peg$f17(s1);
1190
+ }
1191
+ s0 = s1;
1192
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1193
+ return s0;
1194
+ }
1195
+ function peg$parse_() {
1196
+ let s0, s1;
1197
+ const key = peg$currPos * 15 + 14;
1198
+ const cached = peg$resultsCache[key];
1199
+ if (cached) {
1200
+ peg$currPos = cached.nextPos;
1201
+ return cached.result;
1202
+ }
1203
+ s0 = [];
1204
+ s1 = input.charAt(peg$currPos);
1205
+ if (peg$r5.test(s1)) {
1206
+ peg$currPos++;
1207
+ }
1208
+ else {
1209
+ s1 = peg$FAILED;
1210
+ if (peg$silentFails === 0) {
1211
+ peg$fail(peg$e18);
1212
+ }
1213
+ }
1214
+ while (s1 !== peg$FAILED) {
1215
+ s0.push(s1);
1216
+ s1 = input.charAt(peg$currPos);
1217
+ if (peg$r5.test(s1)) {
1218
+ peg$currPos++;
1219
+ }
1220
+ else {
1221
+ s1 = peg$FAILED;
1222
+ if (peg$silentFails === 0) {
1223
+ peg$fail(peg$e18);
1224
+ }
1225
+ }
1226
+ }
1227
+ peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
1228
+ return s0;
1229
+ }
1230
+ const n = options?.nodes;
1231
+ if (!n) {
1232
+ throw new Error('The parser expects a nodes module via options.nodes.');
1233
+ }
1234
+ peg$result = peg$startRuleFunction();
1235
+ const peg$success = (peg$result !== peg$FAILED && peg$currPos === input.length);
1236
+ function peg$throw() {
1237
+ if (peg$result !== peg$FAILED && peg$currPos < input.length) {
1238
+ peg$fail(peg$endExpectation());
1239
+ }
1240
+ throw peg$buildStructuredError(peg$maxFailExpected, peg$maxFailPos < input.length ? peg$getUnicode(peg$maxFailPos) : null, peg$maxFailPos < input.length
1241
+ ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1)
1242
+ : peg$computeLocation(peg$maxFailPos, peg$maxFailPos));
1243
+ }
1244
+ if (options.peg$library) {
1245
+ return /** @type {any} */ ({
1246
+ peg$result,
1247
+ peg$currPos,
1248
+ peg$FAILED,
1249
+ peg$maxFailExpected,
1250
+ peg$maxFailPos,
1251
+ peg$success,
1252
+ peg$throw: peg$success ? undefined : peg$throw,
1253
+ });
1254
+ }
1255
+ if (peg$success) {
1256
+ return peg$result;
1257
+ }
1258
+ else {
1259
+ peg$throw();
1260
+ }
1261
+ }
1262
+ const peg$allowedStartRules = [
1263
+ "rules"
1264
+ ];
1265
+ export { peg$allowedStartRules as StartRules, peg$SyntaxError as SyntaxError, peg$parse as parse };
1266
+ //# sourceMappingURL=grammar.js.map