parseman 0.58.3 → 0.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/analysis/diagnostics.js +141 -93
  2. package/dist/analysis/diagnostics.js.map +3 -3
  3. package/dist/cli/index.js +143 -94
  4. package/dist/cli/index.js.map +3 -3
  5. package/dist/combinators/dispatch.d.ts.map +1 -1
  6. package/dist/combinators/field-trivia.d.ts.map +1 -1
  7. package/dist/combinators/keywords.d.ts.map +1 -1
  8. package/dist/combinators/literal.d.ts.map +1 -1
  9. package/dist/combinators/node.d.ts.map +1 -1
  10. package/dist/combinators/regex.d.ts.map +1 -1
  11. package/dist/combinators/scanTo.d.ts.map +1 -1
  12. package/dist/combinators/token.d.ts.map +1 -1
  13. package/dist/compiler/linker.d.ts.map +1 -1
  14. package/dist/compiler/token-capability.js.map +1 -1
  15. package/dist/cst/capture-buffer.d.ts.map +1 -1
  16. package/dist/cst/plain.js +69 -0
  17. package/dist/cst/plain.js.map +6 -0
  18. package/dist/index.js +144 -98
  19. package/dist/index.js.map +3 -3
  20. package/dist/language-service/index.js +19 -2
  21. package/dist/language-service/index.js.map +2 -2
  22. package/dist/line-index.d.ts +13 -0
  23. package/dist/line-index.d.ts.map +1 -1
  24. package/dist/plugin/entry-supercompiler.d.ts.map +1 -1
  25. package/dist/plugin/index.js +146 -100
  26. package/dist/plugin/index.js.map +3 -3
  27. package/dist/recovery/scan.d.ts.map +1 -1
  28. package/dist/run/index.js +4 -1
  29. package/dist/run/index.js.map +2 -2
  30. package/dist/spec/index.js +18 -1
  31. package/dist/spec/index.js.map +2 -2
  32. package/dist/table/assemble.d.ts.map +1 -1
  33. package/dist/table/emit-assembly.d.ts +1 -1
  34. package/dist/table/emit-assembly.d.ts.map +1 -1
  35. package/dist/table/emit.d.ts +6 -0
  36. package/dist/table/emit.d.ts.map +1 -1
  37. package/dist/table/index.js +124 -89
  38. package/dist/table/index.js.map +3 -3
  39. package/dist/table/run-support.d.ts.map +1 -1
  40. package/dist/version.d.ts +1 -1
  41. package/package.json +2 -1
  42. package/src/combinators/dispatch.ts +2 -1
  43. package/src/combinators/field-trivia.ts +6 -5
  44. package/src/combinators/keywords.ts +3 -2
  45. package/src/combinators/literal.ts +5 -4
  46. package/src/combinators/node.ts +3 -1
  47. package/src/combinators/regex.ts +5 -4
  48. package/src/combinators/scanTo.ts +2 -1
  49. package/src/combinators/token.ts +3 -6
  50. package/src/compiler/linker.ts +4 -2
  51. package/src/cst/capture-buffer.ts +13 -5
  52. package/src/cst/plain.d.ts +35 -0
  53. package/src/cst/plain.js +74 -0
  54. package/src/line-index.ts +37 -0
  55. package/src/plugin/entry-supercompiler.ts +3 -2
  56. package/src/recovery/scan.ts +2 -1
  57. package/src/table/assemble.ts +33 -35
  58. package/src/table/emit-assembly.ts +27 -24
  59. package/src/table/emit.ts +9 -1
  60. package/src/table/run-support.ts +4 -7
  61. package/src/version.ts +1 -1
package/dist/cli/index.js CHANGED
@@ -725,6 +725,7 @@ function analyzeChoice(p, d, rule2, resolve2) {
725
725
  }
726
726
 
727
727
  // src/line-index.ts
728
+ import { PlainLineSpan, PlainSpan } from "../cst/plain.js";
728
729
  function createLineIndex() {
729
730
  return { lineStarts: [0] };
730
731
  }
@@ -777,6 +778,27 @@ function annotateSpan(span, index) {
777
778
  endColumn: e.col
778
779
  };
779
780
  }
