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":"commitment.d.ts","sourceRoot":"","sources":["../../src/analysis/commitment.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,EAAE,UAAU,EAAa,MAAM,aAAa,CAAA;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAI9D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI,GAAE,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAa,GAAG,OAAO,CAqCnG;AAkCD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI,GAAE,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAa,GAAG,OAAO,CAiC1G;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI,GAAE,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAa,EAAE,YAAY,UAAO,GAAG,OAAO,CAwGvI;AAED,8EAA8E;AAC9E,wBAAgB,YAAY,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI,GAAE,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAa,GAAG,OAAO,CAkDxG;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI,GAAE,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAa,GAAG,OAAO,CAgCtG;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI,GAAE,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAa,GAAG,OAAO,CAqC7G;AAED,2FAA2F;AAC3F,wBAAgB,gBAAgB,CAC9B,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EACtB,IAAI,GAAE,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAa,EAC1C,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CA6CT;AAwCD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,GAC7D;IAAE,iBAAiB,EAAE,OAAO,CAAC;IAAC,iBAAiB,EAAE,OAAO,CAAA;CAAE,CAwB5D"}
1
+ {"version":3,"file":"commitment.d.ts","sourceRoot":"","sources":["../../src/analysis/commitment.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,EAAE,UAAU,EAAa,MAAM,aAAa,CAAA;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAI9D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI,GAAE,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAa,GAAG,OAAO,CAqCnG;AAkCD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI,GAAE,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAa,GAAG,OAAO,CAiC1G;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI,GAAE,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAa,EAAE,YAAY,UAAO,GAAG,OAAO,CAwGvI;AAED,8EAA8E;AAC9E,wBAAgB,YAAY,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI,GAAE,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAa,GAAG,OAAO,CAkDxG;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI,GAAE,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAa,GAAG,OAAO,CAgCtG;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI,GAAE,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAa,GAAG,OAAO,CAqC7G;AAED,2FAA2F;AAC3F,wBAAgB,gBAAgB,CAC9B,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EACtB,IAAI,GAAE,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAa,EAC1C,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CA+CT;AAwCD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,GAC7D;IAAE,iBAAiB,EAAE,OAAO,CAAC;IAAC,iBAAiB,EAAE,OAAO,CAAA;CAAE,CAwB5D"}
@@ -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(
@@ -1291,6 +1295,10 @@ function peelLabel(p) {
1291
1295
  return null;
1292
1296
  }
1293
1297
  function analyzeLabeledTrivia(trivia2) {
1298
+ if (trivia2._def.tag === "trivia") {
1299
+ const own = trivia2._meta.labeledTriviaSpec;
1300
+ if (own !== void 0) return own;
1301
+ }
1294
1302
  if (trivia2 === labeledTrivia0) return labeledSpec0;
1295
1303
  if (trivia2 === labeledTrivia1) return labeledSpec1;
1296
1304
  if (trivia2 === labeledTrivia2) return labeledSpec2;
@@ -3244,6 +3252,53 @@ function hasNodeDef(p, seen = /* @__PURE__ */ new Set()) {
3244
3252
  return false;
3245
3253
  }
3246
3254
  }
3255
+ function hasDirectBuildDef(p, seen = /* @__PURE__ */ new Set()) {
3256
+ if (seen.has(p)) return false;
3257
+ seen.add(p);
3258
+ const d = p._def;
3259
+ switch (d.tag) {
3260
+ case "node":
3261
+ return d.build !== void 0 || hasDirectBuildDef(d.parser, seen);
3262
+ case "lazy": {
3263
+ try {
3264
+ return hasDirectBuildDef(d.thunk(), seen);
3265
+ } catch {
3266
+ return false;
3267
+ }
3268
+ }
3269
+ case "grammar":
3270
+ case "trivia":
3271
+ case "token":
3272
+ case "leaf":
3273
+ case "label":
3274
+ case "field":
3275
+ case "optional":
3276
+ case "many":
3277
+ case "oneOrMore":
3278
+ case "attempt":
3279
+ case "not":
3280
+ case "peek":
3281
+ case "withCtx":
3282
+ case "expect":
3283
+ case "transform":
3284
+ return hasDirectBuildDef(d.parser, seen);
3285
+ case "sequence":
3286
+ case "choice":
3287
+ return d.parsers.some((x) => hasDirectBuildDef(x, seen));
3288
+ case "dispatch":
3289
+ return hasDirectBuildDef(d.selector, seen) || d.cases.some((x) => hasDirectBuildDef(x.parser, seen)) || (d.matchers ? d.matchers.some((x) => hasDirectBuildDef(x.parser, seen)) : false) || (d.otherwise ? hasDirectBuildDef(d.otherwise, seen) : false);
3290
+ case "sepBy":
3291
+ return hasDirectBuildDef(d.parser, seen) || hasDirectBuildDef(d.separator, seen);
3292
+ case "scanTo":
3293
+ return hasDirectBuildDef(d.sentinel, seen) || d.skip.some((x) => hasDirectBuildDef(x, seen)) || d.recoverAt !== void 0 && hasDirectBuildDef(d.recoverAt, seen) || d.stopAt !== void 0 && hasDirectBuildDef(d.stopAt, seen);
3294
+ case "recover":
3295
+ return hasDirectBuildDef(d.parser, seen) || hasDirectBuildDef(d.sentinel, seen);
3296
+ case "routed":
3297
+ return d.fallback ? hasDirectBuildDef(d.fallback, seen) : false;
3298
+ default:
3299
+ return false;
3300
+ }
3301
+ }
3247
3302
  function mayCommitFailure(p, seen = /* @__PURE__ */ new Set(), resolve) {
3248
3303
  if (seen.has(p)) return false;
3249
3304
  seen.add(p);
@@ -3254,10 +3309,12 @@ function mayCommitFailure(p, seen = /* @__PURE__ */ new Set(), resolve) {
3254
3309
  case "choice":
3255
3310
  case "sequence":
3256
3311
  return d.parsers.some((x) => mayCommitFailure(x, seen, resolve));
3312
+ // A contained transaction reports every failure uncommitted.
3313
+ case "attempt":
3314
+ return d.contain !== true && mayCommitFailure(d.parser, seen, resolve);
3257
3315
  case "many":
3258
3316
  case "oneOrMore":
3259
3317
  case "optional":
3260
- case "attempt":
3261
3318
  case "transform":
3262
3319
  case "label":
3263
3320
  case "field":
@@ -4428,7 +4485,7 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
4428
4485
  throw new Error("node() options cannot combine project with unwrap or collapse");
4429
4486
  }
4430
4487
  const def = unwrap || collapse || project !== void 0 || captureTrivia || trailingTrivia || buildArity !== void 0 || tags !== void 0 && tags.length > 0 ? { ...baseDef, ...unwrap ? { unwrap: true } : {}, ...collapse ? { collapse: true } : {}, ...project !== void 0 ? { project } : {}, ...captureTrivia ? { captureTrivia: true } : {}, ...trailingTrivia ? { trailingTrivia: true } : {}, ...buildArity !== void 0 ? { buildArity } : {}, ...tags !== void 0 && tags.length > 0 ? { tags } : {} } : baseDef;
4431
- const capturesTrivia = captureTrivia || trailingTrivia || (build ? buildReadsTrivia(def) : project === void 0);
4488
+ const capturesTrivia = captureTrivia || (build ? buildReadsTrivia(def) : project === void 0);
4432
4489
  const clonesState = build ? buildReadsState(def) : project === void 0;
4433
4490
  const hasOwnFields = parserHasOwnFields(combinator);
4434
4491
  const capturesFields = hasOwnFields && (build ? buildReadsFields(def) : project === void 0);
@@ -5318,13 +5375,17 @@ function transform(combinator, fn) {
5318
5375
  };
5319
5376
  }
5320
5377
  function trivia(combinator) {
5321
- const kindLabels = analyzeLabeledTrivia(combinator)?.labels;
5378
+ const labeled = analyzeLabeledTrivia(combinator);
5379
+ const kindLabels = labeled?.labels;
5322
5380
  return {
5323
5381
  _tag: combinator._tag,
5324
5382
  _meta: {
5325
5383
  ...combinator._meta,
5326
5384
  isTrivia: true,
5327
5385
  triviaScanner: fastTriviaScanner(combinator),
5386
+ // Every labeled scan of this trivia reads its spec; the module's four-slot
5387
+ // memo alone thrashes on a grammar with more than four trivia tables.
5388
+ labeledTriviaSpec: labeled,
5328
5389
  ...kindLabels ? { triviaKindLabels: kindLabels } : {}
5329
5390
  },
5330
5391
  _def: { tag: "trivia", parser: combinator },
@@ -7054,7 +7115,7 @@ var Encoder = class {
7054
7115
  const derivedState = d.build !== void 0 ? buildReadsState(d) : noBuildCaptures;
7055
7116
  const derivedFields = d.build !== void 0 ? buildReadsFields(d) : noBuildCaptures;
7056
7117
  const wantsFields = parserHasOwnFields(d.parser) && (cstOut || derivedFields);
7057
- 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);
7118
+ 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);
7058
7119
  const body = this.emit(
7059
7120
  this.track ? OP_NODE_TRACK : OP_NODE,
7060
7121
  d.build === void 0 ? -1 : this.fn(d.build, d.buildSrc ?? null),
@@ -7180,7 +7241,7 @@ var Encoder = class {
7180
7241
  // A TRANSACTION IS A ROW. See `OP_ATTEMPT` for why the transparent
7181
7242
  // lowering was correct only for a choice arm.
7182
7243
  case "attempt": {
7183
- const inner = this.emit(OP_ATTEMPT, this.node(d.parser).ip);
7244
+ const inner = this.emit(OP_ATTEMPT, this.node(d.parser).ip, d.contain === true ? 1 : 0);
7184
7245
  if (!this.failureNeedsRollback(d.parser, void 0)) this.failureRollbackCleanSites.add(inner);
7185
7246
  const fs = d.parser._def.tag === "lazy" ? firstSetOf(d.parser, /* @__PURE__ */ new Set(), this.refResolver(), this.activeTrivia) : d.parser._meta.firstSet;
7186
7247
  if (fs.kind === "any" || matchesEmpty(d.parser)) return inner;
@@ -8573,7 +8634,7 @@ function transfer(code, ip, at, hostCst) {
8573
8634
  }
8574
8635
  if (op === OP_NODE || op === OP_NODE_TRACK) {
8575
8636
  const flags = code[ip + 3];
8576
- const directChildren = !hostCst && op === OP_NODE && code[ip + 1] >= 0 && code[ip + 4] < 0 && (flags === 2 || flags === 18 || flags === 34);
8637
+ const directChildren = !hostCst && op === OP_NODE && code[ip + 1] >= 0 && code[ip + 4] < 0 && ((flags & ~128) === 2 || flags === 18 || flags === 34);
8577
8638
  if (directChildren) {
8578
8639
  return { tri: at.tri, buf: false, raw: RAW_UNKNOWN, cap: CAP_OFF };
8579
8640
  }
@@ -9777,7 +9838,7 @@ ${clean ? "" : emitMark(p, L.buf, L.raw, sinks)}
9777
9838
  const v=${child}(input,pos,ctx)
9778
9839
  if(v!==FAIL)return v
9779
9840
  ${clean ? "" : emitRollback(p, L.buf, L.raw, sinks)}
9780
- if(ctx._fc===true)return FAIL
9841
+ ${code[ip + 2] === 1 ? "ctx._fc=false" : "if(ctx._fc===true)return FAIL"}
9781
9842
  ctx._fe=pos
9782
9843
  return FAIL
9783
9844
  }`;
@@ -10366,7 +10427,8 @@ return nd
10366
10427
  const unwrap = (flags & 64) !== 0;
10367
10428
  const trailingTrivia = (flags & 128) !== 0;
10368
10429
  const build = buildIdx >= 0 ? fnRef(buildIdx) : void 0;
10369
- if (!hostCst && !tracked && build !== void 0 && proj < 0 && (flags === 2 || flags === 18 || flags === 34)) {
10430
+ const leanFlags = flags & ~128;
10431
+ if (!hostCst && !tracked && build !== void 0 && proj < 0 && (leanFlags === 2 || (flags === 18 || flags === 34))) {
10370
10432
  const fields = flags === 18;
10371
10433
  const collapseChildren = flags === 34;
10372
10434
  const publish = L.buf && L.raw === RAW_OMIT ? "_pushNodeNoRawBuf(ctx,nd)" : L.buf && L.raw === RAW_CAPTURE ? `if(sBuf!==undefined){
@@ -10411,7 +10473,8 @@ ctx._cstTriviaLog=undefined
10411
10473
  ctx.captureTrivia=false
10412
10474
  ctx._fields=${fields ? "[]" : "undefined"}
10413
10475
  const v=${child}(input,pos,ctx)
10414
- const captured=_capturedFlatChildren(flat)
10476
+ ${trailingTrivia && L.tri !== TRI_NONE ? `if(v!==FAIL${L.tri === TRI_UNKNOWN ? "&&ctx.trivia!==undefined" : ""})EC.e=consumeTrivia(input,EC.e,ctx)
10477
+ ` : ""}const captured=_capturedFlatChildren(flat)
10415
10478
  ${fields ? "const fieldMap=buildFieldMap(ctx._fields)\n" : ""}ctx._fields=sFields
10416
10479
  ctx._cstBuf=sBuf
10417
10480
  ctx._cstChildren=sCh
@@ -10787,6 +10850,7 @@ function withRuleTrivia(trivia2, ctx, run) {
10787
10850
  ctx.triviaKindLabels = savedLabels;
10788
10851
  }
10789
10852
  }
10853
+ var UNDEFINED_REF = new Error("ref<T>() used before .define() was called");
10790
10854
  function ref() {
10791
10855
  let resolved = null;
10792
10856
  let resolvedScalar = null;
@@ -10802,7 +10866,7 @@ function ref() {
10802
10866
  _def: {
10803
10867
  tag: "lazy",
10804
10868
  thunk: () => {
10805
- if (!resolved) throw new Error("ref<T>() used before .define() was called");
10869
+ if (!resolved) throw UNDEFINED_REF;
10806
10870
  return resolved;
10807
10871
  }
10808
10872
  },
@@ -11428,7 +11492,7 @@ function assemble(t2, prog, cfg) {
11428
11492
  const lf = { _tag: "leaf", value, span: { start: s, end: e } };
11429
11493
  pushCstLeaf(ctx, lf);
11430
11494
  }
11431
- function plainBuildNode(child, build) {
11495
+ function plainBuildNode(child, build, trailing) {
11432
11496
  return (input, pos, ctx) => {
11433
11497
  const sCh = ctx._cstChildren;
11434
11498
  const sLv = ctx._cstLeaves;
@@ -11446,6 +11510,7 @@ function assemble(t2, prog, cfg) {
11446
11510
  ctx.captureTrivia = false;
11447
11511
  ctx._fields = void 0;
11448
11512
  const value = child(input, pos, ctx);
11513
+ if (trailing && value !== FAIL && ctx.trivia !== void 0) EC.e = consumeTrivia(input, EC.e, ctx);
11449
11514
  const kids = buf.ch ?? (buf.single !== void 0 ? [buf.single] : EMPTY_CH);
11450
11515
  const rawKids = buf.raw ?? (buf.rawSingle !== void 0 ? [buf.rawSingle] : EMPTY_CH);
11451
11516
  ctx._fields = savedFields;
@@ -11473,7 +11538,7 @@ function assemble(t2, prog, cfg) {
11473
11538
  while (first < children2.length && children2[first] === void 0) first++;
11474
11539
  return first === children2.length ? EMPTY_CH : children2.slice(first);
11475
11540
  }
11476
- function childrenOnlyBuildNode(child, build) {
11541
+ function childrenOnlyBuildNode(child, build, trailing) {
11477
11542
  return (input, pos, ctx) => {
11478
11543
  const sCh = ctx._cstChildren;
11479
11544
  const sLv = ctx._cstLeaves;
@@ -11491,6 +11556,7 @@ function assemble(t2, prog, cfg) {
11491
11556
  ctx.captureTrivia = false;
11492
11557
  ctx._fields = void 0;
11493
11558
  const value = child(input, pos, ctx);
11559
+ if (trailing && value !== FAIL && ctx.trivia !== void 0) EC.e = consumeTrivia(input, EC.e, ctx);
11494
11560
  const captured = capturedFlatChildren(kids);
11495
11561
  ctx._fields = savedFields;
11496
11562
  ctx._cstBuf = sBuf;
@@ -12515,6 +12581,7 @@ function assemble(t2, prog, cfg) {
12515
12581
  /* ── transaction ─────────────────────────────────────────────────────── */
12516
12582
  case OP_ATTEMPT: {
12517
12583
  const child = link(code[ip + 1]);
12584
+ const contain = code[ip + 2] === 1;
12518
12585
  return (input, pos, ctx) => {
12519
12586
  const need = markCst(ctx);
12520
12587
  const mRaw = MRAW;
@@ -12527,7 +12594,10 @@ function assemble(t2, prog, cfg) {
12527
12594
  const v = child(input, pos, ctx);
12528
12595
  if (v !== FAIL) return v;
12529
12596
  if (need) rollbackTriviaAt(ctx, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot);
12530
- if (committed3(ctx)) return FAIL;
12597
+ if (committed3(ctx)) {
12598
+ if (!contain) return FAIL;
12599
+ ctx._fc = false;
12600
+ }
12531
12601
  ctx._fe = pos;
12532
12602
  return FAIL;
12533
12603
  };
@@ -13978,11 +14048,11 @@ function assemble(t2, prog, cfg) {
13978
14048
  const trailingTrivia = (flags & 128) !== 0;
13979
14049
  const build = buildIdx >= 0 ? fns[buildIdx] : void 0;
13980
14050
  if (!hostCst && !tracked) {
13981
- if (build !== void 0 && proj < 0 && flags === 0) {
13982
- return plainBuildNode(child, build);
14051
+ if (build !== void 0 && proj < 0 && (flags & ~128) === 0) {
14052
+ return plainBuildNode(child, build, trailingTrivia);
13983
14053
  }
13984
- if (build !== void 0 && proj < 0 && flags === 2) {
13985
- return childrenOnlyBuildNode(child, build);
14054
+ if (build !== void 0 && proj < 0 && (flags & ~128) === 2) {
14055
+ return childrenOnlyBuildNode(child, build, trailingTrivia);
13986
14056
  }
13987
14057
  if (build !== void 0 && proj < 0 && flags === 18) {
13988
14058
  return childrenOnlyFieldsBuildNode(child, build);
@@ -14723,7 +14793,8 @@ function children(def, winners) {
14723
14793
  return [];
14724
14794
  }
14725
14795
  const name = resolved._ruleName;
14726
- return name && winners?.[name] ? [winners[name]] : [resolved];
14796
+ const winner = name ? winners?.[name] : void 0;
14797
+ return winner !== void 0 && winner._def !== def ? [winner] : [resolved];
14727
14798
  }
14728
14799
  default:
14729
14800
  return [];
@@ -14748,16 +14819,39 @@ function buildGrammarPlan(entry, winners) {
14748
14819
  }
14749
14820
  }
14750
14821
  }
14822
+ const selfWinnerBody = (parser2) => {
14823
+ if (parser2._def.tag !== "lazy" || winners === void 0) return void 0;
14824
+ const name = winnerNames.get(parser2);
14825
+ if (name === void 0 || winners[name] !== parser2) return void 0;
14826
+ try {
14827
+ return parser2._def.thunk();
14828
+ } catch {
14829
+ return void 0;
14830
+ }
14831
+ };
14832
+ const slotsPerBody = /* @__PURE__ */ new Map();
14833
+ if (winners) {
14834
+ for (const winner of Object.values(winners)) {
14835
+ const body = selfWinnerBody(winner);
14836
+ if (body !== void 0) slotsPerBody.set(body, (slotsPerBody.get(body) ?? 0) + 1);
14837
+ }
14838
+ }
14839
+ const sharedBody = (parser2) => (slotsPerBody.get(parser2) ?? 0) > 1;
14840
+ const ownRule = (parser2, rule2) => {
14841
+ const id = `rule:${rule2}`;
14842
+ definitions.set(id, { id, kind: "rule" });
14843
+ rules.set(parser2, id);
14844
+ };
14751
14845
  const seen = /* @__PURE__ */ new Set();
14752
14846
  const visit = (parser2, path) => {
14753
14847
  if (seen.has(parser2)) return;
14754
14848
  seen.add(parser2);
14755
14849
  const rule2 = winnerNames.get(parser2) ?? parser2._ruleName;
14756
- if (rule2 && (winnerNames.has(parser2) || parser2._def.tag !== "lazy")) {
14757
- const id = `rule:${rule2}`;
14758
- definitions.set(id, { id, kind: "rule" });
14759
- rules.set(parser2, id);
14850
+ const body = selfWinnerBody(parser2);
14851
+ if (rule2 && body === void 0 && !sharedBody(parser2) && (winnerNames.has(parser2) || parser2._def.tag !== "lazy")) {
14852
+ ownRule(parser2, rule2);
14760
14853
  }
14854
+ if (rule2 && body !== void 0 && sharedBody(body)) ownRule(parser2, rule2);
14761
14855
  if (parser2._def.tag === "choice") {
14762
14856
  const ids = parser2._def.parsers.map((_, index) => `choice:${path}/arm:${index}`);
14763
14857
  choices.set(parser2, ids);
@@ -14778,7 +14872,13 @@ function buildGrammarPlan(entry, winners) {
14778
14872
  };
14779
14873
  const roots = Array.isArray(entry) ? entry : [entry];
14780
14874
  for (const root of roots) {
14781
- visit(root, winnerNames.get(root) ?? root._ruleName ?? "entry");
14875
+ const name = winnerNames.get(root) ?? root._ruleName ?? "entry";
14876
+ const body = selfWinnerBody(root);
14877
+ if (body !== void 0 && sharedBody(body) && !seen.has(root)) {
14878
+ seen.add(root);
14879
+ ownRule(root, name);
14880
+ }
14881
+ visit(body ?? root, name);
14782
14882
  }
14783
14883
  return { definitions: [...definitions.values()].sort((a, b) => a.id.localeCompare(b.id)), choices, dispatches, attempts, labels, rules };
14784
14884
  }
@@ -16080,6 +16180,238 @@ ${lines.join("\n")}`);
16080
16180
  function runDuplicationDiagnostic(combinator, opt) {
16081
16181
  return reportDuplication(opt, (o) => analyzeDuplication(combinator, o));
16082
16182
  }
16183
+ function runDuplicationDiagnosticRules(ruleMap, opt) {
16184
+ return reportDuplication(opt, (o) => analyzeDuplicationRules(ruleMap, o));
16185
+ }
16186
+
16187
+ // src/cst/reflection-symbols.ts
16188
+ var GRAMMAR_REFLECTION = /* @__PURE__ */ Symbol.for("parseman.grammarReflection");
16189
+
16190
+ // src/cst/reflection.ts
16191
+ function childrenOf2(def) {
16192
+ switch (def.tag) {
16193
+ case "sequence":
16194
+ case "choice":
16195
+ return def.parsers;
16196
+ case "dispatch":
16197
+ return [
16198
+ def.selector,
16199
+ ...def.cases.map((c) => c.parser),
16200
+ ...def.matchers ? def.matchers.map((c) => c.parser) : [],
16201
+ ...def.otherwise ? [def.otherwise] : []
16202
+ ];
16203
+ case "many":
16204
+ case "oneOrMore":
16205
+ case "optional":
16206
+ case "attempt":
16207
+ case "transform":
16208
+ case "trivia":
16209
+ case "token":
16210
+ case "leaf":
16211
+ case "label":
16212
+ case "field":
16213
+ case "not":
16214
+ case "peek":
16215
+ case "node":
16216
+ case "withCtx":
16217
+ case "expect":
16218
+ return [def.parser];
16219
+ case "recover":
16220
+ return [def.parser, def.sentinel];
16221
+ case "grammar":
16222
+ return def.triviaParser ? [def.parser, def.triviaParser] : [def.parser];
16223
+ case "sepBy":
16224
+ return [def.parser, def.separator];
16225
+ case "scanTo":
16226
+ return [
16227
+ def.sentinel,
16228
+ ...def.skip,
16229
+ ...def.recoverAt === void 0 ? [] : [def.recoverAt],
16230
+ ...def.stopAt === void 0 ? [] : [def.stopAt]
16231
+ ];
16232
+ case "routed":
16233
+ return def.fallback ? [def.fallback] : [];
16234
+ case "literal":
16235
+ case "regex":
16236
+ case "keywords":
16237
+ case "guard":
16238
+ case "adjacency":
16239
+ case "lazy":
16240
+ case "unknown":
16241
+ return [];
16242
+ }
16243
+ }
16244
+ function addNode(out, def) {
16245
+ if (def.type === void 0) return;
16246
+ const existing = out.get(def.type);
16247
+ if (existing === void 0) {
16248
+ out.set(def.type, def.tags === void 0 ? [] : [...def.tags]);
16249
+ return;
16250
+ }
16251
+ if (def.tags === void 0) return;
16252
+ for (const tag of def.tags) {
16253
+ if (!existing.includes(tag)) existing.push(tag);
16254
+ }
16255
+ }
16256
+ function collectFromCombinator(parser2, out, seen, followLazy = true) {
16257
+ if (seen.has(parser2)) return;
16258
+ seen.add(parser2);
16259
+ const def = parser2._def;
16260
+ if (def.tag === "lazy") {
16261
+ if (followLazy) {
16262
+ try {
16263
+ collectFromCombinator(def.thunk(), out, seen, followLazy);
16264
+ } catch {
16265
+ }
16266
+ }
16267
+ return;
16268
+ }
16269
+ if (def.tag === "node") addNode(out, def);
16270
+ for (const child of childrenOf2(def)) collectFromCombinator(child, out, seen, followLazy);
16271
+ }
16272
+ function collectGrammarReflection(ruleMap, opts) {
16273
+ const byType = /* @__PURE__ */ new Map();
16274
+ const followLazy = opts?.followLazy !== false;
16275
+ const seen = /* @__PURE__ */ new Set();
16276
+ for (const [, rule2] of ruleMap) {
16277
+ if (!followLazy && rule2._def.tag === "lazy") {
16278
+ try {
16279
+ const resolved = rule2._def.thunk();
16280
+ if (resolved._def.tag !== "lazy") collectFromCombinator(resolved, byType, /* @__PURE__ */ new Set(), false);
16281
+ } catch {
16282
+ }
16283
+ continue;
16284
+ }
16285
+ collectFromCombinator(rule2, byType, seen, followLazy);
16286
+ }
16287
+ return { nodes: [...byType].map(([type, tags]) => ({ type, tags })) };
16288
+ }
16289
+
16290
+ // src/table/compile-rule-map.ts
16291
+ function resolveHostMode(ruleMap, explicit) {
16292
+ return explicit ?? ruleMap.map(([, r]) => r._meta.grammarHostMode).find(Boolean) ?? "ast";
16293
+ }
16294
+ function resolveTrackLines(ruleMap, explicit) {
16295
+ return explicit === true || ruleMap.some(([, r]) => r._meta.grammarTrackLines === true);
16296
+ }
16297
+ function withAmbient(ruleMap, opts) {
16298
+ if (opts.trivia === void 0 && opts.scanSkip === void 0) return ruleMap;
16299
+ const wrappers = /* @__PURE__ */ new Map();
16300
+ return ruleMap.map(([name, rule2]) => {
16301
+ if (rule2._meta.isTrivia) return [name, rule2];
16302
+ const addTrivia = opts.trivia !== void 0 && rule2._meta.grammarTrivia === void 0;
16303
+ const addScanSkip = opts.scanSkip !== void 0 && rule2._meta.grammarScanSkip === void 0;
16304
+ if (!addTrivia && !addScanSkip) return [name, rule2];
16305
+ let wrapped = wrappers.get(rule2);
16306
+ if (wrapped === void 0) {
16307
+ wrapped = {
16308
+ ...rule2,
16309
+ _meta: {
16310
+ ...rule2._meta,
16311
+ ...addTrivia ? { grammarTrivia: opts.trivia } : {},
16312
+ ...addScanSkip ? { grammarScanSkip: opts.scanSkip } : {}
16313
+ }
16314
+ };
16315
+ wrappers.set(rule2, wrapped);
16316
+ }
16317
+ return [name, wrapped];
16318
+ });
16319
+ }
16320
+ function compileRuleMapRunnable(ruleMap, opts = {}) {
16321
+ const encoded = encodeForRun(ruleMap, opts);
16322
+ if (encoded === null) return null;
16323
+ const { prog, hostMode, plan } = encoded;
16324
+ const artifact = closureArtifact(prog);
16325
+ const reflection = collectGrammarReflection(ruleMap);
16326
+ return {
16327
+ keys: ruleMap.map(([key]) => key),
16328
+ hostMode,
16329
+ hostBranchElided: hostMode === "ast" && ruleMap.some(([, rule2]) => hasDirectBuildDef(rule2)),
16330
+ reflection,
16331
+ ...plan === void 0 ? {} : { coverageDefinitions: plan.definitions },
16332
+ // Reflection rides on the map's metadata prototype from birth. Only `compile()`
16333
+ // asks to specialise; every other caller runs the closure artifact.
16334
+ rules: tableRules(opts.specialise === true ? prog : artifact, { [GRAMMAR_REFLECTION]: reflection }),
16335
+ prog: artifact
16336
+ };
16337
+ }
16338
+ function encodeForRun(ruleMap, opts) {
16339
+ runDuplicationDiagnosticRules(ruleMap, opts.duplication);
16340
+ const encodeMap = withAmbient(ruleMap, opts);
16341
+ const plan = opts.coverage === true ? buildGrammarPlan(
16342
+ encodeMap.map(([, rule2]) => rule2),
16343
+ Object.fromEntries(encodeMap.filter(([, rule2]) => rule2._def.tag !== "lazy"))
16344
+ ) : void 0;
16345
+ const hostMode = resolveHostMode(ruleMap, opts.hostMode);
16346
+ const settings = {
16347
+ hostMode,
16348
+ ...resolveTrackLines(ruleMap, opts.trackLines) ? { trackLines: true } : {},
16349
+ ...opts.recovery === true ? { recovery: true } : {},
16350
+ ...plan === void 0 ? {} : { coverage: plan }
16351
+ };
16352
+ try {
16353
+ const { prog, fnSrcs } = encodeTableProgram(Object.fromEntries(encodeMap), settings);
16354
+ return { prog, fnSrcs, hostMode, plan };
16355
+ } catch (e) {
16356
+ opts.refusals?.push(e instanceof Error ? e.message : String(e));
16357
+ return null;
16358
+ }
16359
+ }
16360
+
16361
+ // src/compiler/borrowed-rules.ts
16362
+ var nameOf = (c) => c._ruleName;
16363
+ function deref(c) {
16364
+ const seen = /* @__PURE__ */ new Set();
16365
+ let current = c;
16366
+ while (current._def.tag === "lazy" && !seen.has(current)) {
16367
+ seen.add(current);
16368
+ try {
16369
+ current = current._def.thunk();
16370
+ } catch {
16371
+ return void 0;
16372
+ }
16373
+ }
16374
+ return current;
16375
+ }
16376
+ function borrowedRuleReference(map) {
16377
+ const seen = /* @__PURE__ */ new Set();
16378
+ for (const [rule2, self] of Object.entries(map)) {
16379
+ let found;
16380
+ const visit = (c) => {
16381
+ if (found !== void 0) return;
16382
+ if (c._def.tag === "lazy") {
16383
+ if (!winnerWrapsReference(self, c)) {
16384
+ const name = nameOf(c);
16385
+ const winner = name !== void 0 && Object.hasOwn(map, name) ? map[name] : void 0;
16386
+ if (winner !== void 0) {
16387
+ if (winnerWrapsReference(winner, c) || deref(c) === deref(winner)) return;
16388
+ found = name;
16389
+ return;
16390
+ }
16391
+ }
16392
+ if (seen.has(c)) return;
16393
+ seen.add(c);
16394
+ let body;
16395
+ try {
16396
+ body = c._def.thunk();
16397
+ } catch {
16398
+ return;
16399
+ }
16400
+ visit(body);
16401
+ return;
16402
+ }
16403
+ if (seen.has(c)) return;
16404
+ seen.add(c);
16405
+ for (const child of childrenOf(c._def)) visit(child);
16406
+ };
16407
+ visit(self);
16408
+ if (found !== void 0) return { rule: rule2, reference: found };
16409
+ }
16410
+ return void 0;
16411
+ }
16412
+ function borrowedRuleMessage(api, hit) {
16413
+ 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.`;
16414
+ }
16083
16415
 
16084
16416
  // src/table/compile.ts
16085
16417
  var ENTRY = "Entry";
@@ -16090,7 +16422,47 @@ function ownSource(fn) {
16090
16422
  const name = fn.name;
16091
16423
  return typeof name === "string" && name.length > 0 && globalThis[name] === fn ? name : null;
16092
16424
  }
16093
- function compile(combinator, mapFnSources, opts = {}) {
16425
+ function compile(target, second, third) {
16426
+ if (!isCombinator(target)) return compileMap(target, second);
16427
+ return compileRoot(target, second, third);
16428
+ }
16429
+ function isCombinator(x) {
16430
+ return typeof x === "object" && x !== null && typeof x.parse === "function" && "_def" in x;
16431
+ }
16432
+ function compileMap(grammar, opts = {}) {
16433
+ const entries = [];
16434
+ for (const [key, value] of Object.entries(grammar)) {
16435
+ if (!isCombinator(value)) throw new TypeError(`compile: grammar entry "${key}" is not a parser`);
16436
+ if (value._def.tag === "lazy") {
16437
+ try {
16438
+ value._def.thunk();
16439
+ } catch {
16440
+ continue;
16441
+ }
16442
+ }
16443
+ entries.push([key, value]);
16444
+ }
16445
+ const borrowed = borrowedRuleReference(Object.fromEntries(entries));
16446
+ if (borrowed !== void 0) throw new Error(borrowedRuleMessage("compile", borrowed));
16447
+ const drain = beginCompileDegradationDrain();
16448
+ let done = false;
16449
+ try {
16450
+ const refusals = [];
16451
+ const compiled = compileRuleMapRunnable(entries, {
16452
+ ...opts.hostMode ? { hostMode: opts.hostMode } : {},
16453
+ refusals,
16454
+ specialise: true
16455
+ });
16456
+ if (compiled === null) {
16457
+ throw new Error(`compile: this grammar could not be encoded to a table${refusals.length ? ` \u2014 ${refusals.join("; ")}` : ""}`);
16458
+ }
16459
+ done = true;
16460
+ return compiled.rules;
16461
+ } finally {
16462
+ drain(done);
16463
+ }
16464
+ }
16465
+ function compileRoot(combinator, mapFnSources, opts = {}) {
16094
16466
  runDuplicationDiagnostic(combinator, opts.duplication);
16095
16467
  const drain = beginCompileDegradationDrain();
16096
16468
  let compiled = false;
@@ -16372,13 +16744,24 @@ function digestValue(value, prefix = "", options) {
16372
16744
  }
16373
16745
 
16374
16746
  // src/combinators/attempt.ts
16375
- function attempt(parser2) {
16747
+ function containOption(options) {
16748
+ if (options === void 0) return false;
16749
+ for (const key of Object.keys(options)) {
16750
+ if (key !== "contain") throw new TypeError(`attempt(): unknown option ${JSON.stringify(key)}`);
16751
+ }
16752
+ if (options.contain !== void 0 && typeof options.contain !== "boolean") {
16753
+ throw new TypeError("attempt(): `contain` must be a boolean");
16754
+ }
16755
+ return options.contain === true;
16756
+ }
16757
+ function attempt(parser2, options) {
16758
+ const contain = containOption(options);
16376
16759
  const guardable = parser2._meta.firstSet.kind !== "any" && !matchesEmpty(parser2);
16377
16760
  let failExpected;
16378
16761
  return {
16379
16762
  _tag: "attempt",
16380
16763
  _meta: parser2._meta,
16381
- _def: { tag: "attempt", parser: parser2 },
16764
+ _def: contain ? { tag: "attempt", parser: parser2, contain: true } : { tag: "attempt", parser: parser2 },
16382
16765
  parse(input, pos, ctx) {
16383
16766
  if (guardable && ctx._probe === void 0 && !ctx._tolerant && !startsFirstSet(parser2, input, pos)) {
16384
16767
  if (failExpected === void 0) {
@@ -16395,7 +16778,7 @@ function attempt(parser2) {
16395
16778
  rollbackCstCapture(ctx, mark);
16396
16779
  if (log !== void 0 && ctx._triviaLog && ctx._triviaLog.length !== log) ctx._triviaLog.length = log;
16397
16780
  if (rootLog !== void 0 && ctx._rootTriviaLog && ctx._rootTriviaLog.length !== rootLog) ctx._rootTriviaLog.length = rootLog;
16398
- if (result.committed) return result;
16781
+ if (result.committed && !contain) return result;
16399
16782
  return { ok: false, expected: result.expected, span: { start: pos, end: pos } };
16400
16783
  }
16401
16784
  };
@@ -16562,7 +16945,7 @@ function rebuildCombinator(root, replacements) {
16562
16945
  out = d.polarity === "adjacent" ? adjacent() : d.kinds === void 0 ? notAdjacent() : notAdjacent({ kinds: d.kinds });
16563
16946
  break;
16564
16947
  case "attempt":
16565
- out = attempt(one(d.parser));
16948
+ out = attempt(one(d.parser), d.contain === true ? { contain: true } : void 0);
16566
16949
  break;
16567
16950
  case "not":
16568
16951
  out = not(one(d.parser));