parseman 0.51.2 → 0.53.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 (98) hide show
  1. package/dist/analysis/commitment.d.ts.map +1 -1
  2. package/dist/analysis/diagnostics.js +411 -28
  3. package/dist/analysis/diagnostics.js.map +3 -3
  4. package/dist/cli/index.js +6162 -6372
  5. package/dist/cli/index.js.map +3 -3
  6. package/dist/combinators/attempt.d.ts +11 -1
  7. package/dist/combinators/attempt.d.ts.map +1 -1
  8. package/dist/combinators/map.d.ts.map +1 -1
  9. package/dist/combinators/node.d.ts +6 -2
  10. package/dist/combinators/node.d.ts.map +1 -1
  11. package/dist/combinators/parser.d.ts +34 -0
  12. package/dist/combinators/parser.d.ts.map +1 -1
  13. package/dist/combinators/ref.d.ts +0 -13
  14. package/dist/combinators/ref.d.ts.map +1 -1
  15. package/dist/compiler/borrowed-rules.d.ts +30 -0
  16. package/dist/compiler/borrowed-rules.d.ts.map +1 -0
  17. package/dist/compiler/compile-linkable-table.d.ts +1 -1
  18. package/dist/compiler/grammar-coverage-ids.d.ts.map +1 -1
  19. package/dist/compiler/ir-serialize.d.ts +10 -4
  20. package/dist/compiler/ir-serialize.d.ts.map +1 -1
  21. package/dist/compiler/linker.d.ts +48 -91
  22. package/dist/compiler/linker.d.ts.map +1 -1
  23. package/dist/compiler/token-capability.js +4 -0
  24. package/dist/compiler/token-capability.js.map +1 -1
  25. package/dist/coverage.d.ts +1 -1
  26. package/dist/coverage.d.ts.map +1 -1
  27. package/dist/cst/reflection.d.ts.map +1 -1
  28. package/dist/cst/trivia-kinds.d.ts.map +1 -1
  29. package/dist/index.d.ts +1 -0
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +470 -725
  32. package/dist/index.js.map +3 -3
  33. package/dist/language-service/index.js.map +1 -1
  34. package/dist/plugin/evaluator.d.ts +38 -2
  35. package/dist/plugin/evaluator.d.ts.map +1 -1
  36. package/dist/plugin/index.d.ts.map +1 -1
  37. package/dist/plugin/index.js +1127 -544
  38. package/dist/plugin/index.js.map +3 -3
  39. package/dist/plugin/ir-eval.d.ts +21 -0
  40. package/dist/plugin/ir-eval.d.ts.map +1 -0
  41. package/dist/plugin/reducer-resolver.d.ts +6 -0
  42. package/dist/plugin/reducer-resolver.d.ts.map +1 -1
  43. package/dist/spec/index.js +555 -6086
  44. package/dist/spec/index.js.map +3 -3
  45. package/dist/spec/railroad-lib.d.ts +7 -2
  46. package/dist/spec/railroad-lib.d.ts.map +1 -1
  47. package/dist/spec/railroad.d.ts.map +1 -1
  48. package/dist/table/assemble.d.ts.map +1 -1
  49. package/dist/table/compile-rule-map.d.ts +11 -4
  50. package/dist/table/compile-rule-map.d.ts.map +1 -1
  51. package/dist/table/compile.d.ts +16 -0
  52. package/dist/table/compile.d.ts.map +1 -1
  53. package/dist/table/emit-assembly.d.ts.map +1 -1
  54. package/dist/table/encode-baseline.d.ts.map +1 -1
  55. package/dist/table/exec.d.ts.map +1 -1
  56. package/dist/table/index.js +272 -102
  57. package/dist/table/index.js.map +2 -2
  58. package/dist/table/ops.d.ts +7 -5
  59. package/dist/table/ops.d.ts.map +1 -1
  60. package/dist/table/site-labels.d.ts.map +1 -1
  61. package/dist/types.d.ts +8 -1
  62. package/dist/types.d.ts.map +1 -1
  63. package/dist/version.d.ts +1 -1
  64. package/package.json +1 -1
  65. package/src/analysis/commitment.ts +3 -1
  66. package/src/analysis/rebuild.ts +1 -1
  67. package/src/combinators/attempt.ts +26 -3
  68. package/src/combinators/first-set.ts +5 -1
  69. package/src/combinators/map.ts +5 -1
  70. package/src/combinators/node.ts +12 -3
  71. package/src/combinators/parser.ts +133 -67
  72. package/src/combinators/ref.ts +10 -1
  73. package/src/compiler/borrowed-rules.ts +88 -0
  74. package/src/compiler/compile-linkable-table.ts +1 -1
  75. package/src/compiler/grammar-coverage-ids.ts +35 -6
  76. package/src/compiler/ir-serialize.ts +13 -119
  77. package/src/compiler/linker.ts +190 -666
  78. package/src/coverage.ts +7 -5
  79. package/src/cst/reflection.ts +6 -1
  80. package/src/cst/trivia-kinds.ts +6 -0
  81. package/src/index.ts +1 -0
  82. package/src/plugin/evaluator.ts +114 -14
  83. package/src/plugin/index.ts +588 -110
  84. package/src/plugin/ir-eval.ts +165 -0
  85. package/src/plugin/reducer-resolver.ts +20 -3
  86. package/src/spec/railroad-lib.ts +18 -8
  87. package/src/spec/railroad.ts +3 -4
  88. package/src/table/assemble.ts +22 -8
  89. package/src/table/compile-rule-map.ts +18 -8
  90. package/src/table/compile.ts +61 -0
  91. package/src/table/emit-assembly.ts +8 -3
  92. package/src/table/encode-baseline.ts +5 -1
  93. package/src/table/encode.ts +13 -13
  94. package/src/table/exec.ts +6 -2
  95. package/src/table/ops.ts +7 -5
  96. package/src/table/site-labels.ts +3 -1
  97. package/src/types.ts +8 -1
  98. package/src/version.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"emit-assembly.d.ts","sourceRoot":"","sources":["../../src/table/emit-assembly.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAS/C,OAAO,EAEL,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,KAAK,YAAY,EAC1D,MAAM,cAAc,CAAA;AAYrB,6EAA6E;AAC7E,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,KAAK,OAAO,CAAA;AACrF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;IAC7C,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,SAAS,CAAC,CAAA;IACvD,QAAQ,CAAC,GAAG,EAAE,MAAM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ACjB,KAAK,EAAE,OAAO,CAAA;CACf,EACD,QAAQ,GAAE,SAAS,MAAM,EAAO,EAChC,WAAW,UAAQ,GAClB,UAAU,CAo/DZ"}