781
+ var SPAN_KEYS = ["start", "end", "startLine", "startColumn", "endLine", "endColumn"];
782
+ function copySpan(span) {
783
+ let n = 0;
784
+ for (const key in span) {
785
+ if (key !== SPAN_KEYS[n]) return { ...span };
786
+ n++;
787
+ }
788
+ if (n === 2) return new PlainSpan(span.start, span.end);
789
+ if (n === 6 && span.startLine !== void 0 && span.startColumn !== void 0 && span.endLine !== void 0 && span.endColumn !== void 0) {
790
+ return new PlainLineSpan(span.start, span.end, span.startLine, span.startColumn, span.endLine, span.endColumn);
791
+ }
792
+ return { ...span };
793
+ }
794
+ function lineSpanFromContext(span, ctx) {
795
+ if (!ctx.trackLines) return span;
796
+ const index = ctx._lineIndex ?? (ctx._lineStarts ? { lineStarts: ctx._lineStarts } : void 0);
797
+ if (!index) return span;
798
+ const s = offsetToLineCol(index, span.start);
799
+ const e = offsetToLineCol(index, span.end);
800
+ return new PlainLineSpan(span.start, span.end, s.line, s.col, e.line, e.col);
801
+ }
780
802
  function annotateSpanFromLineContext(span, ctx) {
781
803
  if (!ctx.trackLines) return span;
782
804
  const index = ctx._lineIndex ?? (ctx._lineStarts ? { lineStarts: ctx._lineStarts } : void 0);
@@ -784,6 +806,7 @@ function annotateSpanFromLineContext(span, ctx) {
784
806
  }
785
807
 
786
808
  // src/cst/capture-buffer.ts
809
+ import { PlainBuf, PlainLeaf } from "../cst/plain.js";
787
810
  var EMPTY = [];
788
811
  var EMPTY_TL = [];
789
812
  function cstCaptureActive(ctx) {
@@ -798,7 +821,7 @@ function beginCstNodeCapture(ctx) {
798
821
  cap: ctx.captureTrivia,
799
822
  buf: ctx._cstBuf
800
823
  };
801
- ctx._cstBuf = {};
824
+ ctx._cstBuf = new PlainBuf(void 0, void 0, 0);
802
825
  ctx._cstChildren = void 0;
803
826
  ctx._cstLeaves = void 0;
804
827
  ctx._cstRawChildren = void 0;
@@ -823,12 +846,15 @@ function endCstNodeCapture(ctx, saved) {
823
846
  ctx.captureTrivia = saved.cap;
824
847
  return materialized;
825
848
  }
849
+ function isLeaf(v) {
850
+ return typeof v === "object" && v !== null && v._tag === "leaf";
851
+ }
826
852
  function pushCstLeaf(ctx, leaf2) {
827
853
  if (!ctx.trackLines) {
828
854
  pushCstChild(ctx, leaf2, leaf2);
829
855
  return;
830
856
  }
831
- const annotated = leaf2 && typeof leaf2 === "object" && leaf2.span ? { ...leaf2, span: annotateSpanFromLineContext(leaf2.span, ctx) } : leaf2;
857
+ const annotated = isLeaf(leaf2) ? new PlainLeaf(leaf2.value, lineSpanFromContext(leaf2.span, ctx)) : leaf2 && typeof leaf2 === "object" && leaf2.span ? { ...leaf2, span: annotateSpanFromLineContext(leaf2.span, ctx) } : leaf2;
832
858
  pushCstChild(ctx, annotated, annotated);
833
859
  }
834
860
  function pushCstChild(ctx, built, rawEntry2) {
@@ -2410,6 +2436,7 @@ function altStarSource(source) {
2410
2436
  }
2411
2437
 
2412
2438
  // src/combinators/dispatch.ts
2439
+ import { PlainLeaf as PlainLeaf2 } from "../cst/plain.js";
2413
2440
  function parserUsesRouted(parser2, seen = /* @__PURE__ */ new Set()) {
2414
2441
  if (seen.has(parser2)) return false;
2415
2442
  seen.add(parser2);
@@ -2478,6 +2505,7 @@ function asciiFoldKey(key) {
2478
2505
  }
2479
2506
 
2480
2507
  // src/recovery/scan.ts
2508
+ import { PlainSpan as PlainSpan2 } from "../cst/plain.js";
2481
2509
  function probeAt(sentinel, input, pos, ctx) {
2482
2510
  const s = {
2483
2511
  _probe: ctx._probe,
@@ -2554,7 +2582,7 @@ function firstSetSentinel(fs) {
2554
2582
  function recoverScan(input, from, ctx, sync, expected) {
2555
2583
  let scanPos = from;
2556
2584
  while (scanPos < input.length && !probeAt(sync, input, scanPos, ctx)) scanPos++;
2557
- const span = { start: from, end: scanPos };
2585
+ const span = new PlainSpan2(from, scanPos);
2558
2586
  if (ctx.trackLines) recordLineRangeFromContext(ctx, input, from, scanPos);
2559
2587
  const error = { _tag: "parseError", span: ctx.trackLines ? annotateSpanFromLineContext(span, ctx) : span, expected };
2560
2588
  ctx._errors?.push(error);
@@ -2744,6 +2772,7 @@ function failAt(ctx, expected, pos) {
2744
2772
  }
2745
2773
 
2746
2774
  // src/combinators/keywords.ts
2775
+ import { PlainLeaf as PlainLeaf3, PlainSpan as PlainSpan3 } from "../cst/plain.js";
2747
2776
  function escapeRe(s) {
2748
2777
  return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2749
2778
  }
@@ -2792,8 +2821,8 @@ function keywords(words, opts = {}) {
2792
2821
  const m = re.exec(input);
2793
2822
  if (m === null) return failAt(ctx, directTerminalFailureExpected(def), pos);
2794
2823
  const value = m[0];
2795
- const span = { start: pos, end: pos + value.length };
2796
- if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value, span });
2824
+ const span = new PlainSpan3(pos, pos + value.length);
2825
+ if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf3(value, span));
2797
2826
  return { ok: true, value, span };
2798
2827
  }
2799
2828
  };
@@ -4429,17 +4458,18 @@ function buildAsciiDispatch(parsers) {
4429
4458
  }
4430
4459
 
4431
4460
  // src/combinators/field-trivia.ts
4461
+ import { PlainSpan as PlainSpan4, PlainTriviaField } from "../cst/plain.js";
4432
4462
  var LEAD = { at: -1 };
4433
4463
  var FIELD_LEADING_TRIVIA = 1;
4434
4464
  var FIELD_TRAILING_TRIVIA = 2;
4435
4465
  function triviaFieldCapture(name, value, input, start, end, leadFrom, trailEnd) {
4436
- return {
4466
+ return new PlainTriviaField(
4437
4467
  name,
4438
4468
  value,
4439
- span: { start, end },
4440
- leading: leadFrom >= 0 && leadFrom < start ? input.slice(leadFrom, start) : "",
4441
- trailing: trailEnd > end ? input.slice(end, trailEnd) : ""
4442
- };
4469
+ new PlainSpan4(start, end),
4470
+ leadFrom >= 0 && leadFrom < start ? input.slice(leadFrom, start) : "",
4471
+ trailEnd > end ? input.slice(end, trailEnd) : ""
4472
+ );
4443
4473
  }
4444
4474
  function leadsTrivia(p) {
4445
4475
  return p._def.tag === "field" && p._def.leadingTrivia === true;
@@ -4955,6 +4985,7 @@ function field(name, combinator, opts) {
4955
4985
  }
4956
4986
 
4957
4987
  // src/combinators/regex.ts
4988
+ import { PlainLeaf as PlainLeaf4, PlainSpan as PlainSpan5 } from "../cst/plain.js";
4958
4989
  var SCAN_BAIL_AT = 64;
4959
4990
  function inRanges3(cp, ranges) {
4960
4991
  for (let i = 0; i < ranges.length; i++) {
@@ -5067,9 +5098,9 @@ function regex(pattern, flags = "") {
5067
5098
  if (scanEnd !== void 0) {
5068
5099
  if (scanEnd === null) return failAt(ctx, directTerminalFailureExpected(def), pos);
5069
5100
  const value = input.slice(pos, scanEnd);
5070
- const span2 = { start: pos, end: scanEnd };
5101
+ const span2 = new PlainSpan5(pos, scanEnd);
5071
5102
  if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, scanEnd);
5072
- if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value, span: span2 });
5103
+ if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf4(value, span2));
5073
5104
  return { ok: true, value, span: span2 };
5074
5105
  }
5075
5106
  anchored.lastIndex = pos;
@@ -5077,9 +5108,9 @@ function regex(pattern, flags = "") {
5077
5108
  if (m === null) {
5078
5109
  return failAt(ctx, directTerminalFailureExpected(def), pos);
5079
5110
  }
5080
- const span = { start: pos, end: pos + m[0].length };
5111
+ const span = new PlainSpan5(pos, pos + m[0].length);
5081
5112
  if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, span.end);
5082
- if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value: m[0], span });
5113
+ if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf4(m[0], span));
5083
5114
  return { ok: true, value: m[0], span };
5084
5115
  }
5085
5116
  };
@@ -5106,6 +5137,7 @@ function buildLexBodyRecognizer(spec, constants) {
5106
5137
  }
5107
5138
 
5108
5139
  // src/table/run-support.ts
5140
+ import { PlainLeaf as PlainLeaf5, PlainLineSpan as PlainLineSpan2, PlainSpan as PlainSpan6 } from "../cst/plain.js";
5109
5141
  function lineCol(ctx, offset) {
5110
5142
  const starts = ctx._lineStarts ?? [0];
5111
5143
  let lo = 0, hi = starts.length - 1;
@@ -5118,18 +5150,14 @@ function lineCol(ctx, offset) {
5118
5150
  }
5119
5151
  function spanLines(ctx, start, end) {
5120
5152
  const s = lineCol(ctx, start), e = lineCol(ctx, end);
5121
- return { start, end, startLine: s[0], startColumn: s[1], endLine: e[0], endColumn: e[1] };
5153
+ return new PlainLineSpan2(start, end, s[0], s[1], e[0], e[1]);
5122
5154
  }
5123
5155
  function rawEntry(v, input, s, e) {
5124
5156
  if (typeof v === "object" && v !== null) {
5125
5157
  const tg = v._tag;
5126
5158
  if (tg === "node" || tg === "leaf" || tg === "parseError") return v;
5127
5159
  }
5128
- return {
5129
- _tag: "leaf",
5130
- value: typeof v === "string" ? v : typeof v === "object" && v !== null ? input.slice(s, e) : "",
5131
- span: { start: s, end: e }
5132
- };
5160
+ return new PlainLeaf5(typeof v === "string" ? v : typeof v === "object" && v !== null ? input.slice(s, e) : "", new PlainSpan6(s, e));
5133
5161
  }
5134
5162
  function lead(input, pos) {
5135
5163
  if (pos >= input.length) return -1;
@@ -5143,7 +5171,7 @@ function collapseEmpty(ctx, build, input, pos, end, readsRaw) {
5143
5171
  const collected = ctx._cstBuf !== void 0 || ctx._cstChildren !== void 0;
5144
5172
  if (collected) popCstChild(ctx);
5145
5173
  const raw = readsRaw ? [rawEntry(void 0, input, pos, end)] : EMPTY_KIDS;
5146
- const nd = build(EMPTY_KIDS, void 0, { start: pos, end }, raw, EMPTY_TRIVIA, void 0);
5174
+ const nd = build(EMPTY_KIDS, void 0, new PlainSpan6(pos, end), raw, EMPTY_TRIVIA, void 0);
5147
5175
  if (collected) pushCstChild(ctx, nd, ctx._cstBuf?.noRaw === true ? void 0 : rawEntry(nd, input, pos, end));
5148
5176
  return nd;
5149
5177
  }
@@ -6365,6 +6393,7 @@ function buildReadsState(def) {
6365
6393
  }
6366
6394
 
6367
6395
  // src/combinators/token.ts
6396
+ import { PlainLeaf as PlainLeaf6 } from "../cst/plain.js";
6368
6397
  function semanticLeafValue(_ctx, _input, _start, _end, value) {
6369
6398
  return value;
6370
6399
  }
@@ -6418,7 +6447,7 @@ function token(root) {
6418
6447
  if (!result.ok) return result;
6419
6448
  const span = result.span;
6420
6449
  const value = input.slice(pos, span.end);
6421
- if (wasCapturing) pushCstLeaf(ctx, { _tag: "leaf", value, span });
6450
+ if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf6(value, span));
6422
6451
  return { ok: true, value, span };
6423
6452
  }
6424
6453
  };
