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
|
@@ -46,24 +46,26 @@ function annotateSpanFromLineContext(span, ctx) {
|
|
|
46
46
|
function cstCaptureActive(ctx) {
|
|
47
47
|
return ctx._cstBuf !== void 0 || ctx._cstLeaves !== void 0;
|
|
48
48
|
}
|
|
49
|
-
function pushCstChild(ctx, built,
|
|
49
|
+
function pushCstChild(ctx, built, rawEntry2) {
|
|
50
50
|
const b = ctx._cstBuf;
|
|
51
51
|
if (b) {
|
|
52
|
-
if (b.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
if (b.rawOnly !== true) {
|
|
53
|
+
if (b.ch) b.ch.push(built);
|
|
54
|
+
else if (b.single !== void 0) {
|
|
55
|
+
b.ch = [b.single, built];
|
|
56
|
+
b.single = void 0;
|
|
57
|
+
} else b.single = built;
|
|
58
|
+
}
|
|
59
|
+
if (b.raw) b.raw.push(rawEntry2);
|
|
58
60
|
else if (b.rawSingle !== void 0) {
|
|
59
|
-
b.raw = [b.rawSingle,
|
|
61
|
+
b.raw = [b.rawSingle, rawEntry2];
|
|
60
62
|
b.rawSingle = void 0;
|
|
61
|
-
} else b.rawSingle =
|
|
63
|
+
} else b.rawSingle = rawEntry2;
|
|
62
64
|
return;
|
|
63
65
|
}
|
|
64
66
|
if (ctx._cstChildren) ctx._cstChildren.push(built);
|
|
65
67
|
else if (ctx._cstLeaves) ctx._cstLeaves.push(built);
|
|
66
|
-
if (ctx._cstRawChildren) ctx._cstRawChildren.push(
|
|
68
|
+
if (ctx._cstRawChildren) ctx._cstRawChildren.push(rawEntry2);
|
|
67
69
|
}
|
|
68
70
|
|
|
69
71
|
// src/recovery/scan.ts
|
|
@@ -159,6 +161,45 @@ function captureError(ctx, error) {
|
|
|
159
161
|
}
|
|
160
162
|
var REC = { scan: recoverScan, at: matchesAt, or: orSentinel, sentinel: firstSetSentinel, capture: captureError };
|
|
161
163
|
|
|
164
|
+
// src/parse-context.ts
|
|
165
|
+
function createParseContext() {
|
|
166
|
+
return {
|
|
167
|
+
trivia: void 0,
|
|
168
|
+
scanSkip: void 0,
|
|
169
|
+
triviaKindLabels: void 0,
|
|
170
|
+
captureTrivia: void 0,
|
|
171
|
+
_triviaCaptureMask: void 0,
|
|
172
|
+
trackLines: false,
|
|
173
|
+
state: void 0,
|
|
174
|
+
build: void 0,
|
|
175
|
+
_errors: void 0,
|
|
176
|
+
_tolerant: void 0,
|
|
177
|
+
_sync: void 0,
|
|
178
|
+
_rec: void 0,
|
|
179
|
+
_fe: void 0,
|
|
180
|
+
_fx: void 0,
|
|
181
|
+
_fc: void 0,
|
|
182
|
+
_probe: void 0,
|
|
183
|
+
_cstChildren: void 0,
|
|
184
|
+
_cstLeaves: void 0,
|
|
185
|
+
_cstRawChildren: void 0,
|
|
186
|
+
_triviaLog: void 0,
|
|
187
|
+
_rootTriviaLog: void 0,
|
|
188
|
+
_rootTriviaKindIndex: void 0,
|
|
189
|
+
_rootTriviaStrictScopes: void 0,
|
|
190
|
+
_rootTriviaCapture: void 0,
|
|
191
|
+
_cstTriviaLog: void 0,
|
|
192
|
+
_fields: void 0,
|
|
193
|
+
_cstBuf: void 0,
|
|
194
|
+
_routed: void 0,
|
|
195
|
+
_lineStarts: void 0,
|
|
196
|
+
_lineIndex: void 0,
|
|
197
|
+
_lineScannedTo: void 0,
|
|
198
|
+
_grammarCoverage: void 0,
|
|
199
|
+
_grammarTrace: void 0
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
162
203
|
// src/cst/trivia-entries.ts
|
|
163
204
|
var EMPTY_INDICES = Object.freeze([]);
|
|
164
205
|
var EMPTY_GAPS = Object.freeze([]);
|
|
@@ -340,9 +381,30 @@ var REMOVED_RUN_RESULT_FIELDS = [
|
|
|
340
381
|
`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\`.`
|
|
341
382
|
]
|
|
342
383
|
];
|
|
343
|
-
|
|
384
|
+
var RunResultRecord = class {
|
|
385
|
+
constructor(ok, value, span, expected, errors, unconsumedFrom) {
|
|
386
|
+
this.ok = ok;
|
|
387
|
+
this.value = value;
|
|
388
|
+
this.span = span;
|
|
389
|
+
this.expected = expected;
|
|
390
|
+
this.errors = errors;
|
|
391
|
+
this.unconsumedFrom = unconsumedFrom;
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
var RunResultWithRootTrivia = class {
|
|
395
|
+
constructor(ok, value, span, expected, errors, rootTrivia, unconsumedFrom) {
|
|
396
|
+
this.ok = ok;
|
|
397
|
+
this.value = value;
|
|
398
|
+
this.span = span;
|
|
399
|
+
this.expected = expected;
|
|
400
|
+
this.errors = errors;
|
|
401
|
+
this.rootTrivia = rootTrivia;
|
|
402
|
+
this.unconsumedFrom = unconsumedFrom;
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
for (const proto of [RunResultRecord.prototype, RunResultWithRootTrivia.prototype]) {
|
|
344
406
|
for (const [name, detail] of REMOVED_RUN_RESULT_FIELDS) {
|
|
345
|
-
Object.defineProperty(
|
|
407
|
+
Object.defineProperty(proto, name, {
|
|
346
408
|
configurable: true,
|
|
347
409
|
enumerable: false,
|
|
348
410
|
get() {
|
|
@@ -352,9 +414,14 @@ function guardRemovedFields(result) {
|
|
|
352
414
|
}
|
|
353
415
|
});
|
|
354
416
|
}
|
|
355
|
-
return result;
|
|
356
417
|
}
|
|
357
418
|
var invoke = (r, input, pos, ctx) => typeof r === "function" ? r(input, pos, ctx) : r.parse(input, pos, ctx);
|
|
419
|
+
function ambientTriviaFromRunnable(r) {
|
|
420
|
+
if (!r) return void 0;
|
|
421
|
+
if (typeof r === "function") return r._meta?.grammarTrivia;
|
|
422
|
+
if (r._meta.isTrivia) return void 0;
|
|
423
|
+
return r._meta.grammarTrivia ?? (r._def.tag === "grammar" ? r._def.triviaParser : void 0);
|
|
424
|
+
}
|
|
358
425
|
function triviaKindLabelsFromRunnable(r) {
|
|
359
426
|
if (!r) return void 0;
|
|
360
427
|
if (typeof r === "function") return r._meta?.triviaKindLabels;
|
|
@@ -374,7 +441,23 @@ function makeSelectedRootLabelIndex(labels) {
|
|
|
374
441
|
}
|
|
375
442
|
return index;
|
|
376
443
|
}
|
|
377
|
-
function
|
|
444
|
+
function growSpanEnd(span, input, end) {
|
|
445
|
+
if (span.endLine === void 0 || span.endColumn === void 0) {
|
|
446
|
+
return { start: span.start, end };
|
|
447
|
+
}
|
|
448
|
+
let line = span.endLine;
|
|
449
|
+
let column = span.endColumn;
|
|
450
|
+
for (let i = span.end; i < end; i++) {
|
|
451
|
+
if (input.charCodeAt(i) === 10) {
|
|
452
|
+
line++;
|
|
453
|
+
column = 1;
|
|
454
|
+
} else {
|
|
455
|
+
column++;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
return { ...span, end, endLine: line, endColumn: column };
|
|
459
|
+
}
|
|
460
|
+
function runOnce(entry, input, options) {
|
|
378
461
|
if (typeof entry !== "function" && typeof entry?.parse !== "function") {
|
|
379
462
|
throw new TypeError(
|
|
380
463
|
`run(): start production is ${entry === null ? "null" : typeof entry}, not a rule \u2014 the requested grammar rule does not exist (check the rule name).`
|
|
@@ -385,8 +468,6 @@ function runOnce(entry, input, options, phase, profileState) {
|
|
|
385
468
|
const selectedRootLog = captureRootTrivia ? [] : void 0;
|
|
386
469
|
const selectedRootLabelIndex = captureRootTrivia ? makeSelectedRootLabelIndex(rootTriviaSelection) : void 0;
|
|
387
470
|
const errors = [];
|
|
388
|
-
const profile = profileState ?? (phase === void 0 ? void 0 : { phase, nodes: 0, childSlots: 0, rawSlots: 0, triviaSlots: 0, fieldSlots: 0, hostCalls: 0 });
|
|
389
|
-
const skipGlobalSinks = phase === "recognizer" || phase === "capture";
|
|
390
471
|
const grammarTrivia = typeof entry !== "function" ? entry._meta.grammarTrivia : void 0;
|
|
391
472
|
const grammarScanSkip = typeof entry !== "function" ? entry._meta.grammarScanSkip : void 0;
|
|
392
473
|
const triviaKindLabels = triviaKindLabelsFromRunnable(entry) ?? triviaKindLabelsFromRunnable(options.trivia);
|
|
@@ -411,62 +492,71 @@ function runOnce(entry, input, options, phase, profileState) {
|
|
|
411
492
|
options.build,
|
|
412
493
|
typeof entry === "function" && stamped[FUSED_HOST_ELIDED] === true
|
|
413
494
|
);
|
|
414
|
-
const ctx =
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
495
|
+
const ctx = createParseContext();
|
|
496
|
+
if (captureRootTrivia) {
|
|
497
|
+
ctx._rootTriviaLog = selectedRootLog;
|
|
498
|
+
ctx._rootTriviaKindIndex = selectedRootLabelIndex;
|
|
499
|
+
ctx._rootTriviaStrictScopes = true;
|
|
500
|
+
}
|
|
501
|
+
ctx._errors = errors;
|
|
502
|
+
ctx.build = options.build;
|
|
503
|
+
ctx.state = options.state;
|
|
504
|
+
if (grammarTrivia !== void 0) ctx.trivia = grammarTrivia;
|
|
505
|
+
if (triviaKindLabels) ctx.triviaKindLabels = triviaKindLabels;
|
|
506
|
+
if (grammarScanSkip !== void 0) ctx.scanSkip = grammarScanSkip;
|
|
507
|
+
if (options.triviaCaptureMask !== void 0) ctx._triviaCaptureMask = options.triviaCaptureMask;
|
|
508
|
+
if (options.tolerant) {
|
|
509
|
+
ctx._tolerant = true;
|
|
510
|
+
ctx._rec = REC;
|
|
511
|
+
}
|
|
512
|
+
if (options.instrumentation !== void 0) {
|
|
513
|
+
ctx._grammarCoverage = options.instrumentation._grammarCoverage;
|
|
514
|
+
ctx._grammarTrace = options.instrumentation._grammarTrace;
|
|
515
|
+
}
|
|
433
516
|
const r = invoke(entry, input, 0, ctx);
|
|
517
|
+
const value = r.ok ? r.value : void 0;
|
|
518
|
+
let span = r.span ?? { start: 0, end: 0 };
|
|
519
|
+
const expected = r.ok ? [] : r.expected ?? [];
|
|
434
520
|
let unconsumedFrom = null;
|
|
435
521
|
if (r.ok) {
|
|
436
|
-
let pos =
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
522
|
+
let pos = span.end;
|
|
523
|
+
const tail = options.trivia ?? ambientTriviaFromRunnable(entry);
|
|
524
|
+
if (tail !== void 0 && pos < input.length) {
|
|
525
|
+
const t = invoke(tail, input, pos, createParseContext());
|
|
526
|
+
if (t.ok && t.span.end > pos) {
|
|
527
|
+
span = growSpanEnd(span, input, t.span.end);
|
|
528
|
+
pos = t.span.end;
|
|
529
|
+
}
|
|
440
530
|
}
|
|
441
531
|
unconsumedFrom = pos < input.length ? pos : null;
|
|
442
532
|
}
|
|
443
|
-
return
|
|
444
|
-
|
|
445
|
-
value
|
|
446
|
-
span
|
|
447
|
-
expected
|
|
533
|
+
return selectedRootLog !== void 0 && selectedRootLog.length > 0 ? new RunResultWithRootTrivia(
|
|
534
|
+
r.ok,
|
|
535
|
+
value,
|
|
536
|
+
span,
|
|
537
|
+
expected,
|
|
448
538
|
errors,
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
}
|
|
455
|
-
} : {},
|
|
539
|
+
{
|
|
540
|
+
rows: selectedRootLog,
|
|
541
|
+
select: rootTriviaSelection,
|
|
542
|
+
index: buildRootTriviaIndex(selectedRootLog, rootTriviaSelection)
|
|
543
|
+
},
|
|
456
544
|
unconsumedFrom
|
|
457
|
-
|
|
545
|
+
) : new RunResultRecord(r.ok, value, span, expected, errors, unconsumedFrom);
|
|
458
546
|
}
|
|
459
547
|
function run(entry, input, options = {}) {
|
|
460
|
-
|
|
461
|
-
throw new TypeError(
|
|
462
|
-
"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."
|
|
463
|
-
);
|
|
548
|
+
return runOnce(entry, input, options);
|
|
464
549
|
}
|
|
465
550
|
|
|
466
551
|
// src/combinators/completions.ts
|
|
467
552
|
function completionsAt(target, input, offset, options = {}) {
|
|
468
553
|
const probe = { offset, best: null };
|
|
469
|
-
const ctx =
|
|
554
|
+
const ctx = createParseContext();
|
|
555
|
+
ctx._probe = probe;
|
|
556
|
+
if (options.tolerant) {
|
|
557
|
+
ctx._tolerant = true;
|
|
558
|
+
ctx._rec = REC;
|
|
559
|
+
}
|
|
470
560
|
const sliced = input.slice(0, offset);
|
|
471
561
|
const result = "parseWithContext" in target ? target.parseWithContext(sliced, ctx, 0) : target.parse(sliced, 0, ctx);
|
|
472
562
|
if (result.ok) return options.tolerant ? probe.best?.expected ?? [] : [];
|
|
@@ -479,36 +569,106 @@ function deeperFail(a, b) {
|
|
|
479
569
|
return a.span.start >= b.span.start ? a : b;
|
|
480
570
|
}
|
|
481
571
|
|
|
482
|
-
// src/
|
|
483
|
-
var WORD_RE_SRC = "-?[A-Za-z][A-Za-z0-9_-]*";
|
|
484
|
-
var WORDS_RE = new RegExp(`^${WORD_RE_SRC}(?:\\|${WORD_RE_SRC})*$`);
|
|
485
|
-
|
|
486
|
-
// src/compiler/scannable-run.ts
|
|
572
|
+
// src/regex/classes.ts
|
|
487
573
|
var META = new Set("()[]{}*+?|^$.".split(""));
|
|
488
|
-
var SELECTED_ROOT_OWNED_RANGE_PLACEHOLDER = Array.from(
|
|
489
|
-
{ length: SELECTED_ROOT_STRIDE - 3 },
|
|
490
|
-
() => "0"
|
|
491
|
-
).join(", ");
|
|
492
574
|
|
|
493
|
-
// src/
|
|
494
|
-
var
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
var
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
575
|
+
// src/table/ops.ts
|
|
576
|
+
var OP_LIT = 1;
|
|
577
|
+
var OP_RX = 2;
|
|
578
|
+
var OP_SEQ = 3;
|
|
579
|
+
var OP_SEQV = 4;
|
|
580
|
+
var OP_CHOICE = 5;
|
|
581
|
+
var OP_REP = 6;
|
|
582
|
+
var OP_REPV = 7;
|
|
583
|
+
var OP_OPT = 8;
|
|
584
|
+
var OP_XFORM = 9;
|
|
585
|
+
var OP_NODE = 10;
|
|
586
|
+
var OP_RULE = 11;
|
|
587
|
+
var OP_GATE = 12;
|
|
588
|
+
var OP_NOT = 13;
|
|
589
|
+
var OP_PEEK = 14;
|
|
590
|
+
var OP_LEAF = 15;
|
|
591
|
+
var OP_EMPTY = 16;
|
|
592
|
+
var OP_LIT_TRACK = 17;
|
|
593
|
+
var OP_RX_TRACK = 18;
|
|
594
|
+
var OP_NODE_TRACK = 19;
|
|
595
|
+
var OP_SCOPE = 20;
|
|
596
|
+
var OP_EXPECT = 21;
|
|
597
|
+
var OP_SEQX = 22;
|
|
598
|
+
var OP_SCAN = 23;
|
|
599
|
+
var OP_FIELD = 24;
|
|
600
|
+
var OP_LIT_CI = 27;
|
|
601
|
+
var OP_LIT_CI_TRACK = 28;
|
|
602
|
+
var OP_TOKEN = 29;
|
|
603
|
+
var OP_SCOPE_CAP = 30;
|
|
604
|
+
var OP_WITHCTX = 31;
|
|
605
|
+
var OP_GUARD = 32;
|
|
606
|
+
var OP_ADJ = 33;
|
|
607
|
+
var OP_GREEDY = 34;
|
|
608
|
+
var OP_REJECT = 35;
|
|
609
|
+
var OP_ARMGATE = 36;
|
|
610
|
+
var OP_LIVE = 37;
|
|
611
|
+
var OP_ATTEMPT = 38;
|
|
612
|
+
var OP_LABEL = 39;
|
|
613
|
+
var OP_COV = 40;
|
|
614
|
+
var OP_SCOPE_PLAIN = 41;
|
|
615
|
+
var OP_DISPATCH = 25;
|
|
616
|
+
var OP_ROUTED = 26;
|
|
617
|
+
var OP_NAMES = {
|
|
618
|
+
[OP_LIT]: "LIT",
|
|
619
|
+
[OP_RX]: "RX",
|
|
620
|
+
[OP_SEQ]: "SEQ",
|
|
621
|
+
[OP_SEQV]: "SEQV",
|
|
622
|
+
[OP_CHOICE]: "CHOICE",
|
|
623
|
+
[OP_REP]: "REP",
|
|
624
|
+
[OP_REPV]: "REPV",
|
|
625
|
+
[OP_OPT]: "OPT",
|
|
626
|
+
[OP_XFORM]: "XFORM",
|
|
627
|
+
[OP_NODE]: "NODE",
|
|
628
|
+
[OP_RULE]: "RULE",
|
|
629
|
+
[OP_GATE]: "GATE",
|
|
630
|
+
[OP_NOT]: "NOT",
|
|
631
|
+
[OP_PEEK]: "PEEK",
|
|
632
|
+
[OP_LEAF]: "LEAF",
|
|
633
|
+
[OP_EMPTY]: "EMPTY",
|
|
634
|
+
[OP_LIT_TRACK]: "LIT_TRACK",
|
|
635
|
+
[OP_RX_TRACK]: "RX_TRACK",
|
|
636
|
+
[OP_NODE_TRACK]: "NODE_TRACK",
|
|
637
|
+
[OP_SCOPE]: "SCOPE",
|
|
638
|
+
[OP_EXPECT]: "EXPECT",
|
|
639
|
+
[OP_SEQX]: "SEQX",
|
|
640
|
+
[OP_SCAN]: "SCAN",
|
|
641
|
+
[OP_FIELD]: "FIELD",
|
|
642
|
+
[OP_LIT_CI]: "LIT_CI",
|
|
643
|
+
[OP_LIT_CI_TRACK]: "LIT_CI_TRACK",
|
|
644
|
+
[OP_DISPATCH]: "DISPATCH",
|
|
645
|
+
[OP_ROUTED]: "ROUTED",
|
|
646
|
+
[OP_TOKEN]: "TOKEN",
|
|
647
|
+
[OP_SCOPE_CAP]: "SCOPE_CAP",
|
|
648
|
+
[OP_WITHCTX]: "WITHCTX",
|
|
649
|
+
[OP_GUARD]: "GUARD",
|
|
650
|
+
[OP_ADJ]: "ADJ",
|
|
651
|
+
[OP_GREEDY]: "GREEDY",
|
|
652
|
+
[OP_REJECT]: "REJECT",
|
|
653
|
+
[OP_ARMGATE]: "ARMGATE",
|
|
654
|
+
[OP_LIVE]: "LIVE",
|
|
655
|
+
[OP_ATTEMPT]: "ATTEMPT",
|
|
656
|
+
[OP_LABEL]: "LABEL",
|
|
657
|
+
[OP_COV]: "COV",
|
|
658
|
+
[OP_SCOPE_PLAIN]: "SCOPE_PLAIN"
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
// src/table/scan-shapes.ts
|
|
662
|
+
var META2 = new Set("()[]{}*+?|^$.".split(""));
|
|
663
|
+
|
|
664
|
+
// src/table/assemble.ts
|
|
665
|
+
var EMIT_ENABLED = globalThis.process?.env?.PM_TABLE_EMIT !== "0";
|
|
666
|
+
var EMPTY_TL = Object.freeze([]);
|
|
667
|
+
var EMPTY_SENTS = Object.freeze([]);
|
|
505
668
|
|
|
506
|
-
// src/
|
|
507
|
-
var
|
|
508
|
-
var
|
|
509
|
-
var MK_BUILD_RE = new RegExp(
|
|
510
|
-
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*$`
|
|
511
|
-
);
|
|
669
|
+
// src/analysis/duplication.ts
|
|
670
|
+
var WORD_RE_SRC = "-?[A-Za-z][A-Za-z0-9_-]*";
|
|
671
|
+
var WORDS_RE = new RegExp(`^${WORD_RE_SRC}(?:\\|${WORD_RE_SRC})*$`);
|
|
512
672
|
|
|
513
673
|
// src/compiler/linker.ts
|
|
514
674
|
function normalizeCstCollapse(collapse) {
|
|
@@ -582,14 +742,48 @@ function asRuleFn(entry) {
|
|
|
582
742
|
function defOf(entry) {
|
|
583
743
|
return typeof entry === "object" && entry !== null && "_def" in entry ? entry._def : void 0;
|
|
584
744
|
}
|
|
745
|
+
function literalTextOf(parser2, depth = 0) {
|
|
746
|
+
const def = defOf(parser2);
|
|
747
|
+
if (!def || depth > 24) return null;
|
|
748
|
+
const d = def;
|
|
749
|
+
switch (d.tag) {
|
|
750
|
+
case "literal":
|
|
751
|
+
return d.caseInsensitive ? null : d.value;
|
|
752
|
+
case "lazy": {
|
|
753
|
+
const thunk = d.thunk;
|
|
754
|
+
try {
|
|
755
|
+
return typeof thunk === "function" ? literalTextOf(thunk(), depth + 1) : null;
|
|
756
|
+
} catch {
|
|
757
|
+
return null;
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
case "node":
|
|
761
|
+
case "transform":
|
|
762
|
+
case "attempt":
|
|
763
|
+
case "token":
|
|
764
|
+
case "leaf":
|
|
765
|
+
case "label":
|
|
766
|
+
case "field":
|
|
767
|
+
case "expect":
|
|
768
|
+
case "withCtx":
|
|
769
|
+
case "grammar":
|
|
770
|
+
return literalTextOf(d.parser, depth + 1);
|
|
771
|
+
default:
|
|
772
|
+
return null;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
585
775
|
function producesRepetition(def, depth = 0) {
|
|
586
|
-
if (!def || depth > 24) return
|
|
776
|
+
if (!def || depth > 24) return null;
|
|
587
777
|
const d = def;
|
|
588
778
|
switch (d.tag) {
|
|
589
|
-
case "sepBy":
|
|
779
|
+
case "sepBy": {
|
|
780
|
+
if (d.keepSeparators) return null;
|
|
781
|
+
const text = literalTextOf(d.separator);
|
|
782
|
+
return text === null || text.length === 0 ? null : { kind: "sep", text };
|
|
783
|
+
}
|
|
590
784
|
case "many":
|
|
591
785
|
case "oneOrMore":
|
|
592
|
-
return
|
|
786
|
+
return { kind: "bare" };
|
|
593
787
|
// Rule entries and `ref`s wrap their body in a `lazy` thunk — resolve it. The
|
|
594
788
|
// `depth` cap bounds any self-referential cycle (a repetition, if present, is
|
|
595
789
|
// found shallowly before recursion goes deep).
|
|
@@ -599,7 +793,7 @@ function producesRepetition(def, depth = 0) {
|
|
|
599
793
|
try {
|
|
600
794
|
inner = typeof thunk === "function" ? thunk() : void 0;
|
|
601
795
|
} catch {
|
|
602
|
-
return
|
|
796
|
+
return null;
|
|
603
797
|
}
|
|
604
798
|
return producesRepetition(inner?._def, depth + 1);
|
|
605
799
|
}
|
|
@@ -616,13 +810,16 @@ function producesRepetition(def, depth = 0) {
|
|
|
616
810
|
case "grammar":
|
|
617
811
|
case "optional":
|
|
618
812
|
return producesRepetition(defOf(d.parser), depth + 1);
|
|
619
|
-
case "skip":
|
|
620
|
-
return producesRepetition(defOf(d.main), depth + 1);
|
|
621
813
|
// A bracketed/anchored list is a sequence whose element run is a repetition.
|
|
622
|
-
case "sequence":
|
|
623
|
-
|
|
814
|
+
case "sequence": {
|
|
815
|
+
for (const p of d.parsers) {
|
|
816
|
+
const rep = producesRepetition(defOf(p), depth + 1);
|
|
817
|
+
if (rep) return rep;
|
|
818
|
+
}
|
|
819
|
+
return null;
|
|
820
|
+
}
|
|
624
821
|
default:
|
|
625
|
-
return
|
|
822
|
+
return null;
|
|
626
823
|
}
|
|
627
824
|
}
|
|
628
825
|
var REENTRY_MAX_SPAN_FRACTION = 0.5;
|
|
@@ -684,17 +881,18 @@ function graftRelative(root, path, newNode, delta) {
|
|
|
684
881
|
children: newChildren
|
|
685
882
|
};
|
|
686
883
|
}
|
|
687
|
-
function parseMiddle(input, reStart, reEnd, cStart, ruleFn, separator, build, tolerant) {
|
|
884
|
+
function parseMiddle(input, reStart, reEnd, cStart, ruleFn, separator, startsAtElement, build, tolerant) {
|
|
688
885
|
const ctx = mkCtx(null, build, tolerant);
|
|
689
886
|
const out = [];
|
|
690
887
|
let pos = reStart;
|
|
691
888
|
let guard = 0;
|
|
889
|
+
let expectElement = separator === null ? true : startsAtElement;
|
|
692
890
|
while (pos < reEnd) {
|
|
693
891
|
if (++guard > reEnd - reStart + 2) return null;
|
|
694
|
-
if (separator
|
|
892
|
+
if (separator !== null && !expectElement) {
|
|
695
893
|
if (pos + separator.length > reEnd || !input.startsWith(separator, pos)) return null;
|
|
696
|
-
out.push({ _tag: "leaf", value: separator, span: { start: pos - cStart, end: pos + separator.length - cStart } });
|
|
697
894
|
pos += separator.length;
|
|
895
|
+
expectElement = true;
|
|
698
896
|
continue;
|
|
699
897
|
}
|
|
700
898
|
let r;
|
|
@@ -706,15 +904,15 @@ function parseMiddle(input, reStart, reEnd, cStart, ruleFn, separator, build, to
|
|
|
706
904
|
if (!r.ok || r.span.end <= pos || r.span.end > reEnd) return null;
|
|
707
905
|
out.push(relativizeCST(r.value, cStart));
|
|
708
906
|
pos = r.span.end;
|
|
907
|
+
if (separator !== null) expectElement = false;
|
|
709
908
|
}
|
|
710
|
-
return pos === reEnd ? out : null;
|
|
909
|
+
return pos === reEnd && expectElement ? out : null;
|
|
711
910
|
}
|
|
712
|
-
function tryListSplice(root, path, C, cStart, newInput, from, to, delta, registry, build, tolerant) {
|
|
911
|
+
function tryListSplice(root, path, C, cStart, newInput, from, to, delta, rep, registry, build, tolerant) {
|
|
713
912
|
const kids = C.children;
|
|
714
913
|
if (kids.length === 0) return null;
|
|
715
914
|
let h = 0;
|
|
716
915
|
while (h < kids.length && cStart + kids[h].span.end <= from) h++;
|
|
717
|
-
while (h > 0 && kids[h - 1]._tag === "node") h--;
|
|
718
916
|
let t = kids.length;
|
|
719
917
|
while (t > h && cStart + kids[t - 1].span.start >= to) t--;
|
|
720
918
|
while (t < kids.length && kids[t]._tag !== "node") t++;
|
|
@@ -733,16 +931,7 @@ function tryListSplice(root, path, C, cStart, newInput, from, to, delta, registr
|
|
|
733
931
|
if (elemType === void 0 || elemCount < 2) return null;
|
|
734
932
|
const ruleFn = registry[elemType];
|
|
735
933
|
if (!ruleFn) return null;
|
|
736
|
-
|
|
737
|
-
for (let i = 1; i < kids.length - 1; i++) {
|
|
738
|
-
if (kids[i - 1]._tag === "node" && kids[i + 1]._tag === "node") {
|
|
739
|
-
if (kids[i]._tag !== "leaf") return null;
|
|
740
|
-
const sep = kids[i].value ?? null;
|
|
741
|
-
if (separator === null) separator = sep;
|
|
742
|
-
else if (sep !== separator) return null;
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
if (separator === null) return null;
|
|
934
|
+
const separator = rep.kind === "sep" ? rep.text : null;
|
|
746
935
|
const first = kids[0];
|
|
747
936
|
const last = kids[kids.length - 1];
|
|
748
937
|
if (first._tag === "leaf" && first.value !== separator && from < cStart + first.span.end) return null;
|
|
@@ -750,17 +939,14 @@ function tryListSplice(root, path, C, cStart, newInput, from, to, delta, registr
|
|
|
750
939
|
const reStart = h > 0 ? cStart + kids[h - 1].span.end : cStart;
|
|
751
940
|
const reEnd = cStart + kids[t].span.start + delta;
|
|
752
941
|
if (reEnd < reStart) return null;
|
|
753
|
-
const
|
|
942
|
+
const startsAtElement = !(h > 0 && kids[h - 1]._tag === "node");
|
|
943
|
+
const middle = parseMiddle(newInput, reStart, reEnd, cStart, ruleFn, separator, startsAtElement, build, tolerant);
|
|
754
944
|
if (!middle) return null;
|
|
755
|
-
if (middle.length > 0) {
|
|
756
|
-
const last2 = middle[middle.length - 1];
|
|
757
|
-
if (!(last2._tag === "leaf" && last2.value === separator)) return null;
|
|
758
|
-
}
|
|
759
945
|
if (reEnd < newInput.length) {
|
|
760
946
|
for (const sentinel of [" ", "\uFFFF"]) {
|
|
761
947
|
if (newInput[reEnd] === sentinel) continue;
|
|
762
948
|
const probed = newInput.slice(0, reEnd) + sentinel.repeat(newInput.length - reEnd);
|
|
763
|
-
const probe = parseMiddle(probed, reStart, reEnd, cStart, ruleFn, separator, build, tolerant);
|
|
949
|
+
const probe = parseMiddle(probed, reStart, reEnd, cStart, ruleFn, separator, startsAtElement, build, tolerant);
|
|
764
950
|
if (!probe || probe.length !== middle.length) return null;
|
|
765
951
|
for (let i = 0; i < middle.length; i++) if (!structurallyEqual(probe[i], middle[i])) return null;
|
|
766
952
|
}
|
|
@@ -824,7 +1010,11 @@ var ParseDocImpl = class _ParseDocImpl {
|
|
|
824
1010
|
_registry;
|
|
825
1011
|
/** Registry entries normalized to callable parse functions (memoized once). */
|
|
826
1012
|
_fns;
|
|
827
|
-
/**
|
|
1013
|
+
/**
|
|
1014
|
+
* Rule names the grammar proves are genuine repetitions — the ONLY splice-safe
|
|
1015
|
+
* types — mapped to the repetition shape (and, for a `sepBy`, the separator text
|
|
1016
|
+
* its construction pins). A rule whose separator isn't recoverable is absent.
|
|
1017
|
+
*/
|
|
828
1018
|
_reps;
|
|
829
1019
|
_rootRule;
|
|
830
1020
|
_opts;
|
|
@@ -845,10 +1035,11 @@ var ParseDocImpl = class _ParseDocImpl {
|
|
|
845
1035
|
constructor(registry, rootRule, opts, trees, errors, unconsumedFrom, input) {
|
|
846
1036
|
this._registry = registry;
|
|
847
1037
|
this._fns = {};
|
|
848
|
-
this._reps = /* @__PURE__ */ new
|
|
1038
|
+
this._reps = /* @__PURE__ */ new Map();
|
|
849
1039
|
for (const [name, entry] of Object.entries(registry)) {
|
|
850
1040
|
this._fns[name] = asRuleFn(entry);
|
|
851
|
-
|
|
1041
|
+
const rep = producesRepetition(defOf(entry));
|
|
1042
|
+
if (rep) this._reps.set(name, rep);
|
|
852
1043
|
}
|
|
853
1044
|
this._rootRule = rootRule;
|
|
854
1045
|
this._opts = opts;
|
|
@@ -932,10 +1123,11 @@ var ParseDocImpl = class _ParseDocImpl {
|
|
|
932
1123
|
if (this._opts.structuralReuse && delta !== 0 && !this._opts.rebuild) {
|
|
933
1124
|
const spliceCandidates = [...candidates, { node: root, path: [] }];
|
|
934
1125
|
for (const { node: node2, path } of spliceCandidates) {
|
|
935
|
-
|
|
1126
|
+
const rep = this._reps.get(node2.type);
|
|
1127
|
+
if (!rep) continue;
|
|
936
1128
|
const { start: cStart, end: cEnd } = absoluteSpanCST(root, path);
|
|
937
1129
|
if (!(cStart <= from && to <= cEnd)) continue;
|
|
938
|
-
const spliced = tryListSplice(root, path, node2, cStart, newInput, from, to, delta, this._fns, this._opts.build, !!this._opts.tolerant);
|
|
1130
|
+
const spliced = tryListSplice(root, path, node2, cStart, newInput, from, to, delta, rep, this._fns, this._opts.build, !!this._opts.tolerant);
|
|
939
1131
|
if (spliced) return this.wrapReuse(spliced, newInput);
|
|
940
1132
|
}
|
|
941
1133
|
}
|
|
@@ -951,7 +1143,7 @@ function triviaOf(entry, opts) {
|
|
|
951
1143
|
function unconsumedAfter(end, input, trivia2) {
|
|
952
1144
|
let pos = end;
|
|
953
1145
|
if (trivia2 && pos < input.length) {
|
|
954
|
-
const t = trivia2.parse(input, pos,
|
|
1146
|
+
const t = trivia2.parse(input, pos, createParseContext());
|
|
955
1147
|
if (t.ok && t.span.end > pos) pos = t.span.end;
|
|
956
1148
|
}
|
|
957
1149
|
return pos < input.length ? pos : null;
|