@@ -1 +1 @@
1
- {"version":3,"file":"encode-baseline.d.ts","sourceRoot":"","sources":["../../src/table/encode-baseline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAuB,MAAM,aAAa,CAAA;AASlE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAQhD,8EAA8E;AAC9E,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,GAAG,KAAK,CAAA;IACjC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAC9B,CAAA;AAiTD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,EAC5C,QAAQ,GAAE,aAAkB,GAC3B,YAAY,CAId"}
1
+ {"version":3,"file":"encode-baseline.d.ts","sourceRoot":"","sources":["../../src/table/encode-baseline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAuB,MAAM,aAAa,CAAA;AASlE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAQhD,8EAA8E;AAC9E,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,GAAG,KAAK,CAAA;IACjC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAC9B,CAAA;AAqTD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,EAC5C,QAAQ,GAAE,aAAkB,GAC3B,YAAY,CAId"}
@@ -1 +1 @@
1
- {"version":3,"file":"exec.d.ts","sourceRoot":"","sources":["../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AAO,CAAC,CAAC,CAAA;IAChC;;;;;;;;;;;OAWG;IACH,cAAc,EAAE,MAAM,CAAA;IACtB,YAAY,EAAE,MAAM,CAAA;IACpB,sFAAsF;IACtF,eAAe,EAAE,MAAM,CAAA;IACvB,YAAY,EAAE,MAAM,CAAA;IACpB,qFAAqF;IACrF,YAAY,EAAE,MAAM,CAAA;CAC+H,CAAA;AAUrJ,wBAAgB,kBAAkB,IAAI,IAAI,CASzC;AA2kDD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,YAAY,GAAG,cAAc;AACrC;;;;;;;;GAQG;AACH,IAAI,GAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAO,EACjC,gBAAgB,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM,GACvD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CA8B3B"}
@@ -257,6 +257,10 @@ function firstSetBody(p, seen, resolve, activeTrivia) {
257
257
  case "node":
258
258
  case "sepBy":
259
259
  case "expect":
260
+ // A transaction accepts exactly what its inner accepts. Its own `_meta` is
261
+ // the inner's construction-time set, which reads `any` when the inner opens
262
+ // with a rule reference — resolve through it like any other wrapper.
263
+ case "attempt":
260
264
  return fs(d.parser);
261
265
  case "grammar":
262
266
  return firstSetOf(
@@ -1621,6 +1625,10 @@ function peelLabel(p) {
1621
1625
  return null;
1622
1626
  }
1623
1627
  function analyzeLabeledTrivia(trivia2) {
1628
+ if (trivia2._def.tag === "trivia") {
1629
+ const own = trivia2._meta.labeledTriviaSpec;
1630
+ if (own !== void 0) return own;
1631
+ }
1624
1632
  if (trivia2 === labeledTrivia0) return labeledSpec0;
1625
1633
  if (trivia2 === labeledTrivia1) return labeledSpec1;
1626
1634
  if (trivia2 === labeledTrivia2) return labeledSpec2;
@@ -3286,13 +3294,17 @@ function transform(combinator, fn) {
3286
3294
  };
3287
3295
  }
3288
3296
  function trivia(combinator) {
3289
- const kindLabels = analyzeLabeledTrivia(combinator)?.labels;
3297
+ const labeled = analyzeLabeledTrivia(combinator);
3298
+ const kindLabels = labeled?.labels;
3290
3299
  return {
3291
3300
  _tag: combinator._tag,
3292
3301
  _meta: {
3293
3302
  ...combinator._meta,
3294
3303
  isTrivia: true,
3295
3304
  triviaScanner: fastTriviaScanner(combinator),
3305
+ // Every labeled scan of this trivia reads its spec; the module's four-slot
3306
+ // memo alone thrashes on a grammar with more than four trivia tables.
3307
+ labeledTriviaSpec: labeled,
3296
3308
  ...kindLabels ? { triviaKindLabels: kindLabels } : {}
3297
3309
  },
3298
3310
  _def: { tag: "trivia", parser: combinator },
@@ -3380,6 +3392,7 @@ function withRuleTrivia(trivia2, ctx, run) {
3380
3392
  ctx.triviaKindLabels = savedLabels;
3381
3393
  }
3382
3394
  }
3395
+ var UNDEFINED_REF = new Error("ref<T>() used before .define() was called");
3383
3396
  function ref() {
3384
3397
  let resolved = null;
3385
3398
  let resolvedScalar = null;
@@ -3395,7 +3408,7 @@ function ref() {
3395
3408
  _def: {
3396
3409
  tag: "lazy",
3397
3410
  thunk: () => {
3398
- if (!resolved) throw new Error("ref<T>() used before .define() was called");
3411
+ if (!resolved) throw UNDEFINED_REF;
3399
3412
  return resolved;
3400
3413
  }
3401
3414
  },
@@ -6145,7 +6158,7 @@ function transfer(code, ip, at, hostCst) {
6145
6158
  }
6146
6159
  if (op === OP_NODE || op === OP_NODE_TRACK) {
6147
6160
  const flags = code[ip + 3];
6148
- const directChildren = !hostCst && op === OP_NODE && code[ip + 1] >= 0 && code[ip + 4] < 0 && (flags === 2 || flags === 18 || flags === 34);
6161
+ const directChildren = !hostCst && op === OP_NODE && code[ip + 1] >= 0 && code[ip + 4] < 0 && ((flags & ~128) === 2 || flags === 18 || flags === 34);
6149
6162
  if (directChildren) {
6150
6163
  return { tri: at.tri, buf: false, raw: RAW_UNKNOWN, cap: CAP_OFF };
6151
6164
  }
@@ -7349,7 +7362,7 @@ ${clean ? "" : emitMark(p, L.buf, L.raw, sinks)}
7349
7362
  const v=${child}(input,pos,ctx)
7350
7363
  if(v!==FAIL)return v
7351
7364
  ${clean ? "" : emitRollback(p, L.buf, L.raw, sinks)}
7352
- if(ctx._fc===true)return FAIL
7365
+ ${code[ip + 2] === 1 ? "ctx._fc=false" : "if(ctx._fc===true)return FAIL"}
7353
7366
  ctx._fe=pos
7354
7367
  return FAIL
7355
7368
  }`;
@@ -7938,7 +7951,8 @@ return nd
7938
7951
  const unwrap = (flags & 64) !== 0;
7939
7952
  const trailingTrivia = (flags & 128) !== 0;
7940
7953
  const build = buildIdx >= 0 ? fnRef(buildIdx) : void 0;
7941
- if (!hostCst && !tracked && build !== void 0 && proj < 0 && (flags === 2 || flags === 18 || flags === 34)) {
7954
+ const leanFlags = flags & ~128;
7955
+ if (!hostCst && !tracked && build !== void 0 && proj < 0 && (leanFlags === 2 || (flags === 18 || flags === 34))) {
7942
7956
  const fields = flags === 18;
7943
7957
  const collapseChildren = flags === 34;
7944
7958
  const publish = L.buf && L.raw === RAW_OMIT ? "_pushNodeNoRawBuf(ctx,nd)" : L.buf && L.raw === RAW_CAPTURE ? `if(sBuf!==undefined){
@@ -7983,7 +7997,8 @@ ctx._cstTriviaLog=undefined
7983
7997
  ctx.captureTrivia=false
7984
7998
  ctx._fields=${fields ? "[]" : "undefined"}
7985
7999
  const v=${child}(input,pos,ctx)
7986
- const captured=_capturedFlatChildren(flat)
8000
+ ${trailingTrivia && L.tri !== TRI_NONE ? `if(v!==FAIL${L.tri === TRI_UNKNOWN ? "&&ctx.trivia!==undefined" : ""})EC.e=consumeTrivia(input,EC.e,ctx)
8001
+ ` : ""}const captured=_capturedFlatChildren(flat)
7987
8002
  ${fields ? "const fieldMap=buildFieldMap(ctx._fields)\n" : ""}ctx._fields=sFields
7988
8003
  ctx._cstBuf=sBuf
7989
8004
  ctx._cstChildren=sCh
@@ -8379,7 +8394,7 @@ function assemble(t, prog, cfg) {
8379
8394
  const lf = { _tag: "leaf", value, span: { start: s, end: e } };
8380
8395
  pushCstLeaf(ctx, lf);
8381
8396
  }
8382
- function plainBuildNode(child, build) {
8397
+ function plainBuildNode(child, build, trailing) {
8383
8398
  return (input, pos, ctx) => {
8384
8399
  const sCh = ctx._cstChildren;
8385
8400
  const sLv = ctx._cstLeaves;
@@ -8397,6 +8412,7 @@ function assemble(t, prog, cfg) {
8397
8412
  ctx.captureTrivia = false;
8398
8413
  ctx._fields = void 0;
8399
8414
  const value = child(input, pos, ctx);
8415
+ if (trailing && value !== FAIL && ctx.trivia !== void 0) EC.e = consumeTrivia(input, EC.e, ctx);
8400
8416
  const kids = buf.ch ?? (buf.single !== void 0 ? [buf.single] : EMPTY_CH);
8401
8417
  const rawKids = buf.raw ?? (buf.rawSingle !== void 0 ? [buf.rawSingle] : EMPTY_CH);
8402
8418
  ctx._fields = savedFields;
@@ -8424,7 +8440,7 @@ function assemble(t, prog, cfg) {
8424
8440
  while (first < children2.length && children2[first] === void 0) first++;
8425
8441
  return first === children2.length ? EMPTY_CH : children2.slice(first);
8426
8442
  }
8427
- function childrenOnlyBuildNode(child, build) {
8443
+ function childrenOnlyBuildNode(child, build, trailing) {
8428
8444
  return (input, pos, ctx) => {
8429
8445
  const sCh = ctx._cstChildren;
8430
8446
  const sLv = ctx._cstLeaves;
@@ -8442,6 +8458,7 @@ function assemble(t, prog, cfg) {
8442
8458
  ctx.captureTrivia = false;
8443
8459
  ctx._fields = void 0;
8444
8460
  const value = child(input, pos, ctx);
8461
+ if (trailing && value !== FAIL && ctx.trivia !== void 0) EC.e = consumeTrivia(input, EC.e, ctx);
8445
8462
  const captured = capturedFlatChildren(kids);
8446
8463
  ctx._fields = savedFields;
8447
8464
  ctx._cstBuf = sBuf;
@@ -9466,6 +9483,7 @@ function assemble(t, prog, cfg) {
9466
9483
  /* ── transaction ─────────────────────────────────────────────────────── */
9467
9484
  case OP_ATTEMPT: {
9468
9485
  const child = link(code[ip + 1]);
9486
+ const contain = code[ip + 2] === 1;
9469
9487
  return (input, pos, ctx) => {
9470
9488
  const need = markCst(ctx);
9471
9489
  const mRaw = MRAW;
@@ -9478,7 +9496,10 @@ function assemble(t, prog, cfg) {
9478
9496
  const v = child(input, pos, ctx);
9479
9497
  if (v !== FAIL) return v;
9480
9498
  if (need) rollbackTriviaAt(ctx, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot);
9481
- if (committed3(ctx)) return FAIL;
9499
+ if (committed3(ctx)) {
9500
+ if (!contain) return FAIL;
9501
+ ctx._fc = false;
9502
+ }
9482
9503
  ctx._fe = pos;
9483
9504
  return FAIL;
9484
9505
  };
@@ -10929,11 +10950,11 @@ function assemble(t, prog, cfg) {
10929
10950
  const trailingTrivia = (flags & 128) !== 0;
10930
10951
  const build = buildIdx >= 0 ? fns[buildIdx] : void 0;
10931
10952
  if (!hostCst && !tracked) {
10932
- if (build !== void 0 && proj < 0 && flags === 0) {
10933
- return plainBuildNode(child, build);
10953
+ if (build !== void 0 && proj < 0 && (flags & ~128) === 0) {
10954
+ return plainBuildNode(child, build, trailingTrivia);
10934
10955
  }
10935
- if (build !== void 0 && proj < 0 && flags === 2) {
10936
- return childrenOnlyBuildNode(child, build);
10956
+ if (build !== void 0 && proj < 0 && (flags & ~128) === 2) {
10957
+ return childrenOnlyBuildNode(child, build, trailingTrivia);
10937
10958
  }
10938
10959
  if (build !== void 0 && proj < 0 && flags === 18) {
10939
10960
  return childrenOnlyFieldsBuildNode(child, build);
@@ -11811,10 +11832,12 @@ function mayCommitFailure(p, seen = /* @__PURE__ */ new Set(), resolve) {
11811
11832
  case "choice":
11812
11833
  case "sequence":
11813
11834
  return d.parsers.some((x) => mayCommitFailure(x, seen, resolve));
11835
+ // A contained transaction reports every failure uncommitted.
11836
+ case "attempt":
11837
+ return d.contain !== true && mayCommitFailure(d.parser, seen, resolve);
11814
11838
  case "many":
11815
11839
  case "oneOrMore":
11816
11840
  case "optional":
11817
- case "attempt":
11818
11841
  case "transform":
11819
11842
  case "label":
11820
11843
  case "field":
@@ -13158,7 +13181,7 @@ var Encoder = class {
13158
13181
  const derivedState = d.build !== void 0 ? buildReadsState(d) : noBuildCaptures;
13159
13182
  const derivedFields = d.build !== void 0 ? buildReadsFields(d) : noBuildCaptures;
13160
13183
  const wantsFields = parserHasOwnFields(d.parser) && (cstOut || derivedFields);
13161
- const flags = (cstOut || d.captureTrivia === true || d.trailingTrivia === true || derivedTrivia ? 4 : 0) | (!cstOut && omitsRaw ? 2 : 0) | (cstOut || derivedState ? 8 : 0) | (wantsFields ? 16 : 0) | (d.collapse === true ? 32 : 0) | (d.unwrap === true ? 64 : 0) | (d.trailingTrivia === true ? 128 : 0) | (d.captureTrivia === true ? 1 : 0);
13184
+ const flags = (cstOut || d.captureTrivia === true || derivedTrivia ? 4 : 0) | (!cstOut && omitsRaw ? 2 : 0) | (cstOut || derivedState ? 8 : 0) | (wantsFields ? 16 : 0) | (d.collapse === true ? 32 : 0) | (d.unwrap === true ? 64 : 0) | (d.trailingTrivia === true ? 128 : 0) | (d.captureTrivia === true ? 1 : 0);
13162
13185
  const body = this.emit(
13163
13186
  this.track ? OP_NODE_TRACK : OP_NODE,
13164
13187
  d.build === void 0 ? -1 : this.fn(d.build, d.buildSrc ?? null),
@@ -13284,7 +13307,7 @@ var Encoder = class {
13284
13307
  // A TRANSACTION IS A ROW. See `OP_ATTEMPT` for why the transparent
13285
13308
  // lowering was correct only for a choice arm.
13286
13309
  case "attempt": {
13287
- const inner = this.emit(OP_ATTEMPT, this.node(d.parser).ip);
13310
+ const inner = this.emit(OP_ATTEMPT, this.node(d.parser).ip, d.contain === true ? 1 : 0);
13288
13311
  if (!this.failureNeedsRollback(d.parser, void 0)) this.failureRollbackCleanSites.add(inner);
13289
13312
  const fs = d.parser._def.tag === "lazy" ? firstSetOf(d.parser, /* @__PURE__ */ new Set(), this.refResolver(), this.activeTrivia) : d.parser._meta.firstSet;
13290
13313
  if (fs.kind === "any" || matchesEmpty(d.parser)) return inner;
@@ -13779,7 +13802,8 @@ function children(def, winners) {
13779
13802
  return [];
13780
13803
  }
13781
13804
  const name = resolved._ruleName;
13782
- return name && winners?.[name] ? [winners[name]] : [resolved];
13805
+ const winner = name ? winners?.[name] : void 0;
13806
+ return winner !== void 0 && winner._def !== def ? [winner] : [resolved];
13783
13807
  }
13784
13808
  default:
13785
13809
  return [];
@@ -13804,16 +13828,39 @@ function buildGrammarPlan(entry, winners) {
13804
13828
  }
13805
13829
  }
13806
13830
  }
13831
+ const selfWinnerBody = (parser) => {
13832
+ if (parser._def.tag !== "lazy" || winners === void 0) return void 0;
13833
+ const name = winnerNames.get(parser);
13834
+ if (name === void 0 || winners[name] !== parser) return void 0;
13835
+ try {
13836
+ return parser._def.thunk();
13837
+ } catch {
13838
+ return void 0;
13839
+ }
13840
+ };
13841
+ const slotsPerBody = /* @__PURE__ */ new Map();
13842
+ if (winners) {
13843
+ for (const winner of Object.values(winners)) {
13844
+ const body = selfWinnerBody(winner);
13845
+ if (body !== void 0) slotsPerBody.set(body, (slotsPerBody.get(body) ?? 0) + 1);
13846
+ }
13847
+ }
13848
+ const sharedBody = (parser) => (slotsPerBody.get(parser) ?? 0) > 1;
13849
+ const ownRule = (parser, rule) => {
13850
+ const id = `rule:${rule}`;
13851
+ definitions.set(id, { id, kind: "rule" });
13852
+ rules.set(parser, id);
13853
+ };
13807
13854
  const seen = /* @__PURE__ */ new Set();
13808
13855
  const visit = (parser, path) => {
13809
13856
  if (seen.has(parser)) return;
13810
13857
  seen.add(parser);
13811
13858
  const rule = winnerNames.get(parser) ?? parser._ruleName;
13812
- if (rule && (winnerNames.has(parser) || parser._def.tag !== "lazy")) {
13813
- const id = `rule:${rule}`;
13814
- definitions.set(id, { id, kind: "rule" });
13815
- rules.set(parser, id);
13859
+ const body = selfWinnerBody(parser);
13860
+ if (rule && body === void 0 && !sharedBody(parser) && (winnerNames.has(parser) || parser._def.tag !== "lazy")) {
13861
+ ownRule(parser, rule);
13816
13862
  }
13863
+ if (rule && body !== void 0 && sharedBody(body)) ownRule(parser, rule);
13817
13864
  if (parser._def.tag === "choice") {
13818
13865
  const ids = parser._def.parsers.map((_, index) => `choice:${path}/arm:${index}`);
13819
13866
  choices.set(parser, ids);
@@ -13834,7 +13881,13 @@ function buildGrammarPlan(entry, winners) {
13834
13881
  };
13835
13882
  const roots = Array.isArray(entry) ? entry : [entry];
13836
13883
  for (const root of roots) {
13837
- visit(root, winnerNames.get(root) ?? root._ruleName ?? "entry");
13884
+ const name = winnerNames.get(root) ?? root._ruleName ?? "entry";
13885
+ const body = selfWinnerBody(root);
13886
+ if (body !== void 0 && sharedBody(body) && !seen.has(root)) {
13887
+ seen.add(root);
13888
+ ownRule(root, name);
13889
+ }
13890
+ visit(body ?? root, name);
13838
13891
  }
13839
13892
  return { definitions: [...definitions.values()].sort((a, b) => a.id.localeCompare(b.id)), choices, dispatches, attempts, labels, rules };
13840
13893
  }
@@ -15140,84 +15193,8 @@ function runDuplicationDiagnosticRules(ruleMap, opt) {
15140
15193
  return reportDuplication(opt, (o) => analyzeDuplicationRules(ruleMap, o));
15141
15194
  }
15142
15195
 
15143
- // src/table/compile.ts
15144
- var ENTRY = "Entry";
15145
- function ownSource(fn) {
15146
- if (typeof fn !== "function") return null;
15147
- const text = Function.prototype.toString.call(fn);
15148
- if (!text.includes("[native code]")) return text;
15149
- const name = fn.name;
15150
- return typeof name === "string" && name.length > 0 && globalThis[name] === fn ? name : null;
15151
- }
15152
- function compile(combinator, mapFnSources, opts = {}) {
15153
- runDuplicationDiagnostic(combinator, opts.duplication);
15154
- const drain = beginCompileDegradationDrain();
15155
- let compiled = false;
15156
- try {
15157
- const out = compileImpl(combinator, mapFnSources, opts);
15158
- compiled = true;
15159
- return out;
15160
- } finally {
15161
- drain(compiled);
15162
- }
15163
- }
15164
- function compileImpl(combinator, mapFnSources, opts = {}) {
15165
- const plan = opts.coverage === true ? buildGrammarPlan(combinator) : void 0;
15166
- const settings = {
15167
- ...opts.hostMode === void 0 ? {} : { hostMode: opts.hostMode },
15168
- ...opts.trackLines === void 0 ? {} : { trackLines: opts.trackLines },
15169
- ...plan === void 0 ? {} : { coverage: plan }
15170
- };
15171
- const { prog, fnSrcs } = encodeTableProgram({ [ENTRY]: combinator }, settings);
15172
- const artifact = closureArtifact(prog);
15173
- const entry = tableRules(prog)[ENTRY];
15174
- const offered = opts.fnSources ?? mapFnSources;
15175
- const supplied = offered !== void 0 && offered.length === fnSrcs.length ? offered : void 0;
15176
- const sources = fnSrcs.map((s, i) => s ?? supplied?.[i] ?? ownSource(prog.fns[i]));
15177
- const unsourced = sources.reduce((acc, s, i) => s === null ? [...acc, i] : acc, []);
15178
- const runtimeOnly = [
15179
- ...prog.runtimeOnly ?? [],
15180
- ...unsourced.length === 0 ? [] : [`author reducer source missing for prog.fns[${unsourced.join(", ")}] \u2014 printing would emit \`() => {}\` and the parse would return no value`]
15181
- ];
15182
- const printable = runtimeOnly.length === 0;
15183
- const emitOpts = { fnSources: sources };
15184
- const source = printable ? emitTableModule(artifact, { name: "grammar", ...emitOpts }) : "";
15185
- const inlineExpression = printable ? emitTableExpression(artifact, { entry: ENTRY, runtimeRef: opts.runtimeRef ?? "tableRules", ...emitOpts }) : null;
15186
- const runOnce = (input, pos, ctx) => entry(input, pos, ctx);
15187
- return {
15188
- source,
15189
- inlineExpression,
15190
- ...printable ? {} : { runtimeOnly },
15191
- // The DENOMINATOR, handed back rather than scraped out of the emitted text.
15192
- // `plugin/index.ts` prefers a compiler-supplied `coverageDefinitions` and only
15193
- // falls back to regex-scanning generated hooks; a table has no hooks to scan,
15194
- // so this is the channel.
15195
- ...plan === void 0 ? {} : { coverageDefinitions: plan.definitions },
15196
- parse(input, pos = 0) {
15197
- return runOnce(input, pos, createParseContext());
15198
- },
15199
- parseWithContext(input, parseCtx, pos = 0) {
15200
- return runOnce(input, pos, parseCtx);
15201
- },
15202
- /**
15203
- * NO LONGER REFUSES. It used to throw unless the caller passed
15204
- * `{ recovery: true }`, because setting `_tolerant` on a table with no
15205
- * recovery rows would report a clean parse with an empty error list whatever
15206
- * the input — refusing was the right answer to that, and OPTIONAL RECOVERY
15207
- * was the wrong question. `compile()` requires no such flag, so the refusal
15208
- * was a `CompiledParser` contract break; recovery is now always lowered and
15209
- * there is nothing left to refuse.
15210
- */
15211
- parseWithErrors(input, pos = 0) {
15212
- const ctx = createParseContext();
15213
- const errors = [];
15214
- ctx._errors = errors;
15215
- ctx._tolerant = true;
15216
- const r = runOnce(input, pos, ctx);
15217
- return { ...r, errors };
15218
- }
15219
- };
15220
- }
15196
+ // src/cst/reflection-symbols.ts
15197
+ var GRAMMAR_REFLECTION = /* @__PURE__ */ Symbol.for("parseman.grammarReflection");
15221
15198
 
15222
15199
  // src/cst/reflection.ts
15223
15200
  function childrenOf2(def) {
@@ -15304,6 +15281,7 @@ function collectFromCombinator(parser, out, seen, followLazy = true) {
15304
15281
  function collectGrammarReflection(ruleMap, opts) {
15305
15282
  const byType = /* @__PURE__ */ new Map();
15306
15283
  const followLazy = opts?.followLazy !== false;
15284
+ const seen = /* @__PURE__ */ new Set();
15307
15285
  for (const [, rule] of ruleMap) {
15308
15286
  if (!followLazy && rule._def.tag === "lazy") {
15309
15287
  try {
@@ -15313,7 +15291,7 @@ function collectGrammarReflection(ruleMap, opts) {
15313
15291
  }
15314
15292
  continue;
15315
15293
  }
15316
- collectFromCombinator(rule, byType, /* @__PURE__ */ new Set(), followLazy);
15294
+ collectFromCombinator(rule, byType, seen, followLazy);
15317
15295
  }
15318
15296
  return { nodes: [...byType].map(([type, tags]) => ({ type, tags })) };
15319
15297
  }
@@ -15349,6 +15327,24 @@ function withAmbient(ruleMap, opts) {
15349
15327
  return [name, wrapped];
15350
15328
  });
15351
15329
  }
15330
+ function compileRuleMapRunnable(ruleMap, opts = {}) {
15331
+ const encoded = encodeForRun(ruleMap, opts);
15332
+ if (encoded === null) return null;
15333
+ const { prog, hostMode, plan } = encoded;
15334
+ const artifact = closureArtifact(prog);
15335
+ const reflection = collectGrammarReflection(ruleMap);
15336
+ return {
15337
+ keys: ruleMap.map(([key]) => key),
15338
+ hostMode,
15339
+ hostBranchElided: hostMode === "ast" && ruleMap.some(([, rule]) => hasDirectBuildDef(rule)),
15340
+ reflection,
15341
+ ...plan === void 0 ? {} : { coverageDefinitions: plan.definitions },
15342
+ // Reflection rides on the map's metadata prototype from birth. Only `compile()`
15343
+ // asks to specialise; every other caller runs the closure artifact.
15344
+ rules: tableRules(opts.specialise === true ? prog : artifact, { [GRAMMAR_REFLECTION]: reflection }),
15345
+ prog: artifact
15346
+ };
15347
+ }
15352
15348
  function encodeForRun(ruleMap, opts) {
15353
15349
  runDuplicationDiagnosticRules(ruleMap, opts.duplication);
15354
15350
  const encodeMap = withAmbient(ruleMap, opts);
@@ -15417,11 +15413,185 @@ function compileRuleMap(ruleMap, opts = {}) {
15417
15413
  hostBranchElided: hostMode === "ast" && ruleMap.some(([, rule]) => hasDirectBuildDef(rule)),
15418
15414
  reflection: collectGrammarReflection(ruleMap),
15419
15415
  ...plan === void 0 ? {} : { coverageDefinitions: plan.definitions },
15420
- rules: tableRules(prog),
15416
+ rules: tableRules(artifact),
15421
15417
  prog: artifact
15422
15418
  };
15423
15419
  }
15424
15420
 
15421
+ // src/compiler/borrowed-rules.ts
15422
+ var nameOf = (c) => c._ruleName;
15423
+ function deref(c) {
15424
+ const seen = /* @__PURE__ */ new Set();
15425
+ let current = c;
15426
+ while (current._def.tag === "lazy" && !seen.has(current)) {
15427
+ seen.add(current);
15428
+ try {
15429
+ current = current._def.thunk();
15430
+ } catch {
15431
+ return void 0;
15432
+ }
15433
+ }
15434
+ return current;
15435
+ }
15436
+ function borrowedRuleReference(map) {
15437
+ const seen = /* @__PURE__ */ new Set();
15438
+ for (const [rule, self] of Object.entries(map)) {
15439
+ let found;
15440
+ const visit = (c) => {
15441
+ if (found !== void 0) return;
15442
+ if (c._def.tag === "lazy") {
15443
+ if (!winnerWrapsReference(self, c)) {
15444
+ const name = nameOf(c);
15445
+ const winner = name !== void 0 && Object.hasOwn(map, name) ? map[name] : void 0;
15446
+ if (winner !== void 0) {
15447
+ if (winnerWrapsReference(winner, c) || deref(c) === deref(winner)) return;
15448
+ found = name;
15449
+ return;
15450
+ }
15451
+ }
15452
+ if (seen.has(c)) return;
15453
+ seen.add(c);
15454
+ let body;
15455
+ try {
15456
+ body = c._def.thunk();
15457
+ } catch {
15458
+ return;
15459
+ }
15460
+ visit(body);
15461
+ return;
15462
+ }
15463
+ if (seen.has(c)) return;
15464
+ seen.add(c);
15465
+ for (const child of childrenOf(c._def)) visit(child);
15466
+ };
15467
+ visit(self);
15468
+ if (found !== void 0) return { rule, reference: found };
15469
+ }
15470
+ return void 0;
15471
+ }
15472
+ function borrowedRuleMessage(api, hit) {
15473
+ return `${api}: rule "${hit.rule}" is a rule object borrowed from another grammar, and its graph references "${hit.reference}", which this grammar also defines. The interpreter would keep the other grammar's "${hit.reference}" while a compiled table binds this grammar's, so the two would accept different input. Compose the grammar that defines "${hit.rule}" instead of borrowing its rule object, so its references resolve to this grammar's rules.`;
15474
+ }
15475
+
15476
+ // src/table/compile.ts
15477
+ var ENTRY = "Entry";
15478
+ function ownSource(fn) {
15479
+ if (typeof fn !== "function") return null;
15480
+ const text = Function.prototype.toString.call(fn);
15481
+ if (!text.includes("[native code]")) return text;
15482
+ const name = fn.name;
15483
+ return typeof name === "string" && name.length > 0 && globalThis[name] === fn ? name : null;
15484
+ }
15485
+ function compile(target, second, third) {
15486
+ if (!isCombinator(target)) return compileMap(target, second);
15487
+ return compileRoot(target, second, third);
15488
+ }
15489
+ function isCombinator(x) {
15490
+ return typeof x === "object" && x !== null && typeof x.parse === "function" && "_def" in x;
15491
+ }
15492
+ function compileMap(grammar, opts = {}) {
15493
+ const entries = [];
15494
+ for (const [key, value] of Object.entries(grammar)) {
15495
+ if (!isCombinator(value)) throw new TypeError(`compile: grammar entry "${key}" is not a parser`);
15496
+ if (value._def.tag === "lazy") {
15497
+ try {
15498
+ value._def.thunk();
15499
+ } catch {
15500
+ continue;
15501
+ }
15502
+ }
15503
+ entries.push([key, value]);
15504
+ }
15505
+ const borrowed = borrowedRuleReference(Object.fromEntries(entries));
15506
+ if (borrowed !== void 0) throw new Error(borrowedRuleMessage("compile", borrowed));
15507
+ const drain = beginCompileDegradationDrain();
15508
+ let done = false;
15509
+ try {
15510
+ const refusals = [];
15511
+ const compiled = compileRuleMapRunnable(entries, {
15512
+ ...opts.hostMode ? { hostMode: opts.hostMode } : {},
15513
+ refusals,
15514
+ specialise: true
15515
+ });
15516
+ if (compiled === null) {
15517
+ throw new Error(`compile: this grammar could not be encoded to a table${refusals.length ? ` \u2014 ${refusals.join("; ")}` : ""}`);
15518
+ }
15519
+ done = true;
15520
+ return compiled.rules;
15521
+ } finally {
15522
+ drain(done);
15523
+ }
15524
+ }
15525
+ function compileRoot(combinator, mapFnSources, opts = {}) {
15526
+ runDuplicationDiagnostic(combinator, opts.duplication);
15527
+ const drain = beginCompileDegradationDrain();
15528
+ let compiled = false;
15529
+ try {
15530
+ const out = compileImpl(combinator, mapFnSources, opts);
15531
+ compiled = true;
15532
+ return out;
15533
+ } finally {
15534
+ drain(compiled);
15535
+ }
15536
+ }
15537
+ function compileImpl(combinator, mapFnSources, opts = {}) {
15538
+ const plan = opts.coverage === true ? buildGrammarPlan(combinator) : void 0;
15539
+ const settings = {
15540
+ ...opts.hostMode === void 0 ? {} : { hostMode: opts.hostMode },
15541
+ ...opts.trackLines === void 0 ? {} : { trackLines: opts.trackLines },
15542
+ ...plan === void 0 ? {} : { coverage: plan }
15543
+ };
15544
+ const { prog, fnSrcs } = encodeTableProgram({ [ENTRY]: combinator }, settings);
15545
+ const artifact = closureArtifact(prog);
15546
+ const entry = tableRules(prog)[ENTRY];
15547
+ const offered = opts.fnSources ?? mapFnSources;
15548
+ const supplied = offered !== void 0 && offered.length === fnSrcs.length ? offered : void 0;
15549
+ const sources = fnSrcs.map((s, i) => s ?? supplied?.[i] ?? ownSource(prog.fns[i]));
15550
+ const unsourced = sources.reduce((acc, s, i) => s === null ? [...acc, i] : acc, []);
15551
+ const runtimeOnly = [
15552
+ ...prog.runtimeOnly ?? [],
15553
+ ...unsourced.length === 0 ? [] : [`author reducer source missing for prog.fns[${unsourced.join(", ")}] \u2014 printing would emit \`() => {}\` and the parse would return no value`]
15554
+ ];
15555
+ const printable = runtimeOnly.length === 0;
15556
+ const emitOpts = { fnSources: sources };
15557
+ const source = printable ? emitTableModule(artifact, { name: "grammar", ...emitOpts }) : "";
15558
+ const inlineExpression = printable ? emitTableExpression(artifact, { entry: ENTRY, runtimeRef: opts.runtimeRef ?? "tableRules", ...emitOpts }) : null;
15559
+ const runOnce = (input, pos, ctx) => entry(input, pos, ctx);
15560
+ return {
15561
+ source,
15562
+ inlineExpression,
15563
+ ...printable ? {} : { runtimeOnly },
15564
+ // The DENOMINATOR, handed back rather than scraped out of the emitted text.
15565
+ // `plugin/index.ts` prefers a compiler-supplied `coverageDefinitions` and only
15566
+ // falls back to regex-scanning generated hooks; a table has no hooks to scan,
15567
+ // so this is the channel.
15568
+ ...plan === void 0 ? {} : { coverageDefinitions: plan.definitions },
15569
+ parse(input, pos = 0) {
15570
+ return runOnce(input, pos, createParseContext());
15571
+ },
15572
+ parseWithContext(input, parseCtx, pos = 0) {
15573
+ return runOnce(input, pos, parseCtx);
15574
+ },
15575
+ /**
15576
+ * NO LONGER REFUSES. It used to throw unless the caller passed
15577
+ * `{ recovery: true }`, because setting `_tolerant` on a table with no
15578
+ * recovery rows would report a clean parse with an empty error list whatever
15579
+ * the input — refusing was the right answer to that, and OPTIONAL RECOVERY
15580
+ * was the wrong question. `compile()` requires no such flag, so the refusal
15581
+ * was a `CompiledParser` contract break; recovery is now always lowered and
15582
+ * there is nothing left to refuse.
15583
+ */
15584
+ parseWithErrors(input, pos = 0) {
15585
+ const ctx = createParseContext();
15586
+ const errors = [];
15587
+ ctx._errors = errors;
15588
+ ctx._tolerant = true;
15589
+ const r = runOnce(input, pos, ctx);
15590
+ return { ...r, errors };
15591
+ }
15592
+ };
15593
+ }
15594
+
15425
15595
  // src/table/fold.ts
15426
15596
  function tableVariants(source, name) {
15427
15597
  const folded = "base" in source ? source : expandCompactFolded(source);