@@ -6466,11 +6495,7 @@ function makeLeaf(root, fn, sourceCstValue) {
6466
6495
  }
6467
6496
  if (!result.ok) return result;
6468
6497
  const value = fn(result.value, result.span);
6469
- if (wasCapturing) pushCstLeaf(ctx, {
6470
- _tag: "leaf",
6471
- value: cstValue(ctx, input, pos, result.span.end, value),
6472
- span: result.span
6473
- });
6498
+ if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf6(cstValue(ctx, input, pos, result.span.end, value), result.span));
6474
6499
  return { ok: true, value, span: result.span };
6475
6500
  }
6476
6501
  };
@@ -7059,6 +7084,7 @@ var OP_NAMES = {
7059
7084
  };
7060
7085
 
7061
7086
  // src/combinators/node.ts
7087
+ import { PlainNode, PlainSpan as PlainSpan7 } from "../cst/plain.js";
7062
7088
  function unwrapChild(child) {
7063
7089
  return child !== null && typeof child === "object" && child._tag === "leaf" ? child.value : child;
7064
7090
  }
@@ -7164,7 +7190,7 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
7164
7190
  const nodeType = def.type ?? missingInferredType();
7165
7191
  const cstOutput = cstOutputHost(ctx.build);
7166
7192
  const span = ctx.trackLines ? annotateSpanFromLineContext(r.span, ctx) : r.span;
7167
- const built = unwrap && children2.length === 1 ? unwrapChild(children2[0]) : collapse && children2.length === 1 ? children2[0] : (cstOutput || !build && project === void 0) && ctx.build?._parsemanCstCollapse && children2.length === 1 && rawChildren.length === 1 && ctx.build._parsemanCstCollapse(nodeType, children2[0], children2, rawChildren) ? children2[0] : project !== void 0 ? cstOutput && ctx.build ? ctx.build(nodeType, children2, fields, span, rawChildren, triviaLog, ctx.state, tags) : projectChild(children2, project, nodeType) : build ? cstOutput && ctx.build ? ctx.build(nodeType, children2, fields, span, rawChildren, triviaLog, ctx.state, tags) : build(children2, fields, span, rawChildren, triviaLog, st) : ctx.build ? ctx.build(nodeType, children2, fields, span, rawChildren, triviaLog, st, tags) : { _tag: "node", type: nodeType, span: ctx.trackLines ? { ...span } : { start: r.span.start, end: r.span.end }, state: st ?? null, children: children2 };
7193
+ const built = unwrap && children2.length === 1 ? unwrapChild(children2[0]) : collapse && children2.length === 1 ? children2[0] : (cstOutput || !build && project === void 0) && ctx.build?._parsemanCstCollapse && children2.length === 1 && rawChildren.length === 1 && ctx.build._parsemanCstCollapse(nodeType, children2[0], children2, rawChildren) ? children2[0] : project !== void 0 ? cstOutput && ctx.build ? ctx.build(nodeType, children2, fields, span, rawChildren, triviaLog, ctx.state, tags) : projectChild(children2, project, nodeType) : build ? cstOutput && ctx.build ? ctx.build(nodeType, children2, fields, span, rawChildren, triviaLog, ctx.state, tags) : build(children2, fields, span, rawChildren, triviaLog, st) : ctx.build ? ctx.build(nodeType, children2, fields, span, rawChildren, triviaLog, st, tags) : new PlainNode(nodeType, ctx.trackLines ? copySpan(span) : new PlainSpan7(r.span.start, r.span.end), st ?? null, [...children2]);
7168
7194
  const rawEntry2 = isCstChild(built) ? built : { _tag: "leaf", value: typeof built === "string" ? built : typeof built === "object" && built !== null ? input.slice(r.span.start, r.span.end) : "", span };
7169
7195
  if (saved.buf !== void 0 || saved.ch !== void 0) {
7170
7196
  pushCstChild(ctx, built, rawEntry2);
@@ -10248,7 +10274,14 @@ var EMITTED_PARAMS = [
10248
10274
  "skipDeferredTrivia",
10249
10275
  // Appended for the pass-through collapse (`run-support.ts`); old factories
10250
10276
  // ignore it.
10251
- "collapseEmpty"
10277
+ "collapseEmpty",
10278
+ // Appended for constructor-built tree objects (`cst/plain.d.ts`): a `new` call has
10279
+ // no allocation site, so V8 cannot pretenure them. Old factories ignore them.
10280
+ "_SP",
10281
+ "_LF",
10282
+ "_ND",
10283
+ "_FC",
10284
+ "_BUF"
10252
10285
  ];
10253
10286
  var RUNTIME_PRELUDE = `
10254
10287
  let _pfScan=null
@@ -10272,9 +10305,9 @@ if(s!==null)return skipTriviaScanned(s,input,cur,ctx)
10272
10305
  if(needsDeferredTriviaCommit(ctx))return skipDeferredTrivia(input,cur,ctx)
10273
10306
  return advanceTrivia(input,cur,ctx)
10274
10307
  }
10275
- function _pushLeaf(ctx,value,s,e){pushCstLeaf(ctx,{_tag:'leaf',value,span:{start:s,end:e}})}
10308
+ function _pushLeaf(ctx,value,s,e){pushCstLeaf(ctx,new _LF(value,new _SP(s,e)))}
10276
10309
  function _pushLeafBuf(ctx,value,s,e){
10277
- const l={_tag:'leaf',value,span:{start:s,end:e}}
10310
+ const l=new _LF(value,new _SP(s,e))
10278
10311
  const b=ctx._cstBuf
10279
10312
  if(b.ch!==undefined)b.ch.push(l)
10280
10313
  else if(b.single!==undefined){b.ch=[b.single,l];b.single=undefined}
@@ -10332,7 +10365,7 @@ if(ctx._rootTriviaLog!==undefined&&ctx._rootTriviaLog.length!==rt)ctx._rootTrivi
10332
10365
  `;
10333
10366
  var NO_RAW_RUNTIME_PRELUDE = `
10334
10367
  function _pushLeafNoRawBuf(ctx,value,s,e){
10335
- const l={_tag:'leaf',value,span:{start:s,end:e}}
10368
+ const l=new _LF(value,new _SP(s,e))
10336
10369
  const b=ctx._cstBuf
10337
10370
  if(b.ch!==undefined)b.ch.push(l)
10338
10371
  else if(b.single!==undefined){b.ch=[b.single,l];b.single=undefined}
@@ -11009,7 +11042,7 @@ try{return ${child}(input,pos,ctx)}finally{ctx.state=saved}
11009
11042
  return `${head}
11010
11043
  const v=${child}(input,pos,ctx)
11011
11044
  if(v===FAIL)return FAIL
11012
- return ${fn}(v,{start:pos,end:EC.e})
11045
+ return ${fn}(v,new _SP(pos,EC.e))
11013
11046
  }`;
11014
11047
  }
11015
11048
  case OP_LABEL: {
@@ -11030,7 +11063,7 @@ return v
11030
11063
  const v=${child}(input,pos,ctx)
11031
11064
  if(v===FAIL)return FAIL
11032
11065
  const f=ctx._fields
11033
- if(f!==undefined)f.push({name:${name},value:v,span:{start:pos,end:EC.e}})
11066
+ if(f!==undefined)f.push(new _FC(${name},v,new _SP(pos,EC.e)))
11034
11067
  return v
11035
11068
  }`;
