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
|
@@ -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,104 @@ 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_DISPATCH = 25;
|
|
615
|
+
var OP_ROUTED = 26;
|
|
616
|
+
var OP_NAMES = {
|
|
617
|
+
[OP_LIT]: "LIT",
|
|
618
|
+
[OP_RX]: "RX",
|
|
619
|
+
[OP_SEQ]: "SEQ",
|
|
620
|
+
[OP_SEQV]: "SEQV",
|
|
621
|
+
[OP_CHOICE]: "CHOICE",
|
|
622
|
+
[OP_REP]: "REP",
|
|
623
|
+
[OP_REPV]: "REPV",
|
|
624
|
+
[OP_OPT]: "OPT",
|
|
625
|
+
[OP_XFORM]: "XFORM",
|
|
626
|
+
[OP_NODE]: "NODE",
|
|
627
|
+
[OP_RULE]: "RULE",
|
|
628
|
+
[OP_GATE]: "GATE",
|
|
629
|
+
[OP_NOT]: "NOT",
|
|
630
|
+
[OP_PEEK]: "PEEK",
|
|
631
|
+
[OP_LEAF]: "LEAF",
|
|
632
|
+
[OP_EMPTY]: "EMPTY",
|
|
633
|
+
[OP_LIT_TRACK]: "LIT_TRACK",
|
|
634
|
+
[OP_RX_TRACK]: "RX_TRACK",
|
|
635
|
+
[OP_NODE_TRACK]: "NODE_TRACK",
|
|
636
|
+
[OP_SCOPE]: "SCOPE",
|
|
637
|
+
[OP_EXPECT]: "EXPECT",
|
|
638
|
+
[OP_SEQX]: "SEQX",
|
|
639
|
+
[OP_SCAN]: "SCAN",
|
|
640
|
+
[OP_FIELD]: "FIELD",
|
|
641
|
+
[OP_LIT_CI]: "LIT_CI",
|
|
642
|
+
[OP_LIT_CI_TRACK]: "LIT_CI_TRACK",
|
|
643
|
+
[OP_DISPATCH]: "DISPATCH",
|
|
644
|
+
[OP_ROUTED]: "ROUTED",
|
|
645
|
+
[OP_TOKEN]: "TOKEN",
|
|
646
|
+
[OP_SCOPE_CAP]: "SCOPE_CAP",
|
|
647
|
+
[OP_WITHCTX]: "WITHCTX",
|
|
648
|
+
[OP_GUARD]: "GUARD",
|
|
649
|
+
[OP_ADJ]: "ADJ",
|
|
650
|
+
[OP_GREEDY]: "GREEDY",
|
|
651
|
+
[OP_REJECT]: "REJECT",
|
|
652
|
+
[OP_ARMGATE]: "ARMGATE",
|
|
653
|
+
[OP_LIVE]: "LIVE",
|
|
654
|
+
[OP_ATTEMPT]: "ATTEMPT",
|
|
655
|
+
[OP_LABEL]: "LABEL",
|
|
656
|
+
[OP_COV]: "COV"
|
|
657
|
+
};
|
|
658
|
+
|
|
659
|
+
// src/table/scan-shapes.ts
|
|
660
|
+
var META2 = new Set("()[]{}*+?|^$.".split(""));
|
|
661
|
+
|
|
662
|
+
// src/table/assemble.ts
|
|
663
|
+
var EMIT_ENABLED = globalThis.process?.env?.PM_TABLE_EMIT !== "0";
|
|
664
|
+
var EMPTY_TL = Object.freeze([]);
|
|
665
|
+
var EMPTY_SENTS = Object.freeze([]);
|
|
505
666
|
|
|
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
|
-
);
|
|
667
|
+
// src/analysis/duplication.ts
|
|
668
|
+
var WORD_RE_SRC = "-?[A-Za-z][A-Za-z0-9_-]*";
|
|
669
|
+
var WORDS_RE = new RegExp(`^${WORD_RE_SRC}(?:\\|${WORD_RE_SRC})*$`);
|
|
512
670
|
|
|
513
671
|
// src/compiler/linker.ts
|
|
514
672
|
function normalizeCstCollapse(collapse) {
|
|
@@ -582,14 +740,48 @@ function asRuleFn(entry) {
|
|
|
582
740
|
function defOf(entry) {
|
|
583
741
|
return typeof entry === "object" && entry !== null && "_def" in entry ? entry._def : void 0;
|
|
584
742
|
}
|
|
743
|
+
function literalTextOf(parser2, depth = 0) {
|
|
744
|
+
const def = defOf(parser2);
|
|
745
|
+
if (!def || depth > 24) return null;
|
|
746
|
+
const d = def;
|
|
747
|
+
switch (d.tag) {
|
|
748
|
+
case "literal":
|
|
749
|
+
return d.caseInsensitive ? null : d.value;
|
|
750
|
+
case "lazy": {
|
|
751
|
+
const thunk = d.thunk;
|
|
752
|
+
try {
|
|
753
|
+
return typeof thunk === "function" ? literalTextOf(thunk(), depth + 1) : null;
|
|
754
|
+
} catch {
|
|
755
|
+
return null;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
case "node":
|
|
759
|
+
case "transform":
|
|
760
|
+
case "attempt":
|
|
761
|
+
case "token":
|
|
762
|
+
case "leaf":
|
|
763
|
+
case "label":
|
|
764
|
+
case "field":
|
|
765
|
+
case "expect":
|
|
766
|
+
case "withCtx":
|
|
767
|
+
case "grammar":
|
|
768
|
+
return literalTextOf(d.parser, depth + 1);
|
|
769
|
+
default:
|
|
770
|
+
return null;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
585
773
|
function producesRepetition(def, depth = 0) {
|
|
586
|
-
if (!def || depth > 24) return
|
|
774
|
+
if (!def || depth > 24) return null;
|
|
587
775
|
const d = def;
|
|
588
776
|
switch (d.tag) {
|
|
589
|
-
case "sepBy":
|
|
777
|
+
case "sepBy": {
|
|
778
|
+
if (d.keepSeparators) return null;
|
|
779
|
+
const text = literalTextOf(d.separator);
|
|
780
|
+
return text === null || text.length === 0 ? null : { kind: "sep", text };
|
|
781
|
+
}
|
|
590
782
|
case "many":
|
|
591
783
|
case "oneOrMore":
|
|
592
|
-
return
|
|
784
|
+
return { kind: "bare" };
|
|
593
785
|
// Rule entries and `ref`s wrap their body in a `lazy` thunk — resolve it. The
|
|
594
786
|
// `depth` cap bounds any self-referential cycle (a repetition, if present, is
|
|
595
787
|
// found shallowly before recursion goes deep).
|
|
@@ -599,7 +791,7 @@ function producesRepetition(def, depth = 0) {
|
|
|
599
791
|
try {
|
|
600
792
|
inner = typeof thunk === "function" ? thunk() : void 0;
|
|
601
793
|
} catch {
|
|
602
|
-
return
|
|
794
|
+
return null;
|
|
603
795
|
}
|
|
604
796
|
return producesRepetition(inner?._def, depth + 1);
|
|
605
797
|
}
|
|
@@ -616,13 +808,16 @@ function producesRepetition(def, depth = 0) {
|
|
|
616
808
|
case "grammar":
|
|
617
809
|
case "optional":
|
|
618
810
|
return producesRepetition(defOf(d.parser), depth + 1);
|
|
619
|
-
case "skip":
|
|
620
|
-
return producesRepetition(defOf(d.main), depth + 1);
|
|
621
811
|
// A bracketed/anchored list is a sequence whose element run is a repetition.
|
|
622
|
-
case "sequence":
|
|
623
|
-
|
|
812
|
+
case "sequence": {
|
|
813
|
+
for (const p of d.parsers) {
|
|
814
|
+
const rep = producesRepetition(defOf(p), depth + 1);
|
|
815
|
+
if (rep) return rep;
|
|
816
|
+
}
|
|
817
|
+
return null;
|
|
818
|
+
}
|
|
624
819
|
default:
|
|
625
|
-
return
|
|
820
|
+
return null;
|
|
626
821
|
}
|
|
627
822
|
}
|
|
628
823
|
var REENTRY_MAX_SPAN_FRACTION = 0.5;
|
|
@@ -684,17 +879,18 @@ function graftRelative(root, path, newNode, delta) {
|
|
|
684
879
|
children: newChildren
|
|
685
880
|
};
|
|
686
881
|
}
|
|
687
|
-
function parseMiddle(input, reStart, reEnd, cStart, ruleFn, separator, build, tolerant) {
|
|
882
|
+
function parseMiddle(input, reStart, reEnd, cStart, ruleFn, separator, startsAtElement, build, tolerant) {
|
|
688
883
|
const ctx = mkCtx(null, build, tolerant);
|
|
689
884
|
const out = [];
|
|
690
885
|
let pos = reStart;
|
|
691
886
|
let guard = 0;
|
|
887
|
+
let expectElement = separator === null ? true : startsAtElement;
|
|
692
888
|
while (pos < reEnd) {
|
|
693
889
|
if (++guard > reEnd - reStart + 2) return null;
|
|
694
|
-
if (separator
|
|
890
|
+
if (separator !== null && !expectElement) {
|
|
695
891
|
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
892
|
pos += separator.length;
|
|
893
|
+
expectElement = true;
|
|
698
894
|
continue;
|
|
699
895
|
}
|
|
700
896
|
let r;
|
|
@@ -706,15 +902,15 @@ function parseMiddle(input, reStart, reEnd, cStart, ruleFn, separator, build, to
|
|
|
706
902
|
if (!r.ok || r.span.end <= pos || r.span.end > reEnd) return null;
|
|
707
903
|
out.push(relativizeCST(r.value, cStart));
|
|
708
904
|
pos = r.span.end;
|
|
905
|
+
if (separator !== null) expectElement = false;
|
|
709
906
|
}
|
|
710
|
-
return pos === reEnd ? out : null;
|
|
907
|
+
return pos === reEnd && expectElement ? out : null;
|
|
711
908
|
}
|
|
712
|
-
function tryListSplice(root, path, C, cStart, newInput, from, to, delta, registry, build, tolerant) {
|
|
909
|
+
function tryListSplice(root, path, C, cStart, newInput, from, to, delta, rep, registry, build, tolerant) {
|
|
713
910
|
const kids = C.children;
|
|
714
911
|
if (kids.length === 0) return null;
|
|
715
912
|
let h = 0;
|
|
716
913
|
while (h < kids.length && cStart + kids[h].span.end <= from) h++;
|
|
717
|
-
while (h > 0 && kids[h - 1]._tag === "node") h--;
|
|
718
914
|
let t = kids.length;
|
|
719
915
|
while (t > h && cStart + kids[t - 1].span.start >= to) t--;
|
|
720
916
|
while (t < kids.length && kids[t]._tag !== "node") t++;
|
|
@@ -733,16 +929,7 @@ function tryListSplice(root, path, C, cStart, newInput, from, to, delta, registr
|
|
|
733
929
|
if (elemType === void 0 || elemCount < 2) return null;
|
|
734
930
|
const ruleFn = registry[elemType];
|
|
735
931
|
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;
|
|
932
|
+
const separator = rep.kind === "sep" ? rep.text : null;
|
|
746
933
|
const first = kids[0];
|
|
747
934
|
const last = kids[kids.length - 1];
|
|
748
935
|
if (first._tag === "leaf" && first.value !== separator && from < cStart + first.span.end) return null;
|
|
@@ -750,17 +937,14 @@ function tryListSplice(root, path, C, cStart, newInput, from, to, delta, registr
|
|
|
750
937
|
const reStart = h > 0 ? cStart + kids[h - 1].span.end : cStart;
|
|
751
938
|
const reEnd = cStart + kids[t].span.start + delta;
|
|
752
939
|
if (reEnd < reStart) return null;
|
|
753
|
-
const
|
|
940
|
+
const startsAtElement = !(h > 0 && kids[h - 1]._tag === "node");
|
|
941
|
+
const middle = parseMiddle(newInput, reStart, reEnd, cStart, ruleFn, separator, startsAtElement, build, tolerant);
|
|
754
942
|
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
943
|
if (reEnd < newInput.length) {
|
|
760
944
|
for (const sentinel of [" ", "\uFFFF"]) {
|
|
761
945
|
if (newInput[reEnd] === sentinel) continue;
|
|
762
946
|
const probed = newInput.slice(0, reEnd) + sentinel.repeat(newInput.length - reEnd);
|
|
763
|
-
const probe = parseMiddle(probed, reStart, reEnd, cStart, ruleFn, separator, build, tolerant);
|
|
947
|
+
const probe = parseMiddle(probed, reStart, reEnd, cStart, ruleFn, separator, startsAtElement, build, tolerant);
|
|
764
948
|
if (!probe || probe.length !== middle.length) return null;
|
|
765
949
|
for (let i = 0; i < middle.length; i++) if (!structurallyEqual(probe[i], middle[i])) return null;
|
|
766
950
|
}
|
|
@@ -824,7 +1008,11 @@ var ParseDocImpl = class _ParseDocImpl {
|
|
|
824
1008
|
_registry;
|
|
825
1009
|
/** Registry entries normalized to callable parse functions (memoized once). */
|
|
826
1010
|
_fns;
|
|
827
|
-
/**
|
|
1011
|
+
/**
|
|
1012
|
+
* Rule names the grammar proves are genuine repetitions — the ONLY splice-safe
|
|
1013
|
+
* types — mapped to the repetition shape (and, for a `sepBy`, the separator text
|
|
1014
|
+
* its construction pins). A rule whose separator isn't recoverable is absent.
|
|
1015
|
+
*/
|
|
828
1016
|
_reps;
|
|
829
1017
|
_rootRule;
|
|
830
1018
|
_opts;
|
|
@@ -845,10 +1033,11 @@ var ParseDocImpl = class _ParseDocImpl {
|
|
|
845
1033
|
constructor(registry, rootRule, opts, trees, errors, unconsumedFrom, input) {
|
|
846
1034
|
this._registry = registry;
|
|
847
1035
|
this._fns = {};
|
|
848
|
-
this._reps = /* @__PURE__ */ new
|
|
1036
|
+
this._reps = /* @__PURE__ */ new Map();
|
|
849
1037
|
for (const [name, entry] of Object.entries(registry)) {
|
|
850
1038
|
this._fns[name] = asRuleFn(entry);
|
|
851
|
-
|
|
1039
|
+
const rep = producesRepetition(defOf(entry));
|
|
1040
|
+
if (rep) this._reps.set(name, rep);
|
|
852
1041
|
}
|
|
853
1042
|
this._rootRule = rootRule;
|
|
854
1043
|
this._opts = opts;
|
|
@@ -932,10 +1121,11 @@ var ParseDocImpl = class _ParseDocImpl {
|
|
|
932
1121
|
if (this._opts.structuralReuse && delta !== 0 && !this._opts.rebuild) {
|
|
933
1122
|
const spliceCandidates = [...candidates, { node: root, path: [] }];
|
|
934
1123
|
for (const { node: node2, path } of spliceCandidates) {
|
|
935
|
-
|
|
1124
|
+
const rep = this._reps.get(node2.type);
|
|
1125
|
+
if (!rep) continue;
|
|
936
1126
|
const { start: cStart, end: cEnd } = absoluteSpanCST(root, path);
|
|
937
1127
|
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);
|
|
1128
|
+
const spliced = tryListSplice(root, path, node2, cStart, newInput, from, to, delta, rep, this._fns, this._opts.build, !!this._opts.tolerant);
|
|
939
1129
|
if (spliced) return this.wrapReuse(spliced, newInput);
|
|
940
1130
|
}
|
|
941
1131
|
}
|
|
@@ -951,7 +1141,7 @@ function triviaOf(entry, opts) {
|
|
|
951
1141
|
function unconsumedAfter(end, input, trivia2) {
|
|
952
1142
|
let pos = end;
|
|
953
1143
|
if (trivia2 && pos < input.length) {
|
|
954
|
-
const t = trivia2.parse(input, pos,
|
|
1144
|
+
const t = trivia2.parse(input, pos, createParseContext());
|
|
955
1145
|
if (t.ok && t.span.end > pos) pos = t.span.end;
|
|
956
1146
|
}
|
|
957
1147
|
return pos < input.length ? pos : null;
|