parseman 0.45.0 → 0.47.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.
- package/README.md +8 -3
- package/dist/analysis/choice-cost-gate.d.ts +158 -0
- package/dist/analysis/choice-cost-gate.d.ts.map +1 -0
- package/dist/analysis/choice-cost-render.d.ts +96 -0
- package/dist/analysis/choice-cost-render.d.ts.map +1 -0
- package/dist/analysis/choice-cost.d.ts +383 -0
- package/dist/analysis/choice-cost.d.ts.map +1 -0
- package/dist/analysis/commitment.d.ts +131 -0
- package/dist/analysis/commitment.d.ts.map +1 -0
- package/dist/analysis/corpus.d.ts +73 -0
- package/dist/analysis/corpus.d.ts.map +1 -0
- package/dist/analysis/diagnose-render.d.ts +65 -0
- package/dist/analysis/diagnose-render.d.ts.map +1 -0
- package/dist/analysis/diagnose.d.ts +15 -0
- package/dist/analysis/diagnose.d.ts.map +1 -1
- package/dist/analysis/diagnostics.cjs +13736 -0
- package/dist/analysis/diagnostics.cjs.map +6 -0
- package/dist/analysis/diagnostics.d.ts +27 -0
- package/dist/analysis/diagnostics.d.ts.map +1 -0
- package/dist/analysis/diagnostics.js +13713 -0
- package/dist/analysis/diagnostics.js.map +6 -0
- package/dist/analysis/duplication.d.ts.map +1 -1
- package/dist/analysis/fix-render.d.ts +43 -0
- package/dist/analysis/fix-render.d.ts.map +1 -0
- package/dist/analysis/fix.d.ts +172 -0
- package/dist/analysis/fix.d.ts.map +1 -0
- 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 +47 -2
- package/dist/analysis/gating.d.ts.map +1 -1
- package/dist/analysis/rebuild.d.ts +61 -0
- package/dist/analysis/rebuild.d.ts.map +1 -0
- package/dist/analysis/terminal.d.ts +145 -0
- package/dist/analysis/terminal.d.ts.map +1 -0
- package/dist/cli/index.cjs +14837 -0
- package/dist/cli/index.cjs.map +6 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +14814 -0
- package/dist/cli/index.js.map +6 -0
- 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 +40 -1
- package/dist/combinators/trivia-skip.d.ts.map +1 -1
- package/dist/combinators/withCtx.d.ts.map +1 -1
- package/dist/compiler/build-arity.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 +79 -47
- 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 +10499 -7478
- package/dist/index.cjs.map +3 -4
- package/dist/index.d.ts +24 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10499 -7478
- package/dist/index.js.map +3 -4
- package/dist/language-service/index.cjs +311 -121
- package/dist/language-service/index.cjs.map +3 -4
- package/dist/language-service/index.js +311 -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 +41 -2
- package/dist/plugin/evaluator.d.ts.map +1 -1
- package/dist/plugin/free-identifiers.d.ts +23 -0
- package/dist/plugin/free-identifiers.d.ts.map +1 -0
- package/dist/plugin/index.cjs +11381 -9442
- package/dist/plugin/index.cjs.map +3 -4
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +11381 -9442
- package/dist/plugin/index.js.map +3 -4
- package/dist/plugin/reducer-resolver.d.ts +17 -1
- package/dist/plugin/reducer-resolver.d.ts.map +1 -1
- 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 +2898 -1622
- package/dist/spec/index.cjs.map +3 -4
- package/dist/spec/index.js +2898 -1622
- 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 +11375 -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 +11352 -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 +446 -0
- package/dist/table/ops.d.ts.map +1 -0
- package/dist/table/program.d.ts +493 -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 +41 -3
- 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 +322 -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 +221 -0
- package/src/combinators/token.ts +120 -0
- package/src/combinators/trivia-boundary.ts +48 -0
- package/src/combinators/trivia-skip.ts +821 -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 +2994 -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 +1766 -0
- package/src/table/emit.ts +418 -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 +1672 -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 +459 -0
- package/src/table/program.ts +855 -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/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,104 @@ 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_DISPATCH = 25;
|
|
641
|
+
var OP_ROUTED = 26;
|
|
642
|
+
var OP_NAMES = {
|
|
643
|
+
[OP_LIT]: "LIT",
|
|
644
|
+
[OP_RX]: "RX",
|
|
645
|
+
[OP_SEQ]: "SEQ",
|
|
646
|
+
[OP_SEQV]: "SEQV",
|
|
647
|
+
[OP_CHOICE]: "CHOICE",
|
|
648
|
+
[OP_REP]: "REP",
|
|
649
|
+
[OP_REPV]: "REPV",
|
|
650
|
+
[OP_OPT]: "OPT",
|
|
651
|
+
[OP_XFORM]: "XFORM",
|
|
652
|
+
[OP_NODE]: "NODE",
|
|
653
|
+
[OP_RULE]: "RULE",
|
|
654
|
+
[OP_GATE]: "GATE",
|
|
655
|
+
[OP_NOT]: "NOT",
|
|
656
|
+
[OP_PEEK]: "PEEK",
|
|
657
|
+
[OP_LEAF]: "LEAF",
|
|
658
|
+
[OP_EMPTY]: "EMPTY",
|
|
659
|
+
[OP_LIT_TRACK]: "LIT_TRACK",
|
|
660
|
+
[OP_RX_TRACK]: "RX_TRACK",
|
|
661
|
+
[OP_NODE_TRACK]: "NODE_TRACK",
|
|
662
|
+
[OP_SCOPE]: "SCOPE",
|
|
663
|
+
[OP_EXPECT]: "EXPECT",
|
|
664
|
+
[OP_SEQX]: "SEQX",
|
|
665
|
+
[OP_SCAN]: "SCAN",
|
|
666
|
+
[OP_FIELD]: "FIELD",
|
|
667
|
+
[OP_LIT_CI]: "LIT_CI",
|
|
668
|
+
[OP_LIT_CI_TRACK]: "LIT_CI_TRACK",
|
|
669
|
+
[OP_DISPATCH]: "DISPATCH",
|
|
670
|
+
[OP_ROUTED]: "ROUTED",
|
|
671
|
+
[OP_TOKEN]: "TOKEN",
|
|
672
|
+
[OP_SCOPE_CAP]: "SCOPE_CAP",
|
|
673
|
+
[OP_WITHCTX]: "WITHCTX",
|
|
674
|
+
[OP_GUARD]: "GUARD",
|
|
675
|
+
[OP_ADJ]: "ADJ",
|
|
676
|
+
[OP_GREEDY]: "GREEDY",
|
|
677
|
+
[OP_REJECT]: "REJECT",
|
|
678
|
+
[OP_ARMGATE]: "ARMGATE",
|
|
679
|
+
[OP_LIVE]: "LIVE",
|
|
680
|
+
[OP_ATTEMPT]: "ATTEMPT",
|
|
681
|
+
[OP_LABEL]: "LABEL",
|
|
682
|
+
[OP_COV]: "COV"
|
|
683
|
+
};
|
|
684
|
+
|
|
685
|
+
// src/table/scan-shapes.ts
|
|
686
|
+
var META2 = new Set("()[]{}*+?|^$.".split(""));
|
|
687
|
+
|
|
688
|
+
// src/table/assemble.ts
|
|
689
|
+
var EMIT_ENABLED = globalThis.process?.env?.PM_TABLE_EMIT !== "0";
|
|
690
|
+
var EMPTY_TL = Object.freeze([]);
|
|
691
|
+
var EMPTY_SENTS = Object.freeze([]);
|
|
531
692
|
|
|
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
|
-
);
|
|
693
|
+
// src/analysis/duplication.ts
|
|
694
|
+
var WORD_RE_SRC = "-?[A-Za-z][A-Za-z0-9_-]*";
|
|
695
|
+
var WORDS_RE = new RegExp(`^${WORD_RE_SRC}(?:\\|${WORD_RE_SRC})*$`);
|
|
538
696
|
|
|
539
697
|
// src/compiler/linker.ts
|
|
540
698
|
function normalizeCstCollapse(collapse) {
|
|
@@ -608,14 +766,48 @@ function asRuleFn(entry) {
|
|
|
608
766
|
function defOf(entry) {
|
|
609
767
|
return typeof entry === "object" && entry !== null && "_def" in entry ? entry._def : void 0;
|
|
610
768
|
}
|
|
769
|
+
function literalTextOf(parser2, depth = 0) {
|
|
770
|
+
const def = defOf(parser2);
|
|
771
|
+
if (!def || depth > 24) return null;
|
|
772
|
+
const d = def;
|
|
773
|
+
switch (d.tag) {
|
|
774
|
+
case "literal":
|
|
775
|
+
return d.caseInsensitive ? null : d.value;
|
|
776
|
+
case "lazy": {
|
|
777
|
+
const thunk = d.thunk;
|
|
778
|
+
try {
|
|
779
|
+
return typeof thunk === "function" ? literalTextOf(thunk(), depth + 1) : null;
|
|
780
|
+
} catch {
|
|
781
|
+
return null;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
case "node":
|
|
785
|
+
case "transform":
|
|
786
|
+
case "attempt":
|
|
787
|
+
case "token":
|
|
788
|
+
case "leaf":
|
|
789
|
+
case "label":
|
|
790
|
+
case "field":
|
|
791
|
+
case "expect":
|
|
792
|
+
case "withCtx":
|
|
793
|
+
case "grammar":
|
|
794
|
+
return literalTextOf(d.parser, depth + 1);
|
|
795
|
+
default:
|
|
796
|
+
return null;
|
|
797
|
+
}
|
|
798
|
+
}
|
|
611
799
|
function producesRepetition(def, depth = 0) {
|
|
612
|
-
if (!def || depth > 24) return
|
|
800
|
+
if (!def || depth > 24) return null;
|
|
613
801
|
const d = def;
|
|
614
802
|
switch (d.tag) {
|
|
615
|
-
case "sepBy":
|
|
803
|
+
case "sepBy": {
|
|
804
|
+
if (d.keepSeparators) return null;
|
|
805
|
+
const text = literalTextOf(d.separator);
|
|
806
|
+
return text === null || text.length === 0 ? null : { kind: "sep", text };
|
|
807
|
+
}
|
|
616
808
|
case "many":
|
|
617
809
|
case "oneOrMore":
|
|
618
|
-
return
|
|
810
|
+
return { kind: "bare" };
|
|
619
811
|
// Rule entries and `ref`s wrap their body in a `lazy` thunk — resolve it. The
|
|
620
812
|
// `depth` cap bounds any self-referential cycle (a repetition, if present, is
|
|
621
813
|
// found shallowly before recursion goes deep).
|
|
@@ -625,7 +817,7 @@ function producesRepetition(def, depth = 0) {
|
|
|
625
817
|
try {
|
|
626
818
|
inner = typeof thunk === "function" ? thunk() : void 0;
|
|
627
819
|
} catch {
|
|
628
|
-
return
|
|
820
|
+
return null;
|
|
629
821
|
}
|
|
630
822
|
return producesRepetition(inner?._def, depth + 1);
|
|
631
823
|
}
|
|
@@ -642,13 +834,16 @@ function producesRepetition(def, depth = 0) {
|
|
|
642
834
|
case "grammar":
|
|
643
835
|
case "optional":
|
|
644
836
|
return producesRepetition(defOf(d.parser), depth + 1);
|
|
645
|
-
case "skip":
|
|
646
|
-
return producesRepetition(defOf(d.main), depth + 1);
|
|
647
837
|
// A bracketed/anchored list is a sequence whose element run is a repetition.
|
|
648
|
-
case "sequence":
|
|
649
|
-
|
|
838
|
+
case "sequence": {
|
|
839
|
+
for (const p of d.parsers) {
|
|
840
|
+
const rep = producesRepetition(defOf(p), depth + 1);
|
|
841
|
+
if (rep) return rep;
|
|
842
|
+
}
|
|
843
|
+
return null;
|
|
844
|
+
}
|
|
650
845
|
default:
|
|
651
|
-
return
|
|
846
|
+
return null;
|
|
652
847
|
}
|
|
653
848
|
}
|
|
654
849
|
var REENTRY_MAX_SPAN_FRACTION = 0.5;
|
|
@@ -710,17 +905,18 @@ function graftRelative(root, path, newNode, delta) {
|
|
|
710
905
|
children: newChildren
|
|
711
906
|
};
|
|
712
907
|
}
|
|
713
|
-
function parseMiddle(input, reStart, reEnd, cStart, ruleFn, separator, build, tolerant) {
|
|
908
|
+
function parseMiddle(input, reStart, reEnd, cStart, ruleFn, separator, startsAtElement, build, tolerant) {
|
|
714
909
|
const ctx = mkCtx(null, build, tolerant);
|
|
715
910
|
const out = [];
|
|
716
911
|
let pos = reStart;
|
|
717
912
|
let guard = 0;
|
|
913
|
+
let expectElement = separator === null ? true : startsAtElement;
|
|
718
914
|
while (pos < reEnd) {
|
|
719
915
|
if (++guard > reEnd - reStart + 2) return null;
|
|
720
|
-
if (separator
|
|
916
|
+
if (separator !== null && !expectElement) {
|
|
721
917
|
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
918
|
pos += separator.length;
|
|
919
|
+
expectElement = true;
|
|
724
920
|
continue;
|
|
725
921
|
}
|
|
726
922
|
let r;
|
|
@@ -732,15 +928,15 @@ function parseMiddle(input, reStart, reEnd, cStart, ruleFn, separator, build, to
|
|
|
732
928
|
if (!r.ok || r.span.end <= pos || r.span.end > reEnd) return null;
|
|
733
929
|
out.push(relativizeCST(r.value, cStart));
|
|
734
930
|
pos = r.span.end;
|
|
931
|
+
if (separator !== null) expectElement = false;
|
|
735
932
|
}
|
|
736
|
-
return pos === reEnd ? out : null;
|
|
933
|
+
return pos === reEnd && expectElement ? out : null;
|
|
737
934
|
}
|
|
738
|
-
function tryListSplice(root, path, C, cStart, newInput, from, to, delta, registry, build, tolerant) {
|
|
935
|
+
function tryListSplice(root, path, C, cStart, newInput, from, to, delta, rep, registry, build, tolerant) {
|
|
739
936
|
const kids = C.children;
|
|
740
937
|
if (kids.length === 0) return null;
|
|
741
938
|
let h = 0;
|
|
742
939
|
while (h < kids.length && cStart + kids[h].span.end <= from) h++;
|
|
743
|
-
while (h > 0 && kids[h - 1]._tag === "node") h--;
|
|
744
940
|
let t = kids.length;
|
|
745
941
|
while (t > h && cStart + kids[t - 1].span.start >= to) t--;
|
|
746
942
|
while (t < kids.length && kids[t]._tag !== "node") t++;
|
|
@@ -759,16 +955,7 @@ function tryListSplice(root, path, C, cStart, newInput, from, to, delta, registr
|
|
|
759
955
|
if (elemType === void 0 || elemCount < 2) return null;
|
|
760
956
|
const ruleFn = registry[elemType];
|
|
761
957
|
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;
|
|
958
|
+
const separator = rep.kind === "sep" ? rep.text : null;
|
|
772
959
|
const first = kids[0];
|
|
773
960
|
const last = kids[kids.length - 1];
|
|
774
961
|
if (first._tag === "leaf" && first.value !== separator && from < cStart + first.span.end) return null;
|
|
@@ -776,17 +963,14 @@ function tryListSplice(root, path, C, cStart, newInput, from, to, delta, registr
|
|
|
776
963
|
const reStart = h > 0 ? cStart + kids[h - 1].span.end : cStart;
|
|
777
964
|
const reEnd = cStart + kids[t].span.start + delta;
|
|
778
965
|
if (reEnd < reStart) return null;
|
|
779
|
-
const
|
|
966
|
+
const startsAtElement = !(h > 0 && kids[h - 1]._tag === "node");
|
|
967
|
+
const middle = parseMiddle(newInput, reStart, reEnd, cStart, ruleFn, separator, startsAtElement, build, tolerant);
|
|
780
968
|
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
969
|
if (reEnd < newInput.length) {
|
|
786
970
|
for (const sentinel of [" ", "\uFFFF"]) {
|
|
787
971
|
if (newInput[reEnd] === sentinel) continue;
|
|
788
972
|
const probed = newInput.slice(0, reEnd) + sentinel.repeat(newInput.length - reEnd);
|
|
789
|
-
const probe = parseMiddle(probed, reStart, reEnd, cStart, ruleFn, separator, build, tolerant);
|
|
973
|
+
const probe = parseMiddle(probed, reStart, reEnd, cStart, ruleFn, separator, startsAtElement, build, tolerant);
|
|
790
974
|
if (!probe || probe.length !== middle.length) return null;
|
|
791
975
|
for (let i = 0; i < middle.length; i++) if (!structurallyEqual(probe[i], middle[i])) return null;
|
|
792
976
|
}
|
|
@@ -850,7 +1034,11 @@ var ParseDocImpl = class _ParseDocImpl {
|
|
|
850
1034
|
_registry;
|
|
851
1035
|
/** Registry entries normalized to callable parse functions (memoized once). */
|
|
852
1036
|
_fns;
|
|
853
|
-
/**
|
|
1037
|
+
/**
|
|
1038
|
+
* Rule names the grammar proves are genuine repetitions — the ONLY splice-safe
|
|
1039
|
+
* types — mapped to the repetition shape (and, for a `sepBy`, the separator text
|
|
1040
|
+
* its construction pins). A rule whose separator isn't recoverable is absent.
|
|
1041
|
+
*/
|
|
854
1042
|
_reps;
|
|
855
1043
|
_rootRule;
|
|
856
1044
|
_opts;
|
|
@@ -871,10 +1059,11 @@ var ParseDocImpl = class _ParseDocImpl {
|
|
|
871
1059
|
constructor(registry, rootRule, opts, trees, errors, unconsumedFrom, input) {
|
|
872
1060
|
this._registry = registry;
|
|
873
1061
|
this._fns = {};
|
|
874
|
-
this._reps = /* @__PURE__ */ new
|
|
1062
|
+
this._reps = /* @__PURE__ */ new Map();
|
|
875
1063
|
for (const [name, entry] of Object.entries(registry)) {
|
|
876
1064
|
this._fns[name] = asRuleFn(entry);
|
|
877
|
-
|
|
1065
|
+
const rep = producesRepetition(defOf(entry));
|
|
1066
|
+
if (rep) this._reps.set(name, rep);
|
|
878
1067
|
}
|
|
879
1068
|
this._rootRule = rootRule;
|
|
880
1069
|
this._opts = opts;
|
|
@@ -958,10 +1147,11 @@ var ParseDocImpl = class _ParseDocImpl {
|
|
|
958
1147
|
if (this._opts.structuralReuse && delta !== 0 && !this._opts.rebuild) {
|
|
959
1148
|
const spliceCandidates = [...candidates, { node: root, path: [] }];
|
|
960
1149
|
for (const { node: node2, path } of spliceCandidates) {
|
|
961
|
-
|
|
1150
|
+
const rep = this._reps.get(node2.type);
|
|
1151
|
+
if (!rep) continue;
|
|
962
1152
|
const { start: cStart, end: cEnd } = absoluteSpanCST(root, path);
|
|
963
1153
|
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);
|
|
1154
|
+
const spliced = tryListSplice(root, path, node2, cStart, newInput, from, to, delta, rep, this._fns, this._opts.build, !!this._opts.tolerant);
|
|
965
1155
|
if (spliced) return this.wrapReuse(spliced, newInput);
|
|
966
1156
|
}
|
|
967
1157
|
}
|
|
@@ -977,7 +1167,7 @@ function triviaOf(entry, opts) {
|
|
|
977
1167
|
function unconsumedAfter(end, input, trivia2) {
|
|
978
1168
|
let pos = end;
|
|
979
1169
|
if (trivia2 && pos < input.length) {
|
|
980
|
-
const t = trivia2.parse(input, pos,
|
|
1170
|
+
const t = trivia2.parse(input, pos, createParseContext());
|
|
981
1171
|
if (t.ok && t.span.end > pos) pos = t.span.end;
|
|
982
1172
|
}
|
|
983
1173
|
return pos < input.length ? pos : null;
|