11036
11069
  }
@@ -11055,7 +11088,7 @@ return v
11055
11088
  return `${head}
11056
11089
  const v=${child}(input,pos,ctx)
11057
11090
  if(v!==FAIL)return v
11058
- const err={_tag:'parseError',span:${prog.lines === 1 ? "spanLines(ctx,pos,pos)" : "{start:pos,end:pos}"},expected:${xf}}
11091
+ const err={_tag:'parseError',span:${prog.lines === 1 ? "spanLines(ctx,pos,pos)" : "new _SP(pos,pos)"},expected:${xf}}
11059
11092
  const es=ctx._errors
11060
11093
  if(es!==undefined)es.push(err)
11061
11094
  ${REC ? "if(ctx._tolerant===true)captureError(ctx,err)\n" : ""}ctx._fc=false
@@ -11066,7 +11099,7 @@ return err
11066
11099
  case OP_ROUTED: {
11067
11100
  const fb = code[ip + 1];
11068
11101
  const fallback = fb >= 0 ? link(fb) : void 0;
11069
- const push = `pushCstLeaf(ctx,{_tag:'leaf',value:it.value,span:it.span})`;
11102
+ const push = `pushCstLeaf(ctx,new _LF(it.value,it.span))`;
11070
11103
  return `${head}
11071
11104
  const it=ctx._routed
11072
11105
  if(it===undefined||pos!==it.span.start){
@@ -11147,8 +11180,8 @@ ctx._triviaLog=sOtl
11147
11180
  }
11148
11181
  if(v===FAIL)return FAIL
11149
11182
  const e=EC.e
11150
- const out=${isToken ? "input.slice(pos,e)" : `${fn}(v,{start:pos,end:e})`}
11151
- if(wasCap)pushCstLeaf(ctx,{_tag:'leaf',value:${capturesSource ? "input.slice(pos,e)" : "out"},span:{start:pos,end:e}})
11183
+ const out=${isToken ? "input.slice(pos,e)" : `${fn}(v,new _SP(pos,e))`}
11184
+ if(wasCap)pushCstLeaf(ctx,new _LF(${capturesSource ? "input.slice(pos,e)" : "out"},new _SP(pos,e)))
11152
11185
  EC.e=e
11153
11186
  return out
11154
11187
  }`;
@@ -11172,7 +11205,7 @@ ${hasSuffix && (lineFlags & 2) !== 0 ? "if(sm)_trackLines(ctx,input,e)" : ""}
11172
11205
  ${hasSuffix ? `if(!sm){ctx._fe=e;ctx._fx=${suffixExpected};if(ctx._probe!==undefined)failAt(ctx,${suffixExpected},e)}` : ""}
11173
11206
  const v=${pending ? "tp?_pfTokValue:" : ""}input.slice(pos,e)
11174
11207
  ${pending ? "if(tp){_pfTokBody=-1;_pfTokValue=undefined}" : ""}
11175
- if(ctx._cstBuf!==undefined||ctx._cstLeaves!==undefined)pushCstLeaf(ctx,{_tag:'leaf',value:v,span:{start:pos,end:e}})
11208
+ if(ctx._cstBuf!==undefined||ctx._cstLeaves!==undefined)pushCstLeaf(ctx,new _LF(v,new _SP(pos,e)))
11176
11209
  EC.e=e
11177
11210
  return v
11178
11211
  }`;
@@ -11211,7 +11244,7 @@ ctx._rootTriviaLog=sRtl
11211
11244
  }
11212
11245
  if(e<0)return FAIL
11213
11246
  const v=input.slice(pos,e)
11214
- if(wasCap)pushCstLeaf(ctx,{_tag:'leaf',value:v,span:{start:pos,end:e}})
11247
+ if(wasCap)pushCstLeaf(ctx,new _LF(v,new _SP(pos,e)))
11215
11248
  EC.e=e
11216
11249
  return v
11217
11250
  }`;
@@ -11219,7 +11252,7 @@ return v
11219
11252
  const e=${run}(input,pos,ctx)
11220
11253
  if(e<0)return FAIL
11221
11254
  const v=input.slice(pos,e)
11222
- if(ctx._cstBuf!==undefined||ctx._cstLeaves!==undefined)pushCstLeaf(ctx,{_tag:'leaf',value:v,span:{start:pos,end:e}})
11255
+ if(ctx._cstBuf!==undefined||ctx._cstLeaves!==undefined)pushCstLeaf(ctx,new _LF(v,new _SP(pos,e)))
11223
11256
  EC.e=e
11224
11257
  return v
11225
11258
  }`;
@@ -11333,7 +11366,7 @@ return v
11333
11366
  }` : `${parts.join("\n")}
11334
11367
  }`;
11335
11368
  if (n === 1) {
11336
- parts.push(fused ? projection === 0 ? "return v0" : `return ${fn}([v0],{start:pos,end:EC.e})` : wantValues ? "return [v0]" : "return undefined");
11369
+ parts.push(fused ? projection === 0 ? "return v0" : `return ${fn}([v0],new _SP(pos,EC.e))` : wantValues ? "return [v0]" : "return undefined");
11337
11370
  return close();
11338
11371
  }
11339
11372
  parts.push("let cur=EC.e");
@@ -11359,7 +11392,7 @@ return v
11359
11392
  names.push(vn);
11360
11393
  }
11361
11394
  parts.push("EC.e=cur");
11362
- parts.push(fused ? projection >= 0 ? `return ${names[projection]}` : `return ${fn}([${names.join(",")}],{start:pos,end:cur})` : wantValues ? `return [${names.join(",")}]` : "return undefined");
11395
+ parts.push(fused ? projection >= 0 ? `return ${names[projection]}` : `return ${fn}([${names.join(",")}],new _SP(pos,cur))` : wantValues ? `return [${names.join(",")}]` : "return undefined");
11363
11396
  return close();
11364
11397
  }
11365
11398
  case OP_CHOICE: {
@@ -11618,7 +11651,7 @@ ${spec.match.map((m, i) => `${i === 0 ? "" : "else "}if(${dispatchClaim(m)})arm=
11618
11651
  const routedCall = (target) => `{const savedRouted=ctx._routed
11619
11652
  ${emitRollback(m1, L.buf, L.raw, sinks)}
11620
11653
  ${emitMark(m2, L.buf, L.raw, sinks, false)}
11621
- ctx._routed={value:key,span:{start:pos,end:selEnd}}
11654
+ ctx._routed={value:key,span:new _SP(pos,selEnd)}
11622
11655
  try{v=${target}(input,pos,ctx)}finally{ctx._routed=savedRouted}
11623
11656
  break}`;
