parseman 0.46.0 → 0.47.1
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.
- package/README.md +8 -3
- package/dist/analysis/choice-cost-render.d.ts +12 -4
- package/dist/analysis/choice-cost-render.d.ts.map +1 -1
- package/dist/analysis/choice-cost.d.ts +2 -2
- package/dist/analysis/choice-cost.d.ts.map +1 -1
- package/dist/analysis/commitment.d.ts +131 -0
- package/dist/analysis/commitment.d.ts.map +1 -0
- package/dist/analysis/diagnostics.cjs +10339 -7787
- package/dist/analysis/diagnostics.cjs.map +3 -4
- package/dist/analysis/diagnostics.d.ts +2 -2
- package/dist/analysis/diagnostics.js +10339 -7787
- package/dist/analysis/diagnostics.js.map +3 -4
- package/dist/analysis/duplication.d.ts.map +1 -1
- package/dist/analysis/fix.d.ts +3 -3
- package/dist/analysis/fix.d.ts.map +1 -1
- package/dist/analysis/format-number.d.ts +23 -0
- package/dist/analysis/format-number.d.ts.map +1 -0
- package/dist/analysis/gating.d.ts +39 -2
- package/dist/analysis/gating.d.ts.map +1 -1
- package/dist/analysis/rebuild.d.ts.map +1 -1
- package/dist/analysis/terminal.d.ts +5 -2
- package/dist/analysis/terminal.d.ts.map +1 -1
- package/dist/cli/index.cjs +10924 -8506
- package/dist/cli/index.cjs.map +3 -4
- package/dist/cli/index.js +10924 -8506
- package/dist/cli/index.js.map +3 -4
- package/dist/combinators/adjacency.d.ts +100 -0
- package/dist/combinators/adjacency.d.ts.map +1 -0
- package/dist/combinators/choice.d.ts.map +1 -1
- package/dist/combinators/completions.d.ts.map +1 -1
- package/dist/combinators/dispatch.d.ts +8 -1
- package/dist/combinators/dispatch.d.ts.map +1 -1
- package/dist/combinators/expect.d.ts.map +1 -1
- package/dist/combinators/first-set.d.ts.map +1 -1
- package/dist/combinators/gate.d.ts.map +1 -1
- package/dist/combinators/grammar.d.ts +22 -0
- package/dist/combinators/grammar.d.ts.map +1 -1
- package/dist/combinators/literal.d.ts +8 -0
- package/dist/combinators/literal.d.ts.map +1 -1
- package/dist/combinators/map.d.ts +0 -1
- package/dist/combinators/map.d.ts.map +1 -1
- package/dist/combinators/node.d.ts +13 -3
- package/dist/combinators/node.d.ts.map +1 -1
- package/dist/combinators/parser.d.ts +1 -1
- package/dist/combinators/parser.d.ts.map +1 -1
- package/dist/combinators/ref.d.ts.map +1 -1
- package/dist/combinators/regex.d.ts +1 -16
- package/dist/combinators/regex.d.ts.map +1 -1
- package/dist/combinators/repeat.d.ts +30 -2
- package/dist/combinators/repeat.d.ts.map +1 -1
- package/dist/combinators/scanTo.d.ts +71 -1
- package/dist/combinators/scanTo.d.ts.map +1 -1
- package/dist/combinators/sequence.d.ts.map +1 -1
- package/dist/combinators/token.d.ts.map +1 -1
- package/dist/combinators/trivia-boundary.d.ts +26 -0
- package/dist/combinators/trivia-boundary.d.ts.map +1 -0
- package/dist/combinators/trivia-skip.d.ts +45 -1
- package/dist/combinators/trivia-skip.d.ts.map +1 -1
- package/dist/combinators/withCtx.d.ts.map +1 -1
- package/dist/compiler/compile-linkable-table.d.ts +104 -0
- package/dist/compiler/compile-linkable-table.d.ts.map +1 -0
- package/dist/compiler/degradation.d.ts +0 -2
- package/dist/compiler/degradation.d.ts.map +1 -1
- package/dist/compiler/fields.d.ts +13 -0
- package/dist/compiler/fields.d.ts.map +1 -1
- package/dist/compiler/grammar-coverage-ids.d.ts +5 -5
- package/dist/compiler/grammar-coverage-ids.d.ts.map +1 -1
- package/dist/compiler/ir-serialize.d.ts.map +1 -1
- package/dist/compiler/linker.d.ts +47 -53
- package/dist/compiler/linker.d.ts.map +1 -1
- package/dist/compiler/token-alphabet.d.ts +81 -0
- package/dist/compiler/token-alphabet.d.ts.map +1 -0
- package/dist/compiler/token-dispatch.d.ts +95 -0
- package/dist/compiler/token-dispatch.d.ts.map +1 -0
- package/dist/compiler/token-scanner.d.ts +53 -0
- package/dist/compiler/token-scanner.d.ts.map +1 -0
- package/dist/compiler/value-usage.d.ts.map +1 -1
- package/dist/coverage.d.ts +1 -1
- package/dist/coverage.d.ts.map +1 -1
- package/dist/cst/capture-buffer.d.ts +35 -0
- package/dist/cst/capture-buffer.d.ts.map +1 -1
- package/dist/cst/reflection-attach.d.ts +8 -0
- package/dist/cst/reflection-attach.d.ts.map +1 -0
- package/dist/cst/reflection-symbols.d.ts +10 -0
- package/dist/cst/reflection-symbols.d.ts.map +1 -0
- package/dist/cst/reflection.d.ts +2 -4
- package/dist/cst/reflection.d.ts.map +1 -1
- package/dist/cst/root-trivia-scope.d.ts +26 -0
- package/dist/cst/root-trivia-scope.d.ts.map +1 -0
- package/dist/cst/trivia-charscan.d.ts +18 -0
- package/dist/cst/trivia-charscan.d.ts.map +1 -0
- package/dist/cst/trivia-kinds.d.ts +19 -0
- package/dist/cst/trivia-kinds.d.ts.map +1 -1
- package/dist/functional/doc.d.ts.map +1 -1
- package/dist/functional/run-tabled.d.ts +12 -0
- package/dist/functional/run-tabled.d.ts.map +1 -0
- package/dist/functional/run.d.ts +25 -42
- package/dist/functional/run.d.ts.map +1 -1
- package/dist/grammar-metadata.d.ts +3 -0
- package/dist/grammar-metadata.d.ts.map +1 -0
- package/dist/index.cjs +9290 -7181
- package/dist/index.cjs.map +3 -4
- package/dist/index.d.ts +18 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9300 -7191
- package/dist/index.js.map +3 -4
- package/dist/language-service/index.cjs +313 -121
- package/dist/language-service/index.cjs.map +3 -4
- package/dist/language-service/index.js +313 -121
- package/dist/language-service/index.js.map +3 -4
- package/dist/oracle/index.cjs.map +0 -1
- package/dist/oracle/index.js.map +0 -1
- package/dist/parse-context.d.ts +49 -0
- package/dist/parse-context.d.ts.map +1 -0
- package/dist/plugin/evaluator.d.ts +40 -1
- package/dist/plugin/evaluator.d.ts.map +1 -1
- package/dist/plugin/index.cjs +11175 -9534
- package/dist/plugin/index.cjs.map +3 -4
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +11175 -9534
- package/dist/plugin/index.js.map +3 -4
- package/dist/regex/classes.d.ts +28 -0
- package/dist/regex/classes.d.ts.map +1 -1
- package/dist/regex/first-set.d.ts +14 -0
- package/dist/regex/first-set.d.ts.map +1 -1
- package/dist/run/index.cjs +136 -51
- package/dist/run/index.cjs.map +2 -3
- package/dist/run/index.js +136 -51
- package/dist/run/index.js.map +2 -3
- package/dist/spec/index.cjs +2934 -1611
- package/dist/spec/index.cjs.map +3 -4
- package/dist/spec/index.js +2934 -1611
- package/dist/spec/index.js.map +3 -4
- package/dist/spec/model.d.ts +8 -0
- package/dist/spec/model.d.ts.map +1 -1
- package/dist/table/assemble.d.ts +307 -0
- package/dist/table/assemble.d.ts.map +1 -0
- package/dist/table/cell.d.ts +42 -0
- package/dist/table/cell.d.ts.map +1 -0
- package/dist/table/child-slots.d.ts +30 -0
- package/dist/table/child-slots.d.ts.map +1 -0
- package/dist/table/compile-rule-map.d.ts +136 -0
- package/dist/table/compile-rule-map.d.ts.map +1 -0
- package/dist/table/compile.d.ts +56 -0
- package/dist/table/compile.d.ts.map +1 -0
- package/dist/table/duplication-hook.d.ts +32 -0
- package/dist/table/duplication-hook.d.ts.map +1 -0
- package/dist/table/emit-assembly.d.ts +139 -0
- package/dist/table/emit-assembly.d.ts.map +1 -0
- package/dist/table/emit.d.ts +113 -0
- package/dist/table/emit.d.ts.map +1 -0
- package/dist/table/encode-baseline.d.ts +16 -0
- package/dist/table/encode-baseline.d.ts.map +1 -0
- package/dist/table/encode.d.ts +71 -0
- package/dist/table/encode.d.ts.map +1 -0
- package/dist/table/exec-baseline.d.ts +9 -0
- package/dist/table/exec-baseline.d.ts.map +1 -0
- package/dist/table/exec.d.ts +72 -0
- package/dist/table/exec.d.ts.map +1 -0
- package/dist/table/fold.d.ts +25 -0
- package/dist/table/fold.d.ts.map +1 -0
- package/dist/table/index.cjs +11463 -0
- package/dist/table/index.cjs.map +6 -0
- package/dist/table/index.d.ts +100 -0
- package/dist/table/index.d.ts.map +1 -0
- package/dist/table/index.js +11440 -0
- package/dist/table/index.js.map +6 -0
- package/dist/table/inspect.d.ts +17 -0
- package/dist/table/inspect.d.ts.map +1 -0
- package/dist/table/ops.d.ts +453 -0
- package/dist/table/ops.d.ts.map +1 -0
- package/dist/table/program.d.ts +496 -0
- package/dist/table/program.d.ts.map +1 -0
- package/dist/table/run-support.d.ts +38 -0
- package/dist/table/run-support.d.ts.map +1 -0
- package/dist/{compiler/scannable-run.d.ts → table/scan-shapes.d.ts} +14 -13
- package/dist/table/scan-shapes.d.ts.map +1 -0
- package/dist/table/site-labels.d.ts +58 -0
- package/dist/table/site-labels.d.ts.map +1 -0
- package/dist/table/stamp.d.ts +70 -0
- package/dist/table/stamp.d.ts.map +1 -0
- package/dist/types.d.ts +80 -24
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +26 -2
- package/src/analysis/choice-cost-gate.ts +359 -0
- package/src/analysis/choice-cost-render.ts +293 -0
- package/src/analysis/choice-cost.ts +1008 -0
- package/src/analysis/commitment.ts +557 -0
- package/src/analysis/corpus.ts +130 -0
- package/src/analysis/diagnose-render.ts +625 -0
- package/src/analysis/diagnose.ts +317 -0
- package/src/analysis/diagnostics.ts +33 -0
- package/src/analysis/duplication.ts +1955 -0
- package/src/analysis/fix-render.ts +217 -0
- package/src/analysis/fix.ts +669 -0
- package/src/analysis/format-number.ts +31 -0
- package/src/analysis/gating.ts +792 -0
- package/src/analysis/grammar.ts +72 -0
- package/src/analysis/rebuild.ts +287 -0
- package/src/analysis/terminal.ts +336 -0
- package/src/cli/index.ts +413 -0
- package/src/combinators/adjacency.ts +171 -0
- package/src/combinators/attempt.ts +41 -0
- package/src/combinators/case-fold.ts +90 -0
- package/src/combinators/choice.ts +466 -0
- package/src/combinators/completions.ts +64 -0
- package/src/combinators/dispatch.ts +358 -0
- package/src/combinators/expect.ts +159 -0
- package/src/combinators/first-set.ts +348 -0
- package/src/combinators/gate.ts +50 -0
- package/src/combinators/grammar.ts +272 -0
- package/src/combinators/keywords.ts +145 -0
- package/src/combinators/literal.ts +102 -0
- package/src/combinators/map.ts +106 -0
- package/src/combinators/node.ts +345 -0
- package/src/combinators/not.ts +55 -0
- package/src/combinators/parser.ts +266 -0
- package/src/combinators/peek.ts +63 -0
- package/src/combinators/probe.ts +25 -0
- package/src/combinators/ref.ts +109 -0
- package/src/combinators/regex.ts +170 -0
- package/src/combinators/repeat.ts +561 -0
- package/src/combinators/scanTo.ts +393 -0
- package/src/combinators/sequence.ts +237 -0
- package/src/combinators/token.ts +120 -0
- package/src/combinators/trivia-boundary.ts +48 -0
- package/src/combinators/trivia-skip.ts +852 -0
- package/src/combinators/withCtx.ts +45 -0
- package/src/compiler/build-arity.ts +330 -0
- package/src/compiler/compile-linkable-table.ts +209 -0
- package/src/compiler/degradation.ts +266 -0
- package/src/compiler/fields.ts +191 -0
- package/src/compiler/grammar-coverage-ids.ts +129 -0
- package/src/compiler/ir-serialize.ts +615 -0
- package/src/compiler/linker.ts +954 -0
- package/src/compiler/token-alphabet.ts +209 -0
- package/src/compiler/token-dispatch.ts +353 -0
- package/src/compiler/token-scanner.ts +318 -0
- package/src/compiler/value-usage.ts +147 -0
- package/src/coverage.ts +383 -0
- package/src/cst/capture-buffer.ts +297 -0
- package/src/cst/host-mode.ts +69 -0
- package/src/cst/reflection-attach.ts +11 -0
- package/src/cst/reflection-symbols.ts +9 -0
- package/src/cst/reflection.ts +149 -0
- package/src/cst/relative-spans.ts +207 -0
- package/src/cst/root-trivia-scope.ts +30 -0
- package/src/cst/trivia-charscan.ts +312 -0
- package/src/cst/trivia-entries.ts +285 -0
- package/src/cst/trivia-index.ts +131 -0
- package/src/cst/trivia-kinds.ts +358 -0
- package/src/cst/types.ts +76 -0
- package/src/cst/walk.ts +101 -0
- package/src/functional/doc.ts +959 -0
- package/src/functional/run-tabled.ts +153 -0
- package/src/functional/run.ts +558 -0
- package/src/grammar-metadata.ts +2 -0
- package/src/index.ts +189 -0
- package/src/language-service/index.ts +221 -0
- package/src/line-index.ts +131 -0
- package/src/oracle/digest.ts +620 -0
- package/src/oracle/index.ts +55 -0
- package/src/parse-context.ts +91 -0
- package/src/plugin/direct-builder-static.ts +102 -0
- package/src/plugin/evaluator.ts +1505 -0
- package/src/plugin/free-identifiers.ts +338 -0
- package/src/plugin/index.ts +2281 -0
- package/src/plugin/reducer-resolver.ts +606 -0
- package/src/recovery/scan.ts +155 -0
- package/src/regex/classes.ts +183 -0
- package/src/regex/first-set.ts +316 -0
- package/src/run/index.ts +31 -0
- package/src/spec/ebnf.ts +128 -0
- package/src/spec/index.ts +54 -0
- package/src/spec/model.ts +636 -0
- package/src/spec/railroad-lib.ts +559 -0
- package/src/spec/railroad.ts +256 -0
- package/src/table/assemble.ts +3006 -0
- package/src/table/cell.ts +42 -0
- package/src/table/child-slots.ts +113 -0
- package/src/table/compile-rule-map.ts +336 -0
- package/src/table/compile.ts +244 -0
- package/src/table/duplication-hook.ts +89 -0
- package/src/table/emit-assembly.ts +1777 -0
- package/src/table/emit.ts +429 -0
- package/src/table/encode-baseline.ts +340 -0
- package/src/table/encode.ts +1569 -0
- package/src/table/exec-baseline.ts +537 -0
- package/src/table/exec.ts +1680 -0
- package/src/table/fold.ts +38 -0
- package/src/table/index.ts +108 -0
- package/src/table/inspect.ts +52 -0
- package/src/table/ops.ts +467 -0
- package/src/table/program.ts +876 -0
- package/src/table/run-support.ts +66 -0
- package/src/table/scan-shapes.ts +1578 -0
- package/src/table/site-labels.ts +228 -0
- package/src/table/stamp.ts +229 -0
- package/src/types.ts +563 -0
- package/src/version.ts +16 -0
- package/dist/compiler/codegen.d.ts +0 -334
- package/dist/compiler/codegen.d.ts.map +0 -1
- package/dist/compiler/inline-build.d.ts +0 -11
- package/dist/compiler/inline-build.d.ts.map +0 -1
- package/dist/compiler/inline-callback.d.ts +0 -21
- package/dist/compiler/inline-callback.d.ts.map +0 -1
- package/dist/compiler/line-index.d.ts +0 -2
- package/dist/compiler/line-index.d.ts.map +0 -1
- package/dist/compiler/module-hoist.d.ts +0 -106
- package/dist/compiler/module-hoist.d.ts.map +0 -1
- package/dist/compiler/scannable-run.d.ts.map +0 -1
- package/dist/compiler/scannable-terminal.d.ts +0 -23
- package/dist/compiler/scannable-terminal.d.ts.map +0 -1
- package/dist/compiler/trivia-fast-path.d.ts +0 -38
- package/dist/compiler/trivia-fast-path.d.ts.map +0 -1
|
@@ -72,24 +72,26 @@ function annotateSpanFromLineContext(span, ctx) {
|
|
|
72
72
|
function cstCaptureActive(ctx) {
|
|
73
73
|
return ctx._cstBuf !== void 0 || ctx._cstLeaves !== void 0;
|
|
74
74
|
}
|
|
75
|
-
function pushCstChild(ctx, built,
|
|
75
|
+
function pushCstChild(ctx, built, rawEntry2) {
|
|
76
76
|
const b = ctx._cstBuf;
|
|
77
77
|
if (b) {
|
|
78
|
-
if (b.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
78
|
+
if (b.rawOnly !== true) {
|
|
79
|
+
if (b.ch) b.ch.push(built);
|
|
80
|
+
else if (b.single !== void 0) {
|
|
81
|
+
b.ch = [b.single, built];
|
|
82
|
+
b.single = void 0;
|
|
83
|
+
} else b.single = built;
|
|
84
|
+
}
|
|
85
|
+
if (b.raw) b.raw.push(rawEntry2);
|
|
84
86
|
else if (b.rawSingle !== void 0) {
|
|
85
|
-
b.raw = [b.rawSingle,
|
|
87
|
+
b.raw = [b.rawSingle, rawEntry2];
|
|
86
88
|
b.rawSingle = void 0;
|
|
87
|
-
} else b.rawSingle =
|
|
89
|
+
} else b.rawSingle = rawEntry2;
|
|
88
90
|
return;
|
|
89
91
|
}
|
|
90
92
|
if (ctx._cstChildren) ctx._cstChildren.push(built);
|
|
91
93
|
else if (ctx._cstLeaves) ctx._cstLeaves.push(built);
|
|
92
|
-
if (ctx._cstRawChildren) ctx._cstRawChildren.push(
|
|
94
|
+
if (ctx._cstRawChildren) ctx._cstRawChildren.push(rawEntry2);
|
|
93
95
|
}
|
|
94
96
|
|
|
95
97
|
// src/recovery/scan.ts
|
|
@@ -185,6 +187,45 @@ function captureError(ctx, error) {
|
|
|
185
187
|
}
|
|
186
188
|
var REC = { scan: recoverScan, at: matchesAt, or: orSentinel, sentinel: firstSetSentinel, capture: captureError };
|
|
187
189
|
|
|
190
|
+
// src/parse-context.ts
|
|
191
|
+
function createParseContext() {
|
|
192
|
+
return {
|
|
193
|
+
trivia: void 0,
|
|
194
|
+
scanSkip: void 0,
|
|
195
|
+
triviaKindLabels: void 0,
|
|
196
|
+
captureTrivia: void 0,
|
|
197
|
+
_triviaCaptureMask: void 0,
|
|
198
|
+
trackLines: false,
|
|
199
|
+
state: void 0,
|
|
200
|
+
build: void 0,
|
|
201
|
+
_errors: void 0,
|
|
202
|
+
_tolerant: void 0,
|
|
203
|
+
_sync: void 0,
|
|
204
|
+
_rec: void 0,
|
|
205
|
+
_fe: void 0,
|
|
206
|
+
_fx: void 0,
|
|
207
|
+
_fc: void 0,
|
|
208
|
+
_probe: void 0,
|
|
209
|
+
_cstChildren: void 0,
|
|
210
|
+
_cstLeaves: void 0,
|
|
211
|
+
_cstRawChildren: void 0,
|
|
212
|
+
_triviaLog: void 0,
|
|
213
|
+
_rootTriviaLog: void 0,
|
|
214
|
+
_rootTriviaKindIndex: void 0,
|
|
215
|
+
_rootTriviaStrictScopes: void 0,
|
|
216
|
+
_rootTriviaCapture: void 0,
|
|
217
|
+
_cstTriviaLog: void 0,
|
|
218
|
+
_fields: void 0,
|
|
219
|
+
_cstBuf: void 0,
|
|
220
|
+
_routed: void 0,
|
|
221
|
+
_lineStarts: void 0,
|
|
222
|
+
_lineIndex: void 0,
|
|
223
|
+
_lineScannedTo: void 0,
|
|
224
|
+
_grammarCoverage: void 0,
|
|
225
|
+
_grammarTrace: void 0
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
188
229
|
// src/cst/trivia-entries.ts
|
|
189
230
|
var EMPTY_INDICES = Object.freeze([]);
|
|
190
231
|
var EMPTY_GAPS = Object.freeze([]);
|
|
@@ -366,9 +407,30 @@ var REMOVED_RUN_RESULT_FIELDS = [
|
|
|
366
407
|
`It was already optional, so nothing ever flagged its disappearance \u2014 and \`triviaKindMask(undefined, \u2026)\` means "capture everything", so reading it now silently WIDENS capture instead of erroring. Migration: request labels \u2014 ${SELECT_EXAMPLE} \u2014 then the set you asked for is \`RunResult.rootTrivia.select\` and the resolved table is \`RunResult.rootTrivia.index.labels\`.`
|
|
367
408
|
]
|
|
368
409
|
];
|
|
369
|
-
|
|
410
|
+
var RunResultRecord = class {
|
|
411
|
+
constructor(ok, value, span, expected, errors, unconsumedFrom) {
|
|
412
|
+
this.ok = ok;
|
|
413
|
+
this.value = value;
|
|
414
|
+
this.span = span;
|
|
415
|
+
this.expected = expected;
|
|
416
|
+
this.errors = errors;
|
|
417
|
+
this.unconsumedFrom = unconsumedFrom;
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
var RunResultWithRootTrivia = class {
|
|
421
|
+
constructor(ok, value, span, expected, errors, rootTrivia, unconsumedFrom) {
|
|
422
|
+
this.ok = ok;
|
|
423
|
+
this.value = value;
|
|
424
|
+
this.span = span;
|
|
425
|
+
this.expected = expected;
|
|
426
|
+
this.errors = errors;
|
|
427
|
+
this.rootTrivia = rootTrivia;
|
|
428
|
+
this.unconsumedFrom = unconsumedFrom;
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
for (const proto of [RunResultRecord.prototype, RunResultWithRootTrivia.prototype]) {
|
|
370
432
|
for (const [name, detail] of REMOVED_RUN_RESULT_FIELDS) {
|
|
371
|
-
Object.defineProperty(
|
|
433
|
+
Object.defineProperty(proto, name, {
|
|
372
434
|
configurable: true,
|
|
373
435
|
enumerable: false,
|
|
374
436
|
get() {
|
|
@@ -378,9 +440,14 @@ function guardRemovedFields(result) {
|
|
|
378
440
|
}
|
|
379
441
|
});
|
|
380
442
|
}
|
|
381
|
-
return result;
|
|
382
443
|
}
|
|
383
444
|
var invoke = (r, input, pos, ctx) => typeof r === "function" ? r(input, pos, ctx) : r.parse(input, pos, ctx);
|
|
445
|
+
function ambientTriviaFromRunnable(r) {
|
|
446
|
+
if (!r) return void 0;
|
|
447
|
+
if (typeof r === "function") return r._meta?.grammarTrivia;
|
|
448
|
+
if (r._meta.isTrivia) return void 0;
|
|
449
|
+
return r._meta.grammarTrivia ?? (r._def.tag === "grammar" ? r._def.triviaParser : void 0);
|
|
450
|
+
}
|
|
384
451
|
function triviaKindLabelsFromRunnable(r) {
|
|
385
452
|
if (!r) return void 0;
|
|
386
453
|
if (typeof r === "function") return r._meta?.triviaKindLabels;
|
|
@@ -400,7 +467,23 @@ function makeSelectedRootLabelIndex(labels) {
|
|
|
400
467
|
}
|
|
401
468
|
return index;
|
|
402
469
|
}
|
|
403
|
-
function
|
|
470
|
+
function growSpanEnd(span, input, end) {
|
|
471
|
+
if (span.endLine === void 0 || span.endColumn === void 0) {
|
|
472
|
+
return { start: span.start, end };
|
|
473
|
+
}
|
|
474
|
+
let line = span.endLine;
|
|
475
|
+
let column = span.endColumn;
|
|
476
|
+
for (let i = span.end; i < end; i++) {
|
|
477
|
+
if (input.charCodeAt(i) === 10) {
|
|
478
|
+
line++;
|
|
479
|
+
column = 1;
|
|
480
|
+
} else {
|
|
481
|
+
column++;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
return { ...span, end, endLine: line, endColumn: column };
|
|
485
|
+
}
|
|
486
|
+
function runOnce(entry, input, options) {
|
|
404
487
|
if (typeof entry !== "function" && typeof entry?.parse !== "function") {
|
|
405
488
|
throw new TypeError(
|
|
406
489
|
`run(): start production is ${entry === null ? "null" : typeof entry}, not a rule \u2014 the requested grammar rule does not exist (check the rule name).`
|
|
@@ -411,8 +494,6 @@ function runOnce(entry, input, options, phase, profileState) {
|
|
|
411
494
|
const selectedRootLog = captureRootTrivia ? [] : void 0;
|
|
412
495
|
const selectedRootLabelIndex = captureRootTrivia ? makeSelectedRootLabelIndex(rootTriviaSelection) : void 0;
|
|
413
496
|
const errors = [];
|
|
414
|
-
const profile = profileState ?? (phase === void 0 ? void 0 : { phase, nodes: 0, childSlots: 0, rawSlots: 0, triviaSlots: 0, fieldSlots: 0, hostCalls: 0 });
|
|
415
|
-
const skipGlobalSinks = phase === "recognizer" || phase === "capture";
|
|
416
497
|
const grammarTrivia = typeof entry !== "function" ? entry._meta.grammarTrivia : void 0;
|
|
417
498
|
const grammarScanSkip = typeof entry !== "function" ? entry._meta.grammarScanSkip : void 0;
|
|
418
499
|
const triviaKindLabels = triviaKindLabelsFromRunnable(entry) ?? triviaKindLabelsFromRunnable(options.trivia);
|
|
@@ -437,62 +518,71 @@ function runOnce(entry, input, options, phase, profileState) {
|
|
|
437
518
|
options.build,
|
|
438
519
|
typeof entry === "function" && stamped[FUSED_HOST_ELIDED] === true
|
|
439
520
|
);
|
|
440
|
-
const ctx =
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
521
|
+
const ctx = createParseContext();
|
|
522
|
+
if (captureRootTrivia) {
|
|
523
|
+
ctx._rootTriviaLog = selectedRootLog;
|
|
524
|
+
ctx._rootTriviaKindIndex = selectedRootLabelIndex;
|
|
525
|
+
ctx._rootTriviaStrictScopes = true;
|
|
526
|
+
}
|
|
527
|
+
ctx._errors = errors;
|
|
528
|
+
ctx.build = options.build;
|
|
529
|
+
ctx.state = options.state;
|
|
530
|
+
if (grammarTrivia !== void 0) ctx.trivia = grammarTrivia;
|
|
531
|
+
if (triviaKindLabels) ctx.triviaKindLabels = triviaKindLabels;
|
|
532
|
+
if (grammarScanSkip !== void 0) ctx.scanSkip = grammarScanSkip;
|
|
533
|
+
if (options.triviaCaptureMask !== void 0) ctx._triviaCaptureMask = options.triviaCaptureMask;
|
|
534
|
+
if (options.tolerant) {
|
|
535
|
+
ctx._tolerant = true;
|
|
536
|
+
ctx._rec = REC;
|
|
537
|
+
}
|
|
538
|
+
if (options.instrumentation !== void 0) {
|
|
539
|
+
ctx._grammarCoverage = options.instrumentation._grammarCoverage;
|
|
540
|
+
ctx._grammarTrace = options.instrumentation._grammarTrace;
|
|
541
|
+
}
|
|
459
542
|
const r = invoke(entry, input, 0, ctx);
|
|
543
|
+
const value = r.ok ? r.value : void 0;
|
|
544
|
+
let span = r.span ?? { start: 0, end: 0 };
|
|
545
|
+
const expected = r.ok ? [] : r.expected ?? [];
|
|
460
546
|
let unconsumedFrom = null;
|
|
461
547
|
if (r.ok) {
|
|
462
|
-
let pos =
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
548
|
+
let pos = span.end;
|
|
549
|
+
const tail = options.trivia ?? ambientTriviaFromRunnable(entry);
|
|
550
|
+
if (tail !== void 0 && pos < input.length) {
|
|
551
|
+
const t = invoke(tail, input, pos, createParseContext());
|
|
552
|
+
if (t.ok && t.span.end > pos) {
|
|
553
|
+
span = growSpanEnd(span, input, t.span.end);
|
|
554
|
+
pos = t.span.end;
|
|
555
|
+
}
|
|
466
556
|
}
|
|
467
557
|
unconsumedFrom = pos < input.length ? pos : null;
|
|
468
558
|
}
|
|
469
|
-
return
|
|
470
|
-
|
|
471
|
-
value
|
|
472
|
-
span
|
|
473
|
-
expected
|
|
559
|
+
return selectedRootLog !== void 0 && selectedRootLog.length > 0 ? new RunResultWithRootTrivia(
|
|
560
|
+
r.ok,
|
|
561
|
+
value,
|
|
562
|
+
span,
|
|
563
|
+
expected,
|
|
474
564
|
errors,
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
}
|
|
481
|
-
} : {},
|
|
565
|
+
{
|
|
566
|
+
rows: selectedRootLog,
|
|
567
|
+
select: rootTriviaSelection,
|
|
568
|
+
index: buildRootTriviaIndex(selectedRootLog, rootTriviaSelection)
|
|
569
|
+
},
|
|
482
570
|
unconsumedFrom
|
|
483
|
-
|
|
571
|
+
) : new RunResultRecord(r.ok, value, span, expected, errors, unconsumedFrom);
|
|
484
572
|
}
|
|
485
573
|
function run(entry, input, options = {}) {
|
|
486
|
-
|
|
487
|
-
throw new TypeError(
|
|
488
|
-
"run({ profile: true }) is unavailable: profiling counters are no longer compiled into parser artifacts, and the interpreter does not implement them yet. Profiling is moving to interpreted mode."
|
|
489
|
-
);
|
|
574
|
+
return runOnce(entry, input, options);
|
|
490
575
|
}
|
|
491
576
|
|
|
492
577
|
// src/combinators/completions.ts
|
|
493
578
|
function completionsAt(target, input, offset, options = {}) {
|
|
494
579
|
const probe = { offset, best: null };
|
|
495
|
-
const ctx =
|
|
580
|
+
const ctx = createParseContext();
|
|
581
|
+
ctx._probe = probe;
|
|
582
|
+
if (options.tolerant) {
|
|
583
|
+
ctx._tolerant = true;
|
|
584
|
+
ctx._rec = REC;
|
|
585
|
+
}
|
|
496
586
|
const sliced = input.slice(0, offset);
|
|
497
587
|
const result = "parseWithContext" in target ? target.parseWithContext(sliced, ctx, 0) : target.parse(sliced, 0, ctx);
|
|
498
588
|
if (result.ok) return options.tolerant ? probe.best?.expected ?? [] : [];
|
|
@@ -505,36 +595,106 @@ function deeperFail(a, b) {
|
|
|
505
595
|
return a.span.start >= b.span.start ? a : b;
|
|
506
596
|
}
|
|
507
597
|
|
|
508
|
-
// src/
|
|
509
|
-
var WORD_RE_SRC = "-?[A-Za-z][A-Za-z0-9_-]*";
|
|
510
|
-
var WORDS_RE = new RegExp(`^${WORD_RE_SRC}(?:\\|${WORD_RE_SRC})*$`);
|
|
511
|
-
|
|
512
|
-
// src/compiler/scannable-run.ts
|
|
598
|
+
// src/regex/classes.ts
|
|
513
599
|
var META = new Set("()[]{}*+?|^$.".split(""));
|
|
514
|
-
var SELECTED_ROOT_OWNED_RANGE_PLACEHOLDER = Array.from(
|
|
515
|
-
{ length: SELECTED_ROOT_STRIDE - 3 },
|
|
516
|
-
() => "0"
|
|
517
|
-
).join(", ");
|
|
518
600
|
|
|
519
|
-
// src/
|
|
520
|
-
var
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
var
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
601
|
+
// src/table/ops.ts
|
|
602
|
+
var OP_LIT = 1;
|
|
603
|
+
var OP_RX = 2;
|
|
604
|
+
var OP_SEQ = 3;
|
|
605
|
+
var OP_SEQV = 4;
|
|
606
|
+
var OP_CHOICE = 5;
|
|
607
|
+
var OP_REP = 6;
|
|
608
|
+
var OP_REPV = 7;
|
|
609
|
+
var OP_OPT = 8;
|
|
610
|
+
var OP_XFORM = 9;
|
|
611
|
+
var OP_NODE = 10;
|
|
612
|
+
var OP_RULE = 11;
|
|
613
|
+
var OP_GATE = 12;
|
|
614
|
+
var OP_NOT = 13;
|
|
615
|
+
var OP_PEEK = 14;
|
|
616
|
+
var OP_LEAF = 15;
|
|
617
|
+
var OP_EMPTY = 16;
|
|
618
|
+
var OP_LIT_TRACK = 17;
|
|
619
|
+
var OP_RX_TRACK = 18;
|
|
620
|
+
var OP_NODE_TRACK = 19;
|
|
621
|
+
var OP_SCOPE = 20;
|
|
622
|
+
var OP_EXPECT = 21;
|
|
623
|
+
var OP_SEQX = 22;
|
|
624
|
+
var OP_SCAN = 23;
|
|
625
|
+
var OP_FIELD = 24;
|
|
626
|
+
var OP_LIT_CI = 27;
|
|
627
|
+
var OP_LIT_CI_TRACK = 28;
|
|
628
|
+
var OP_TOKEN = 29;
|
|
629
|
+
var OP_SCOPE_CAP = 30;
|
|
630
|
+
var OP_WITHCTX = 31;
|
|
631
|
+
var OP_GUARD = 32;
|
|
632
|
+
var OP_ADJ = 33;
|
|
633
|
+
var OP_GREEDY = 34;
|
|
634
|
+
var OP_REJECT = 35;
|
|
635
|
+
var OP_ARMGATE = 36;
|
|
636
|
+
var OP_LIVE = 37;
|
|
637
|
+
var OP_ATTEMPT = 38;
|
|
638
|
+
var OP_LABEL = 39;
|
|
639
|
+
var OP_COV = 40;
|
|
640
|
+
var OP_SCOPE_PLAIN = 41;
|
|
641
|
+
var OP_DISPATCH = 25;
|
|
642
|
+
var OP_ROUTED = 26;
|
|
643
|
+
var OP_NAMES = {
|
|
644
|
+
[OP_LIT]: "LIT",
|
|
645
|
+
[OP_RX]: "RX",
|
|
646
|
+
[OP_SEQ]: "SEQ",
|
|
647
|
+
[OP_SEQV]: "SEQV",
|
|
648
|
+
[OP_CHOICE]: "CHOICE",
|
|
649
|
+
[OP_REP]: "REP",
|
|
650
|
+
[OP_REPV]: "REPV",
|
|
651
|
+
[OP_OPT]: "OPT",
|
|
652
|
+
[OP_XFORM]: "XFORM",
|
|
653
|
+
[OP_NODE]: "NODE",
|
|
654
|
+
[OP_RULE]: "RULE",
|
|
655
|
+
[OP_GATE]: "GATE",
|
|
656
|
+
[OP_NOT]: "NOT",
|
|
657
|
+
[OP_PEEK]: "PEEK",
|
|
658
|
+
[OP_LEAF]: "LEAF",
|
|
659
|
+
[OP_EMPTY]: "EMPTY",
|
|
660
|
+
[OP_LIT_TRACK]: "LIT_TRACK",
|
|
661
|
+
[OP_RX_TRACK]: "RX_TRACK",
|
|
662
|
+
[OP_NODE_TRACK]: "NODE_TRACK",
|
|
663
|
+
[OP_SCOPE]: "SCOPE",
|
|
664
|
+
[OP_EXPECT]: "EXPECT",
|
|
665
|
+
[OP_SEQX]: "SEQX",
|
|
666
|
+
[OP_SCAN]: "SCAN",
|
|
667
|
+
[OP_FIELD]: "FIELD",
|
|
668
|
+
[OP_LIT_CI]: "LIT_CI",
|
|
669
|
+
[OP_LIT_CI_TRACK]: "LIT_CI_TRACK",
|
|
670
|
+
[OP_DISPATCH]: "DISPATCH",
|
|
671
|
+
[OP_ROUTED]: "ROUTED",
|
|
672
|
+
[OP_TOKEN]: "TOKEN",
|
|
673
|
+
[OP_SCOPE_CAP]: "SCOPE_CAP",
|
|
674
|
+
[OP_WITHCTX]: "WITHCTX",
|
|
675
|
+
[OP_GUARD]: "GUARD",
|
|
676
|
+
[OP_ADJ]: "ADJ",
|
|
677
|
+
[OP_GREEDY]: "GREEDY",
|
|
678
|
+
[OP_REJECT]: "REJECT",
|
|
679
|
+
[OP_ARMGATE]: "ARMGATE",
|
|
680
|
+
[OP_LIVE]: "LIVE",
|
|
681
|
+
[OP_ATTEMPT]: "ATTEMPT",
|
|
682
|
+
[OP_LABEL]: "LABEL",
|
|
683
|
+
[OP_COV]: "COV",
|
|
684
|
+
[OP_SCOPE_PLAIN]: "SCOPE_PLAIN"
|
|
685
|
+
};
|
|
686
|
+
|
|
687
|
+
// src/table/scan-shapes.ts
|
|
688
|
+
var META2 = new Set("()[]{}*+?|^$.".split(""));
|
|
689
|
+
|
|
690
|
+
// src/table/assemble.ts
|
|
691
|
+
var EMIT_ENABLED = globalThis.process?.env?.PM_TABLE_EMIT !== "0";
|
|
692
|
+
var EMPTY_TL = Object.freeze([]);
|
|
693
|
+
var EMPTY_SENTS = Object.freeze([]);
|
|
531
694
|
|
|
532
|
-
// src/
|
|
533
|
-
var
|
|
534
|
-
var
|
|
535
|
-
var MK_BUILD_RE = new RegExp(
|
|
536
|
-
String.raw`^\(\s*(\w+)${ANN}\s*,\s*${ANY_P}\s*,\s*(\w+)${ANN}\s*,\s*(\w+)${ANN}\s*,\s*(\w+)${ANN}\s*\)\s*=>\s*mk\s*\(\s*(['"])([^'"]+)\5\s*,\s*\1\s*,\s*\3\s*,\s*\2\s*,\s*\4\s*\)\s*$`
|
|
537
|
-
);
|
|
695
|
+
// src/analysis/duplication.ts
|
|
696
|
+
var WORD_RE_SRC = "-?[A-Za-z][A-Za-z0-9_-]*";
|
|
697
|
+
var WORDS_RE = new RegExp(`^${WORD_RE_SRC}(?:\\|${WORD_RE_SRC})*$`);
|
|
538
698
|
|
|
539
699
|
// src/compiler/linker.ts
|
|
540
700
|
function normalizeCstCollapse(collapse) {
|
|
@@ -608,14 +768,48 @@ function asRuleFn(entry) {
|
|
|
608
768
|
function defOf(entry) {
|
|
609
769
|
return typeof entry === "object" && entry !== null && "_def" in entry ? entry._def : void 0;
|
|
610
770
|
}
|
|
771
|
+
function literalTextOf(parser2, depth = 0) {
|
|
772
|
+
const def = defOf(parser2);
|
|
773
|
+
if (!def || depth > 24) return null;
|
|
774
|
+
const d = def;
|
|
775
|
+
switch (d.tag) {
|
|
776
|
+
case "literal":
|
|
777
|
+
return d.caseInsensitive ? null : d.value;
|
|
778
|
+
case "lazy": {
|
|
779
|
+
const thunk = d.thunk;
|
|
780
|
+
try {
|
|
781
|
+
return typeof thunk === "function" ? literalTextOf(thunk(), depth + 1) : null;
|
|
782
|
+
} catch {
|
|
783
|
+
return null;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
case "node":
|
|
787
|
+
case "transform":
|
|
788
|
+
case "attempt":
|
|
789
|
+
case "token":
|
|
790
|
+
case "leaf":
|
|
791
|
+
case "label":
|
|
792
|
+
case "field":
|
|
793
|
+
case "expect":
|
|
794
|
+
case "withCtx":
|
|
795
|
+
case "grammar":
|
|
796
|
+
return literalTextOf(d.parser, depth + 1);
|
|
797
|
+
default:
|
|
798
|
+
return null;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
611
801
|
function producesRepetition(def, depth = 0) {
|
|
612
|
-
if (!def || depth > 24) return
|
|
802
|
+
if (!def || depth > 24) return null;
|
|
613
803
|
const d = def;
|
|
614
804
|
switch (d.tag) {
|
|
615
|
-
case "sepBy":
|
|
805
|
+
case "sepBy": {
|
|
806
|
+
if (d.keepSeparators) return null;
|
|
807
|
+
const text = literalTextOf(d.separator);
|
|
808
|
+
return text === null || text.length === 0 ? null : { kind: "sep", text };
|
|
809
|
+
}
|
|
616
810
|
case "many":
|
|
617
811
|
case "oneOrMore":
|
|
618
|
-
return
|
|
812
|
+
return { kind: "bare" };
|
|
619
813
|
// Rule entries and `ref`s wrap their body in a `lazy` thunk — resolve it. The
|
|
620
814
|
// `depth` cap bounds any self-referential cycle (a repetition, if present, is
|
|
621
815
|
// found shallowly before recursion goes deep).
|
|
@@ -625,7 +819,7 @@ function producesRepetition(def, depth = 0) {
|
|
|
625
819
|
try {
|
|
626
820
|
inner = typeof thunk === "function" ? thunk() : void 0;
|
|
627
821
|
} catch {
|
|
628
|
-
return
|
|
822
|
+
return null;
|
|
629
823
|
}
|
|
630
824
|
return producesRepetition(inner?._def, depth + 1);
|
|
631
825
|
}
|
|
@@ -642,13 +836,16 @@ function producesRepetition(def, depth = 0) {
|
|
|
642
836
|
case "grammar":
|
|
643
837
|
case "optional":
|
|
644
838
|
return producesRepetition(defOf(d.parser), depth + 1);
|
|
645
|
-
case "skip":
|
|
646
|
-
return producesRepetition(defOf(d.main), depth + 1);
|
|
647
839
|
// A bracketed/anchored list is a sequence whose element run is a repetition.
|
|
648
|
-
case "sequence":
|
|
649
|
-
|
|
840
|
+
case "sequence": {
|
|
841
|
+
for (const p of d.parsers) {
|
|
842
|
+
const rep = producesRepetition(defOf(p), depth + 1);
|
|
843
|
+
if (rep) return rep;
|
|
844
|
+
}
|
|
845
|
+
return null;
|
|
846
|
+
}
|
|
650
847
|
default:
|
|
651
|
-
return
|
|
848
|
+
return null;
|
|
652
849
|
}
|
|
653
850
|
}
|
|
654
851
|
var REENTRY_MAX_SPAN_FRACTION = 0.5;
|
|
@@ -710,17 +907,18 @@ function graftRelative(root, path, newNode, delta) {
|
|
|
710
907
|
children: newChildren
|
|
711
908
|
};
|
|
712
909
|
}
|
|
713
|
-
function parseMiddle(input, reStart, reEnd, cStart, ruleFn, separator, build, tolerant) {
|
|
910
|
+
function parseMiddle(input, reStart, reEnd, cStart, ruleFn, separator, startsAtElement, build, tolerant) {
|
|
714
911
|
const ctx = mkCtx(null, build, tolerant);
|
|
715
912
|
const out = [];
|
|
716
913
|
let pos = reStart;
|
|
717
914
|
let guard = 0;
|
|
915
|
+
let expectElement = separator === null ? true : startsAtElement;
|
|
718
916
|
while (pos < reEnd) {
|
|
719
917
|
if (++guard > reEnd - reStart + 2) return null;
|
|
720
|
-
if (separator
|
|
918
|
+
if (separator !== null && !expectElement) {
|
|
721
919
|
if (pos + separator.length > reEnd || !input.startsWith(separator, pos)) return null;
|
|
722
|
-
out.push({ _tag: "leaf", value: separator, span: { start: pos - cStart, end: pos + separator.length - cStart } });
|
|
723
920
|
pos += separator.length;
|
|
921
|
+
expectElement = true;
|
|
724
922
|
continue;
|
|
725
923
|
}
|
|
726
924
|
let r;
|
|
@@ -732,15 +930,15 @@ function parseMiddle(input, reStart, reEnd, cStart, ruleFn, separator, build, to
|
|
|
732
930
|
if (!r.ok || r.span.end <= pos || r.span.end > reEnd) return null;
|
|
733
931
|
out.push(relativizeCST(r.value, cStart));
|
|
734
932
|
pos = r.span.end;
|
|
933
|
+
if (separator !== null) expectElement = false;
|
|
735
934
|
}
|
|
736
|
-
return pos === reEnd ? out : null;
|
|
935
|
+
return pos === reEnd && expectElement ? out : null;
|
|
737
936
|
}
|
|
738
|
-
function tryListSplice(root, path, C, cStart, newInput, from, to, delta, registry, build, tolerant) {
|
|
937
|
+
function tryListSplice(root, path, C, cStart, newInput, from, to, delta, rep, registry, build, tolerant) {
|
|
739
938
|
const kids = C.children;
|
|
740
939
|
if (kids.length === 0) return null;
|
|
741
940
|
let h = 0;
|
|
742
941
|
while (h < kids.length && cStart + kids[h].span.end <= from) h++;
|
|
743
|
-
while (h > 0 && kids[h - 1]._tag === "node") h--;
|
|
744
942
|
let t = kids.length;
|
|
745
943
|
while (t > h && cStart + kids[t - 1].span.start >= to) t--;
|
|
746
944
|
while (t < kids.length && kids[t]._tag !== "node") t++;
|
|
@@ -759,16 +957,7 @@ function tryListSplice(root, path, C, cStart, newInput, from, to, delta, registr
|
|
|
759
957
|
if (elemType === void 0 || elemCount < 2) return null;
|
|
760
958
|
const ruleFn = registry[elemType];
|
|
761
959
|
if (!ruleFn) return null;
|
|
762
|
-
|
|
763
|
-
for (let i = 1; i < kids.length - 1; i++) {
|
|
764
|
-
if (kids[i - 1]._tag === "node" && kids[i + 1]._tag === "node") {
|
|
765
|
-
if (kids[i]._tag !== "leaf") return null;
|
|
766
|
-
const sep = kids[i].value ?? null;
|
|
767
|
-
if (separator === null) separator = sep;
|
|
768
|
-
else if (sep !== separator) return null;
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
if (separator === null) return null;
|
|
960
|
+
const separator = rep.kind === "sep" ? rep.text : null;
|
|
772
961
|
const first = kids[0];
|
|
773
962
|
const last = kids[kids.length - 1];
|
|
774
963
|
if (first._tag === "leaf" && first.value !== separator && from < cStart + first.span.end) return null;
|
|
@@ -776,17 +965,14 @@ function tryListSplice(root, path, C, cStart, newInput, from, to, delta, registr
|
|
|
776
965
|
const reStart = h > 0 ? cStart + kids[h - 1].span.end : cStart;
|
|
777
966
|
const reEnd = cStart + kids[t].span.start + delta;
|
|
778
967
|
if (reEnd < reStart) return null;
|
|
779
|
-
const
|
|
968
|
+
const startsAtElement = !(h > 0 && kids[h - 1]._tag === "node");
|
|
969
|
+
const middle = parseMiddle(newInput, reStart, reEnd, cStart, ruleFn, separator, startsAtElement, build, tolerant);
|
|
780
970
|
if (!middle) return null;
|
|
781
|
-
if (middle.length > 0) {
|
|
782
|
-
const last2 = middle[middle.length - 1];
|
|
783
|
-
if (!(last2._tag === "leaf" && last2.value === separator)) return null;
|
|
784
|
-
}
|
|
785
971
|
if (reEnd < newInput.length) {
|
|
786
972
|
for (const sentinel of [" ", "\uFFFF"]) {
|
|
787
973
|
if (newInput[reEnd] === sentinel) continue;
|
|
788
974
|
const probed = newInput.slice(0, reEnd) + sentinel.repeat(newInput.length - reEnd);
|
|
789
|
-
const probe = parseMiddle(probed, reStart, reEnd, cStart, ruleFn, separator, build, tolerant);
|
|
975
|
+
const probe = parseMiddle(probed, reStart, reEnd, cStart, ruleFn, separator, startsAtElement, build, tolerant);
|
|
790
976
|
if (!probe || probe.length !== middle.length) return null;
|
|
791
977
|
for (let i = 0; i < middle.length; i++) if (!structurallyEqual(probe[i], middle[i])) return null;
|
|
792
978
|
}
|
|
@@ -850,7 +1036,11 @@ var ParseDocImpl = class _ParseDocImpl {
|
|
|
850
1036
|
_registry;
|
|
851
1037
|
/** Registry entries normalized to callable parse functions (memoized once). */
|
|
852
1038
|
_fns;
|
|
853
|
-
/**
|
|
1039
|
+
/**
|
|
1040
|
+
* Rule names the grammar proves are genuine repetitions — the ONLY splice-safe
|
|
1041
|
+
* types — mapped to the repetition shape (and, for a `sepBy`, the separator text
|
|
1042
|
+
* its construction pins). A rule whose separator isn't recoverable is absent.
|
|
1043
|
+
*/
|
|
854
1044
|
_reps;
|
|
855
1045
|
_rootRule;
|
|
856
1046
|
_opts;
|
|
@@ -871,10 +1061,11 @@ var ParseDocImpl = class _ParseDocImpl {
|
|
|
871
1061
|
constructor(registry, rootRule, opts, trees, errors, unconsumedFrom, input) {
|
|
872
1062
|
this._registry = registry;
|
|
873
1063
|
this._fns = {};
|
|
874
|
-
this._reps = /* @__PURE__ */ new
|
|
1064
|
+
this._reps = /* @__PURE__ */ new Map();
|
|
875
1065
|
for (const [name, entry] of Object.entries(registry)) {
|
|
876
1066
|
this._fns[name] = asRuleFn(entry);
|
|
877
|
-
|
|
1067
|
+
const rep = producesRepetition(defOf(entry));
|
|
1068
|
+
if (rep) this._reps.set(name, rep);
|
|
878
1069
|
}
|
|
879
1070
|
this._rootRule = rootRule;
|
|
880
1071
|
this._opts = opts;
|
|
@@ -958,10 +1149,11 @@ var ParseDocImpl = class _ParseDocImpl {
|
|
|
958
1149
|
if (this._opts.structuralReuse && delta !== 0 && !this._opts.rebuild) {
|
|
959
1150
|
const spliceCandidates = [...candidates, { node: root, path: [] }];
|
|
960
1151
|
for (const { node: node2, path } of spliceCandidates) {
|
|
961
|
-
|
|
1152
|
+
const rep = this._reps.get(node2.type);
|
|
1153
|
+
if (!rep) continue;
|
|
962
1154
|
const { start: cStart, end: cEnd } = absoluteSpanCST(root, path);
|
|
963
1155
|
if (!(cStart <= from && to <= cEnd)) continue;
|
|
964
|
-
const spliced = tryListSplice(root, path, node2, cStart, newInput, from, to, delta, this._fns, this._opts.build, !!this._opts.tolerant);
|
|
1156
|
+
const spliced = tryListSplice(root, path, node2, cStart, newInput, from, to, delta, rep, this._fns, this._opts.build, !!this._opts.tolerant);
|
|
965
1157
|
if (spliced) return this.wrapReuse(spliced, newInput);
|
|
966
1158
|
}
|
|
967
1159
|
}
|
|
@@ -977,7 +1169,7 @@ function triviaOf(entry, opts) {
|
|
|
977
1169
|
function unconsumedAfter(end, input, trivia2) {
|
|
978
1170
|
let pos = end;
|
|
979
1171
|
if (trivia2 && pos < input.length) {
|
|
980
|
-
const t = trivia2.parse(input, pos,
|
|
1172
|
+
const t = trivia2.parse(input, pos, createParseContext());
|
|
981
1173
|
if (t.ok && t.span.end > pos) pos = t.span.end;
|
|
982
1174
|
}
|
|
983
1175
|
return pos < input.length ? pos : null;
|