11624
11657
  const plainCall = (target) => `v=${target}(input,selEnd,ctx);break`;
@@ -11813,8 +11846,8 @@ return out
11813
11846
  const end=${recognize}(input,pos)
11814
11847
  if(end<0){ctx._fe=pos;ctx._fx=${xf};return FAIL}
11815
11848
  const value=${value2}
11816
- const leaf={_tag:'leaf',value,span:{start:pos,end}}
11817
- const kids=[leaf],rawKids=[leaf],span={start:pos,end}
11849
+ const leaf=new _LF(value,new _SP(pos,end))
11850
+ const kids=[leaf],rawKids=[leaf],span=new _SP(pos,end)
11818
11851
  EC.e=end
11819
11852
  const nd=${build2}(kids,undefined,span,rawKids,EMPTY_TL,undefined)
11820
11853
  ${L.buf && L.raw === RAW_OMIT ? "_pushNodeNoRawBuf(ctx,nd)" : L.buf && L.raw === RAW_CAPTURE ? "pushCstChild(ctx,nd,rawEntry(nd,input,pos,end))" : staticBuild ? "if(ctx._cstBuf!==undefined||ctx._cstChildren!==undefined)pushCstChild(ctx,nd,ctx._cstBuf!==undefined&&ctx._cstBuf.noRaw===true?undefined:ctx._cstBuf!==undefined||ctx._cstRawChildren!==undefined?rawEntry(nd,input,pos,end):undefined)" : "if(ctx._cstBuf!==undefined||ctx._cstChildren!==undefined)pushCstChild(ctx,nd,rawEntry(nd,input,pos,end))"}
@@ -11913,7 +11946,7 @@ ctx._cstTriviaLog=sTl
11913
11946
  ctx.captureTrivia=sCap
11914
11947
  if(v===FAIL)return FAIL
11915
11948
  const end=EC.e
11916
- ${collapseChildren ? `const nd=captured.length===1?captured[0]:${build}(captured,undefined,{start:pos,end},EMPTY_CH,EMPTY_TL,undefined)` : `const nd=${build}(captured,${fields ? "fieldMap" : "undefined"},{start:pos,end},EMPTY_CH,EMPTY_TL,undefined)`}
11949
+ ${collapseChildren ? `const nd=captured.length===1?captured[0]:${build}(captured,undefined,new _SP(pos,end),EMPTY_CH,EMPTY_TL,undefined)` : `const nd=${build}(captured,${fields ? "fieldMap" : "undefined"},new _SP(pos,end),EMPTY_CH,EMPTY_TL,undefined)`}
11917
11950
  ${publish}
11918
11951
  EC.e=end
11919
11952
  return nd
@@ -11936,20 +11969,20 @@ return nd
11936
11969
  const direct = `${build}(kids,fieldMap,span,rawKids,${captureWide ? "tlog" : "EMPTY_TL"},st)`;
11937
11970
  value = hostCst ? `nd=_pfHost!==undefined?${hostCall}:${direct}` : `nd=${direct}`;
11938
11971
  } else {
11939
- value = `nd=_pfHost!==undefined?_pfHost(${ty},hostKids,fieldMap,span,rawKids,tlog,st,${tags}):{_tag:'node',type:${ty},span,state:st??null,children:kids}`;
11972
+ value = `nd=_pfHost!==undefined?_pfHost(${ty},hostKids,fieldMap,span,rawKids,tlog,st,${tags}):new _ND(${ty},span,st??null,kids===EMPTY_CH?kids:[...kids])`;
11940
11973
  }
11941
11974
  const collapsible = keepChildren && (hostCst || build === void 0 && proj < 0);
11942
- const openCapture = omitsRaw ? `const buf={noRaw:true,rawLen:0}
11975
+ const openCapture = omitsRaw ? `const buf=new _BUF(undefined,true,0)
11943
11976
  ctx._cstBuf=buf
11944
11977
  ctx._cstChildren=undefined
11945
11978
  ctx._cstLeaves=undefined
11946
11979
  ctx._cstRawChildren=undefined
11947
- ctx._cstTriviaLog=undefined` : keepChildren ? `const buf={}
11980
+ ctx._cstTriviaLog=undefined` : keepChildren ? `const buf=new _BUF(undefined,undefined,0)
11948
11981
  ctx._cstBuf=buf
11949
11982
  ctx._cstChildren=undefined
11950
11983
  ctx._cstLeaves=undefined
11951
11984
  ctx._cstRawChildren=undefined
11952
- ctx._cstTriviaLog=undefined` : `const buf={rawOnly:true}
11985
+ ctx._cstTriviaLog=undefined` : `const buf=new _BUF(true,undefined,0)
11953
11986
  ctx._cstBuf=buf
11954
11987
  ctx._cstChildren=undefined
11955
11988
  ctx._cstLeaves=undefined
@@ -11987,7 +12020,7 @@ ctx._cstTriviaLog=sTl
11987
12020
  ctx.captureTrivia=sCap
11988
12021
  if(v===FAIL)return FAIL
11989
12022
  const end=EC.e
11990
- const span=${tracked ? "spanLines(ctx,pos,end)" : "{start:pos,end}"}
12023
+ const span=${tracked ? "spanLines(ctx,pos,end)" : "new _SP(pos,end)"}
11991
12024
  const st=${readsState ? "ctx.state" : "undefined"}
11992
12025
  let nd
11993
12026
  ${unwrap ? "if(kids.length===1)nd=unwrapChild(kids[0])\nelse " : ""}${collapse ? "if(kids.length===1)nd=kids[0]\nelse " : ""}${collapsible ? `if(_pfHost!==undefined&&_pfHost._parsemanCstCollapse!==undefined&&kids.length===1&&rawKids.length===1&&_pfHost._parsemanCstCollapse(${ty},kids[0],kids,rawKids))nd=kids[0]
@@ -12274,6 +12307,7 @@ function rebuildLineScan(s, subtree) {
12274
12307
  }
12275
12308
 
12276
12309
  // src/combinators/literal.ts
12310
+ import { PlainLeaf as PlainLeaf7, PlainSpan as PlainSpan8 } from "../cst/plain.js";
12277
12311
  function asciiFoldEq(a, b) {
12278
12312
  if (a.length !== b.length) return false;
12279
12313
  for (let i = 0; i < a.length; i++) {
@@ -12331,9 +12365,9 @@ function literal(value, opts = {}) {
12331
12365
  const code = value.charCodeAt(0);
12332
12366
  return function parse3(input, pos, ctx) {
12333
12367
  if (input.charCodeAt(pos) === code) {
12334
- const span = { start: pos, end: pos + 1 };
12368
+ const span = new PlainSpan8(pos, pos + 1);
12335
12369
  if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, span.end);
12336
- if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value, span });
12370
+ if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf7(value, span));
12337
12371
  return { ok: true, value, span };
12338
12372
  }
12339
12373
  return failAt(ctx, expected, pos);
@@ -12345,9 +12379,9 @@ function literal(value, opts = {}) {
12345
12379
  }
12346
12380
  const matchedValue = caseInsensitive ? input.slice(pos, end) : value;
12347
12381
  if (caseInsensitive ? asciiFoldEq(matchedValue, value) : input.startsWith(value, pos)) {
12348
- const span = { start: pos, end };
12382
+ const span = new PlainSpan8(pos, end);
12349
12383
  if (canMatchNewline && ctx.trackLines) recordLineRangeFromContext(ctx, input, pos, end);
12350
- if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value: matchedValue, span });
12384
+ if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf7(matchedValue, span));
12351
12385
  return { ok: true, value: matchedValue, span };
12352
12386
  }
12353
12387
  return failAt(ctx, expected, pos);
@@ -12429,6 +12463,7 @@ function ref() {
12429
12463
  }
12430
12464
 
12431
12465
  // src/combinators/scanTo.ts
12466
+ import { PlainLeaf as PlainLeaf8, PlainSpan as PlainSpan9 } from "../cst/plain.js";
12432
12467
  function resolveScanSkip(explicitSkip, raw, ctx) {
12433
12468
  if (raw) return [];
12434
12469
  const trivia2 = ctx.trivia;
@@ -12466,7 +12501,7 @@ function scanTo(sentinel, { skip, raw = false, orEOF = false, recoverAt, stopAt
12466
12501
  probeCtx._errors = ctx._errors;
12467
12502
  const emit = (end) => {
12468
12503
  if (end > pos && cstCaptureActive(ctx)) {
12469
- const leaf2 = { _tag: "leaf", value: input.slice(pos, end), span: { start: pos, end } };
12504
+ const leaf2 = new PlainLeaf8(input.slice(pos, end), new PlainSpan9(pos, end));
12470
12505
  pushCstLeaf(ctx, leaf2);
12471
12506
  }
12472
12507
  };
@@ -12745,6 +12780,9 @@ function clearOf(ranges, input, from, to) {
12745
12780
  return true;
12746
12781
  }
12747
12782
 
12783
+ // src/table/assemble.ts
12784
+ import { PlainBuf as PlainBuf2, PlainField, PlainLeaf as PlainLeaf9, PlainNode as PlainNode2, PlainSpan as PlainSpan10 } from "../cst/plain.js";
12785
+
12748
12786
  // src/table/fail-clean.ts
12749
12787
  function passChild(code, ip) {
12750
12788
  switch (code[ip]) {
@@ -13055,7 +13093,7 @@ function assemble(t2, prog, cfg) {
13055
13093
  const NULLABLE = /* @__PURE__ */ new Map();
13056
13094
  const CLEAN = REC ? () => false : failCleanAnalysis(code);
13057
13095
  function pushLeaf(ctx, value, s, e) {
13058
- const lf = { _tag: "leaf", value, span: { start: s, end: e } };
13096
+ const lf = new PlainLeaf9(value, new PlainSpan10(s, e));
13059
13097
  pushCstLeaf(ctx, lf);
13060
13098
  }
13061
13099
  function plainBuildNode(child, build, trailing) {
@@ -13088,7 +13126,7 @@ function assemble(t2, prog, cfg) {
13088
13126
  ctx.captureTrivia = sCap;
13089
13127
  if (value === FAIL) return FAIL;
13090
13128
  const end = EC.e;
13091
- const span = { start: pos, end };
13129
+ const span = new PlainSpan10(pos, end);
13092
13130
  const node2 = build(kids, void 0, span, rawKids, EMPTY_TL2, void 0);
13093
13131
  if (sBuf !== void 0 || sCh !== void 0) {
13094
13132
  pushCstChild(ctx, node2, rawEntry(node2, input, pos, end));
@@ -13133,7 +13171,7 @@ function assemble(t2, prog, cfg) {
13133
13171
  ctx.captureTrivia = sCap;
13134
13172
  if (value === FAIL) return FAIL;
13135
13173
  const end = EC.e;
13136
- const node2 = build(captured, void 0, { start: pos, end }, EMPTY_CH, EMPTY_TL2, void 0);
13174
+ const node2 = build(captured, void 0, new PlainSpan10(pos, end), EMPTY_CH, EMPTY_TL2, void 0);
13137
13175
  if (sBuf !== void 0 || sCh !== void 0) {
13138
13176
  pushCstChild(ctx, node2, sBuf !== void 0 || sRaw !== void 0 ? rawEntry(node2, input, pos, end) : void 0);
13139
13177
  }
@@ -13170,7 +13208,7 @@ function assemble(t2, prog, cfg) {
13170
13208
  ctx.captureTrivia = sCap;
13171
13209
  if (value === FAIL) return FAIL;
13172
13210
  const end = EC.e;
13173
- const node2 = build(captured, fieldMap, { start: pos, end }, EMPTY_CH, EMPTY_TL2, void 0);
13211
+ const node2 = build(captured, fieldMap, new PlainSpan10(pos, end), EMPTY_CH, EMPTY_TL2, void 0);
13174
13212
  if (sBuf !== void 0 || sCh !== void 0) {
13175
13213
  pushCstChild(ctx, node2, sBuf !== void 0 || sRaw !== void 0 ? rawEntry(node2, input, pos, end) : void 0);
13176
13214
  }
@@ -13207,7 +13245,7 @@ function assemble(t2, prog, cfg) {
13207
13245
  ctx.captureTrivia = sCap;
13208
13246
  if (value === FAIL) return FAIL;
13209
13247
  const end = EC.e;
13210
- const span = { start: pos, end };
13248
+ const span = new PlainSpan10(pos, end);
13211
13249
  const node2 = kids.length === 1 ? kids[0] : build(kids, void 0, span, rawKids, EMPTY_TL2, void 0);
13212
13250
  if (sBuf !== void 0 || sCh !== void 0) {
13213
13251
  pushCstChild(ctx, node2, rawEntry(node2, input, pos, end));
@@ -13244,7 +13282,7 @@ function assemble(t2, prog, cfg) {
13244
13282
  ctx.captureTrivia = sCap;
13245
13283
  if (value === FAIL) return FAIL;
13246
13284
  const end = EC.e;
13247
- const node2 = captured.length === 1 ? captured[0] : build(captured, void 0, { start: pos, end }, EMPTY_CH, EMPTY_TL2, void 0);
13285
+ const node2 = captured.length === 1 ? captured[0] : build(captured, void 0, new PlainSpan10(pos, end), EMPTY_CH, EMPTY_TL2, void 0);
13248
13286
  if (sBuf !== void 0 || sCh !== void 0) {
13249
13287
  pushCstChild(ctx, node2, sBuf !== void 0 || sRaw !== void 0 ? rawEntry(node2, input, pos, end) : void 0);
13250
13288
  }
@@ -13677,7 +13715,7 @@ function assemble(t2, prog, cfg) {
13677
13715
  return (input, pos, selEnd, key, ctx, need, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot) => {
13678
13716
  const savedRouted = ctx._routed;
13679
13717
  if (need) rollbackTriviaAt(ctx, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot);
13680
- ctx._routed = { value: key, span: { start: pos, end: selEnd } };
13718
+ ctx._routed = { value: key, span: new PlainSpan10(pos, selEnd) };
13681
13719
  let v;
13682
13720
  try {
13683
13721
  v = child(input, pos, ctx);
@@ -14110,7 +14148,7 @@ function assemble(t2, prog, cfg) {
14110
14148
  case OP_EXPECT: {
14111
14149
  const child = link(code[ip + 1]);
14112
14150
  const xf = fx[code[ip + 2]];
14113
- const expectSpan = (ctx, pos) => prog.lines === 1 ? spanLines(ctx, pos, pos) : { start: pos, end: pos };
14151
+ const expectSpan = (ctx, pos) => prog.lines === 1 ? spanLines(ctx, pos, pos) : new PlainSpan10(pos, pos);
14114
14152
  if (REC) {
14115
14153
  return (input, pos, ctx) => {
14116
14154
  const v = child(input, pos, ctx);
@@ -14142,7 +14180,7 @@ function assemble(t2, prog, cfg) {
14142
14180
  return (input, pos, ctx) => {
14143
14181
  const v = child(input, pos, ctx);
14144
14182
  if (v === FAIL) return FAIL;
14145
- ctx._fields?.push({ name, value: v, span: { start: pos, end: EC.e } });
14183
+ ctx._fields?.push(new PlainField(name, v, new PlainSpan10(pos, EC.e)));
14146
14184
  return v;
14147
14185
  };
14148
14186
  }
@@ -14166,7 +14204,7 @@ function assemble(t2, prog, cfg) {
14166
14204
  return (input, pos, ctx) => {
14167
14205
  const v = child(input, pos, ctx);
14168
14206
  if (v === FAIL) return FAIL;
14169
- return fn(v, { start: pos, end: EC.e });
14207
+ return fn(v, new PlainSpan10(pos, EC.e));
14170
14208
  };
14171
14209
  }
14172
14210
  case OP_SCAN: {
@@ -14270,7 +14308,7 @@ function assemble(t2, prog, cfg) {
14270
14308
  ctx._fx = ROUTED_FX;
14271
14309
  return FAIL;
14272
14310
  }
14273
- if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value: item.value, span: item.span });
14311
+ if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf9(item.value, item.span));
14274
14312
  EC.e = item.span.end;
14275
14313
  return item.value;
14276
14314
  };
@@ -14456,7 +14494,7 @@ function assemble(t2, prog, cfg) {
14456
14494
  if (v === FAIL) return FAIL;
14457
14495
  const end = EC.e;
14458
14496
  const value = input.slice(pos, end);
14459
- if (wasCapturing) pushCstLeaf(ctx, { _tag: "leaf", value, span: { start: pos, end } });
14497
+ if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf9(value, new PlainSpan10(pos, end)));
14460
14498
  EC.e = end;
14461
14499
  return value;
14462
14500
  };
@@ -14490,7 +14528,7 @@ function assemble(t2, prog, cfg) {
14490
14528
  if (ctx._probe !== void 0) failAt(ctx, suffixExpected, end);
14491
14529
  }
14492
14530
  const value = input.slice(pos, end);
14493
- if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value, span: { start: pos, end } });
14531
+ if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf9(value, new PlainSpan10(pos, end)));
14494
14532
  EC.e = end;
14495
14533
  return value;
14496
14534
  };
@@ -14533,7 +14571,7 @@ function assemble(t2, prog, cfg) {
14533
14571
  }
14534
14572
  if (end < 0) return FAIL;
14535
14573
  const value = input.slice(pos, end);
14536
- if (wasCapturing) pushCstLeaf(ctx, { _tag: "leaf", value, span: { start: pos, end } });
14574
+ if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf9(value, new PlainSpan10(pos, end)));
14537
14575
  EC.e = end;
14538
14576
  return value;
14539
14577
  };
@@ -14542,7 +14580,7 @@ function assemble(t2, prog, cfg) {
14542
14580
  const end = run(input, pos, ctx);
14543
14581
  if (end < 0) return FAIL;
14544
14582
  const value = input.slice(pos, end);
14545
- if (cstCaptureActive(ctx)) pushCstLeaf(ctx, { _tag: "leaf", value, span: { start: pos, end } });
14583
+ if (cstCaptureActive(ctx)) pushCstLeaf(ctx, new PlainLeaf9(value, new PlainSpan10(pos, end)));
14546
14584
  EC.e = end;
14547
14585
  return value;
14548
14586
  };
@@ -14575,12 +14613,8 @@ function assemble(t2, prog, cfg) {
14575
14613
  }
14576
14614
  if (v === FAIL) return FAIL;
14577
14615
  const end = EC.e;
14578
- const out = fn(v, { start: pos, end });
14579
- if (wasCapturing) pushCstLeaf(ctx, {
14580
- _tag: "leaf",
14581
- value: op === OP_SOURCE_LEAF && hostCst ? input.slice(pos, end) : out,
14582
- span: { start: pos, end }
14583
- });
14616
+ const out = fn(v, new PlainSpan10(pos, end));
14617
+ if (wasCapturing) pushCstLeaf(ctx, new PlainLeaf9(op === OP_SOURCE_LEAF && hostCst ? input.slice(pos, end) : out, new PlainSpan10(pos, end)));
14584
14618
  EC.e = end;
14585
14619
  return out;
14586
14620
  };
@@ -14715,7 +14749,7 @@ function assemble(t2, prog, cfg) {
14715
14749
  const cur = runSyncTerms(input, pos, ctx, values);
14716
14750
  if (cur < 0) return FAIL;
14717
14751
  EC.e = cur;
14718
- return projection >= 0 ? values[projection] : fn(values, { start: pos, end: cur });
14752
+ return projection >= 0 ? values[projection] : fn(values, new PlainSpan10(pos, cur));
14719
14753
  };
14720
14754
  }
14721
14755
  if (wantValues) {
@@ -14809,7 +14843,7 @@ function assemble(t2, prog, cfg) {
14809
14843
  const cur = runAdjTerms(input, pos, ctx, values);
14810
14844
  if (cur < 0) return FAIL;
14811
14845
  EC.e = cur;
14812
- return projection >= 0 ? values[projection] : fn(values, { start: pos, end: cur });
14846
+ return projection >= 0 ? values[projection] : fn(values, new PlainSpan10(pos, cur));
14813
14847
  };
14814
14848
  }
14815
14849
  if (wantValues) {
@@ -14834,7 +14868,7 @@ function assemble(t2, prog, cfg) {
14834
14868
  return (input, pos, ctx) => {
14835
14869
  const v = k0(input, pos, ctx);
14836
14870
  if (v === FAIL) return FAIL;
14837
- return projection === 0 ? v : fn([v], { start: pos, end: EC.e });
14871
+ return projection === 0 ? v : fn([v], new PlainSpan10(pos, EC.e));
14838
14872
  };
14839
14873
  }
14840
14874
  if (wantValues) {
@@ -14859,7 +14893,7 @@ function assemble(t2, prog, cfg) {
14859
14893
  const cur = step(k1, input, EC.e, ctx);
14860
14894
  if (cur < 0) return FAIL;
14861
14895
  EC.e = cur;
14862
- return projection === 0 ? v0 : projection === 1 ? TERMV : fn([v0, TERMV], { start: pos, end: cur });
14896
+ return projection === 0 ? v0 : projection === 1 ? TERMV : fn([v0, TERMV], new PlainSpan10(pos, cur));
14863
14897
  };
14864
14898
  }
14865
14899
  if (wantValues) {
@@ -14893,7 +14927,7 @@ function assemble(t2, prog, cfg) {
14893
14927
  cur = step(k2, input, cur, ctx);
14894
14928
  if (cur < 0) return FAIL;
14895
14929
  EC.e = cur;
14896
- return projection === 0 ? v0 : projection === 1 ? v1 : projection === 2 ? TERMV : fn([v0, v1, TERMV], { start: pos, end: cur });
14930
+ return projection === 0 ? v0 : projection === 1 ? v1 : projection === 2 ? TERMV : fn([v0, v1, TERMV], new PlainSpan10(pos, cur));
14897
14931
  };
14898
14932
  }
14899
14933
  if (wantValues) {
@@ -14990,7 +15024,7 @@ function assemble(t2, prog, cfg) {
14990
15024
  const cur = runDirectTerms(input, pos, ctx, values);
14991
15025
  if (cur < 0) return FAIL;
14992
15026
  EC.e = cur;
14993
- return projection >= 0 ? values[projection] : fn(values, { start: pos, end: cur });
15027
+ return projection >= 0 ? values[projection] : fn(values, new PlainSpan10(pos, cur));
14994
15028
  };
14995
15029
  }
14996
15030
  if (wantValues) {
@@ -15888,10 +15922,10 @@ function assemble(t2, prog, cfg) {
15888
15922
  return FAIL;
15889
15923
  }
15890
15924
  const value = regexValue ? input.slice(pos, end) : spec;
15891
- const leaf2 = { _tag: "leaf", value, span: { start: pos, end } };
15925
+ const leaf2 = new PlainLeaf9(value, new PlainSpan10(pos, end));
15892
15926
  const kids = [leaf2];
15893
15927
  const rawKids = [leaf2];
15894
- const span = { start: pos, end };
15928
+ const span = new PlainSpan10(pos, end);
15895
15929
  EC.e = end;
15896
15930
  const nd = build2(kids, void 0, span, rawKids, EMPTY_TL2, void 0);
15897
15931
  if (ctx._cstBuf !== void 0 || ctx._cstChildren !== void 0) {
@@ -15973,7 +16007,7 @@ function assemble(t2, prog, cfg) {
15973
16007
  const sCh = ctx._cstChildren;
15974
16008
  const sCap = ctx.captureTrivia;
15975
16009
  const sBuf = ctx._cstBuf;
15976
- const buf = rawOnly ? { rawOnly: true } : omitsRaw ? { noRaw: true, rawLen: 0 } : {};
16010
+ const buf = rawOnly ? new PlainBuf2(true, void 0, 0) : omitsRaw ? new PlainBuf2(void 0, true, 0) : new PlainBuf2(void 0, void 0, 0);
15977
16011
  ctx._cstBuf = buf;
15978
16012
  ctx.captureTrivia = captureWide;
15979
16013
  const savedFields = ctx._fields;
@@ -15995,7 +16029,7 @@ function assemble(t2, prog, cfg) {
15995
16029
  ctx.captureTrivia = sCap;
15996
16030
  if (v === FAIL) return FAIL;
15997
16031
  const end = EC.e;
15998
- const span = tracked ? spanLines(ctx, pos, end) : { start: pos, end };
16032
+ const span = tracked ? spanLines(ctx, pos, end) : new PlainSpan10(pos, end);
15999
16033
  const st = readsState ? ctx.state : void 0;
16000
16034
  let nd;
16001
16035
  if (unwrap && kids.length === 1) {
@@ -16019,7 +16053,7 @@ function assemble(t2, prog, cfg) {
16019
16053
  } else if (host !== void 0) {
16020
16054
  nd = host(type, hostKids, fieldMap, span, rawKids, tlog, st, tags);
16021
16055
  } else {
16022
- nd = { _tag: "node", type, span, state: st ?? null, children: kids };
16056
+ nd = new PlainNode2(type, span, st ?? null, kids === EMPTY_CH ? kids : [...kids]);
16023
16057
  }
16024
16058
  if (sBuf !== void 0 || sCh !== void 0) {
16025
16059
  pushCstChild(ctx, nd, rawEntry(nd, input, pos, end));
@@ -16045,7 +16079,7 @@ function assemble(t2, prog, cfg) {
16045
16079
  const at = fe === void 0 || fe < 0 ? pos : fe;
16046
16080
  return { ok: false, expected: ctx._fx ?? EMPTY_FX2, span: { start: at, end: at } };
16047
16081
  }
16048
- return { ok: true, value: v, span: { start: pos, end: EC.e } };
16082
+ return { ok: true, value: v, span: new PlainSpan10(pos, EC.e) };
16049
16083
  }
16050
16084
  };
16051
16085
  }
@@ -16160,7 +16194,12 @@ function assemble(t2, prog, cfg) {
16160
16194
  LEAD,
16161
16195
  triviaFieldCapture,
16162
16196
  skipDeferredTrivia,
16163
- collapseEmpty
16197
+ collapseEmpty,
16198
+ PlainSpan10,
16199
+ PlainLeaf9,
16200
+ PlainNode2,
16201
+ PlainField,
16202
+ PlainBuf2
16164
16203
  );
16165
16204
  emitReached = new Set(pre.reached);
16166
16205
  if (emitted.ext !== void 0) HYBRID = emitted;
@@ -16247,7 +16286,12 @@ function assemble(t2, prog, cfg) {
16247
16286
  LEAD,
16248
16287
  triviaFieldCapture,
16249
16288
  skipDeferredTrivia,
16250
- collapseEmpty
16289
+ collapseEmpty,
16290
+ PlainSpan10,
16291
+ PlainLeaf9,
16292
+ PlainNode2,
16293
+ PlainField,
16294
+ PlainBuf2
16251
16295
  );
16252
16296
  emitReached = em.reached;
16253
16297
  } catch (e) {
@@ -16505,7 +16549,11 @@ function tableRules(source, metadataOrEntry = {}) {
16505
16549
  return map[entry];
16506
16550
  }
16507
16551
 
16552
+ // src/version.ts
16553
+ var PARSEMAN_VERSION = "0.59.0";
16554
+
16508
16555
  // src/table/emit.ts
16556
+ var FACTORY_ARITY_GUARD = `if(arguments.length<${EMITTED_PARAMS.length})throw new Error(${JSON.stringify(`parseman: this parser was printed by parseman ${PARSEMAN_VERSION}; upgrade the parseman runtime to at least that version`)});`;
16509
16557
  function jsString(s) {
16510
16558
  return JSON.stringify(s);
16511
16559
  }
@@ -16580,7 +16628,7 @@ function emitAssemblies(prog, cfgs) {
16580
16628
  throw e;
16581
16629
  }
16582
16630
  const plan = em.plan;
16583
- out.push(`{key:${key},factory:function(${EMITTED_PARAMS.join(",")}){${em.source}
16631
+ out.push(`{key:${key},factory:function(${EMITTED_PARAMS.join(",")}){${FACTORY_ARITY_GUARD}${em.source}
16584
16632
  },plan:{classes:[${plan.classes.map((r) => `[${r.join(",")}]`).join(",")}],armExpected:[${plan.armExpected.map((r) => `[${r.join(",")}]`).join(",")}],masks:[${plan.masks.join(",")}]},reached:[${[...em.reached].join(",")}]}`);
16585
16633
  }
16586
16634
  return [`a:[${out.join(",")}],`];
@@ -18203,6 +18251,7 @@ function encodeForRun(ruleMap, opts) {
18203
18251
  }
18204
18252
 
18205
18253
  // src/compiler/linker.ts
18254
+ import { PlainNode as PlainNode3, PlainTaggedNode } from "../cst/plain.js";
18206
18255
  function normalizeCstCollapse(collapse) {
18207
18256
  if (collapse === true) return () => true;
18208
18257
  if (Array.isArray(collapse)) {
@@ -18212,7 +18261,7 @@ function normalizeCstCollapse(collapse) {
18212
18261
  return typeof collapse === "function" ? collapse : void 0;
18213
18262
  }
18214
18263
  function buildCstNode(type, children2, _fields, span, _rawChildren, _triviaLog, state, tags) {
18215
- return tags !== void 0 && tags.length > 0 ? { _tag: "node", type, tags, span: { ...span }, state: state ?? null, children: [...children2] } : { _tag: "node", type, span: { ...span }, state: state ?? null, children: [...children2] };
18264
+ return tags !== void 0 && tags.length > 0 ? new PlainTaggedNode(type, tags, copySpan(span), state ?? null, [...children2]) : new PlainNode3(type, copySpan(span), state ?? null, [...children2]);
18216
18265
  }
18217
18266
  function cstBuildHost(typeOrOptions, children2, _fields, span, rawChildren, triviaLog, state, _tags) {
18218
18267
  if (typeof typeOrOptions === "string") {