parseman 0.51.2 → 0.52.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 (54) hide show
  1. package/dist/analysis/commitment.d.ts.map +1 -1
  2. package/dist/analysis/diagnostics.js +53 -20
  3. package/dist/analysis/diagnostics.js.map +1 -1
  4. package/dist/cli/index.js +53 -20
  5. package/dist/cli/index.js.map +1 -1
  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/compiler/token-capability.js +4 -0
  12. package/dist/compiler/token-capability.js.map +1 -1
  13. package/dist/cst/trivia-kinds.d.ts.map +1 -1
  14. package/dist/index.d.ts +1 -0
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +55 -22
  17. package/dist/index.js.map +1 -1
  18. package/dist/plugin/index.js +55 -22
  19. package/dist/plugin/index.js.map +1 -1
  20. package/dist/spec/index.js +28 -5
  21. package/dist/spec/index.js.map +1 -1
  22. package/dist/table/assemble.d.ts.map +1 -1
  23. package/dist/table/emit-assembly.d.ts.map +1 -1
  24. package/dist/table/encode-baseline.d.ts.map +1 -1
  25. package/dist/table/exec.d.ts.map +1 -1
  26. package/dist/table/index.js +37 -15
  27. package/dist/table/index.js.map +1 -1
  28. package/dist/table/ops.d.ts +7 -5
  29. package/dist/table/ops.d.ts.map +1 -1
  30. package/dist/table/site-labels.d.ts.map +1 -1
  31. package/dist/types.d.ts +8 -1
  32. package/dist/types.d.ts.map +1 -1
  33. package/dist/version.d.ts +1 -1
  34. package/package.json +1 -1
  35. package/src/analysis/commitment.ts +3 -1
  36. package/src/analysis/rebuild.ts +1 -1
  37. package/src/combinators/attempt.ts +26 -3
  38. package/src/combinators/first-set.ts +5 -1
  39. package/src/combinators/map.ts +5 -1
  40. package/src/combinators/node.ts +12 -3
  41. package/src/compiler/ir-serialize.ts +1 -1
  42. package/src/coverage.ts +1 -1
  43. package/src/cst/trivia-kinds.ts +6 -0
  44. package/src/index.ts +1 -0
  45. package/src/plugin/evaluator.ts +1 -1
  46. package/src/table/assemble.ts +22 -8
  47. package/src/table/emit-assembly.ts +8 -3
  48. package/src/table/encode-baseline.ts +5 -1
  49. package/src/table/encode.ts +13 -13
  50. package/src/table/exec.ts +6 -2
  51. package/src/table/ops.ts +7 -5
  52. package/src/table/site-labels.ts +3 -1
  53. package/src/types.ts +8 -1
  54. 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,IAA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iB,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;
@@ -3254,10 +3262,12 @@ function mayCommitFailure(p, seen = /* @__PURE__ */ new Set(), resolve) {
3254
3262
  case "choice":
3255
3263
  case "sequence":
3256
3264
  return d.parsers.some((x) => mayCommitFailure(x, seen, resolve));
3265
+ // A contained transaction reports every failure uncommitted.
3266
+ case "attempt":
3267
+ return d.contain !== true && mayCommitFailure(d.parser, seen, resolve);
3257
3268
  case "many":
3258
3269
  case "oneOrMore":
3259
3270
  case "optional":
3260
- case "attempt":
3261
3271
  case "transform":
3262
3272
  case "label":
3263
3273
  case "field":
@@ -4428,7 +4438,7 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
4428
4438
  throw new Error("node() options cannot combine project with unwrap or collapse");
4429
4439
  }
4430
4440
  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);
4441
+ const capturesTrivia = captureTrivia || (build ? buildReadsTrivia(def) : project === void 0);
4432
4442
  const clonesState = build ? buildReadsState(def) : project === void 0;
4433
4443
  const hasOwnFields = parserHasOwnFields(combinator);
4434
4444
  const capturesFields = hasOwnFields && (build ? buildReadsFields(def) : project === void 0);
@@ -5318,13 +5328,17 @@ function transform(combinator, fn) {
5318
5328
  };
5319
5329
  }
5320
5330
  function trivia(combinator) {
5321
- const kindLabels = analyzeLabeledTrivia(combinator)?.labels;
5331
+ const labeled = analyzeLabeledTrivia(combinator);
5332
+ const kindLabels = labeled?.labels;
5322
5333
  return {
5323
5334
  _tag: combinator._tag,
5324
5335
  _meta: {
5325
5336
  ...combinator._meta,
5326
5337
  isTrivia: true,
5327
5338
  triviaScanner: fastTriviaScanner(combinator),
5339
+ // Every labeled scan of this trivia reads its spec; the module's four-slot
5340
+ // memo alone thrashes on a grammar with more than four trivia tables.
5341
+ labeledTriviaSpec: labeled,
5328
5342
  ...kindLabels ? { triviaKindLabels: kindLabels } : {}
5329
5343
  },
5330
5344
  _def: { tag: "trivia", parser: combinator },
@@ -7054,7 +7068,7 @@ var Encoder = class {
7054
7068
  const derivedState = d.build !== void 0 ? buildReadsState(d) : noBuildCaptures;
7055
7069
  const derivedFields = d.build !== void 0 ? buildReadsFields(d) : noBuildCaptures;
7056
7070
  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);
7071
+ 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
7072
  const body = this.emit(
7059
7073
  this.track ? OP_NODE_TRACK : OP_NODE,
7060
7074
  d.build === void 0 ? -1 : this.fn(d.build, d.buildSrc ?? null),
@@ -7180,7 +7194,7 @@ var Encoder = class {
7180
7194
  // A TRANSACTION IS A ROW. See `OP_ATTEMPT` for why the transparent
7181
7195
  // lowering was correct only for a choice arm.
7182
7196
  case "attempt": {
7183
- const inner = this.emit(OP_ATTEMPT, this.node(d.parser).ip);
7197
+ const inner = this.emit(OP_ATTEMPT, this.node(d.parser).ip, d.contain === true ? 1 : 0);
7184
7198
  if (!this.failureNeedsRollback(d.parser, void 0)) this.failureRollbackCleanSites.add(inner);
7185
7199
  const fs = d.parser._def.tag === "lazy" ? firstSetOf(d.parser, /* @__PURE__ */ new Set(), this.refResolver(), this.activeTrivia) : d.parser._meta.firstSet;
7186
7200
  if (fs.kind === "any" || matchesEmpty(d.parser)) return inner;
@@ -8573,7 +8587,7 @@ function transfer(code, ip, at, hostCst) {
8573
8587
  }
8574
8588
  if (op === OP_NODE || op === OP_NODE_TRACK) {
8575
8589
  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);
8590
+ const directChildren = !hostCst && op === OP_NODE && code[ip + 1] >= 0 && code[ip + 4] < 0 && ((flags & ~128) === 2 || flags === 18 || flags === 34);
8577
8591
  if (directChildren) {
8578
8592
  return { tri: at.tri, buf: false, raw: RAW_UNKNOWN, cap: CAP_OFF };
8579
8593
  }
@@ -9777,7 +9791,7 @@ ${clean ? "" : emitMark(p, L.buf, L.raw, sinks)}
9777
9791
  const v=${child}(input,pos,ctx)
9778
9792
  if(v!==FAIL)return v
9779
9793
  ${clean ? "" : emitRollback(p, L.buf, L.raw, sinks)}
9780
- if(ctx._fc===true)return FAIL
9794
+ ${code[ip + 2] === 1 ? "ctx._fc=false" : "if(ctx._fc===true)return FAIL"}
9781
9795
  ctx._fe=pos
9782
9796
  return FAIL
9783
9797
  }`;
@@ -10366,7 +10380,8 @@ return nd
10366
10380
  const unwrap = (flags & 64) !== 0;
10367
10381
  const trailingTrivia = (flags & 128) !== 0;
10368
10382
  const build = buildIdx >= 0 ? fnRef(buildIdx) : void 0;
10369
- if (!hostCst && !tracked && build !== void 0 && proj < 0 && (flags === 2 || flags === 18 || flags === 34)) {
10383
+ const leanFlags = flags & ~128;
10384
+ if (!hostCst && !tracked && build !== void 0 && proj < 0 && (leanFlags === 2 || (flags === 18 || flags === 34))) {
10370
10385
  const fields = flags === 18;
10371
10386
  const collapseChildren = flags === 34;
10372
10387
  const publish = L.buf && L.raw === RAW_OMIT ? "_pushNodeNoRawBuf(ctx,nd)" : L.buf && L.raw === RAW_CAPTURE ? `if(sBuf!==undefined){
@@ -10411,7 +10426,8 @@ ctx._cstTriviaLog=undefined
10411
10426
  ctx.captureTrivia=false
10412
10427
  ctx._fields=${fields ? "[]" : "undefined"}
10413
10428
  const v=${child}(input,pos,ctx)
10414
- const captured=_capturedFlatChildren(flat)
10429
+ ${trailingTrivia && L.tri !== TRI_NONE ? `if(v!==FAIL${L.tri === TRI_UNKNOWN ? "&&ctx.trivia!==undefined" : ""})EC.e=consumeTrivia(input,EC.e,ctx)
10430
+ ` : ""}const captured=_capturedFlatChildren(flat)
10415
10431
  ${fields ? "const fieldMap=buildFieldMap(ctx._fields)\n" : ""}ctx._fields=sFields
10416
10432
  ctx._cstBuf=sBuf
10417
10433
  ctx._cstChildren=sCh
@@ -11428,7 +11444,7 @@ function assemble(t2, prog, cfg) {
11428
11444
  const lf = { _tag: "leaf", value, span: { start: s, end: e } };
11429
11445
  pushCstLeaf(ctx, lf);
11430
11446
  }
11431
- function plainBuildNode(child, build) {
11447
+ function plainBuildNode(child, build, trailing) {
11432
11448
  return (input, pos, ctx) => {
11433
11449
  const sCh = ctx._cstChildren;
11434
11450
  const sLv = ctx._cstLeaves;
@@ -11446,6 +11462,7 @@ function assemble(t2, prog, cfg) {
11446
11462
  ctx.captureTrivia = false;
11447
11463
  ctx._fields = void 0;
11448
11464
  const value = child(input, pos, ctx);
11465
+ if (trailing && value !== FAIL && ctx.trivia !== void 0) EC.e = consumeTrivia(input, EC.e, ctx);
11449
11466
  const kids = buf.ch ?? (buf.single !== void 0 ? [buf.single] : EMPTY_CH);
11450
11467
  const rawKids = buf.raw ?? (buf.rawSingle !== void 0 ? [buf.rawSingle] : EMPTY_CH);
11451
11468
  ctx._fields = savedFields;
@@ -11473,7 +11490,7 @@ function assemble(t2, prog, cfg) {
11473
11490
  while (first < children2.length && children2[first] === void 0) first++;
11474
11491
  return first === children2.length ? EMPTY_CH : children2.slice(first);
11475
11492
  }
11476
- function childrenOnlyBuildNode(child, build) {
11493
+ function childrenOnlyBuildNode(child, build, trailing) {
11477
11494
  return (input, pos, ctx) => {
11478
11495
  const sCh = ctx._cstChildren;
11479
11496
  const sLv = ctx._cstLeaves;
@@ -11491,6 +11508,7 @@ function assemble(t2, prog, cfg) {
11491
11508
  ctx.captureTrivia = false;
11492
11509
  ctx._fields = void 0;
11493
11510
  const value = child(input, pos, ctx);
11511
+ if (trailing && value !== FAIL && ctx.trivia !== void 0) EC.e = consumeTrivia(input, EC.e, ctx);
11494
11512
  const captured = capturedFlatChildren(kids);
11495
11513
  ctx._fields = savedFields;
11496
11514
  ctx._cstBuf = sBuf;
@@ -12515,6 +12533,7 @@ function assemble(t2, prog, cfg) {
12515
12533
  /* ── transaction ─────────────────────────────────────────────────────── */
12516
12534
  case OP_ATTEMPT: {
12517
12535
  const child = link(code[ip + 1]);
12536
+ const contain = code[ip + 2] === 1;
12518
12537
  return (input, pos, ctx) => {
12519
12538
  const need = markCst(ctx);
12520
12539
  const mRaw = MRAW;
@@ -12527,7 +12546,10 @@ function assemble(t2, prog, cfg) {
12527
12546
  const v = child(input, pos, ctx);
12528
12547
  if (v !== FAIL) return v;
12529
12548
  if (need) rollbackTriviaAt(ctx, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot);
12530
- if (committed3(ctx)) return FAIL;
12549
+ if (committed3(ctx)) {
12550
+ if (!contain) return FAIL;
12551
+ ctx._fc = false;
12552
+ }
12531
12553
  ctx._fe = pos;
12532
12554
  return FAIL;
12533
12555
  };
@@ -13978,11 +14000,11 @@ function assemble(t2, prog, cfg) {
13978
14000
  const trailingTrivia = (flags & 128) !== 0;
13979
14001
  const build = buildIdx >= 0 ? fns[buildIdx] : void 0;
13980
14002
  if (!hostCst && !tracked) {
13981
- if (build !== void 0 && proj < 0 && flags === 0) {
13982
- return plainBuildNode(child, build);
14003
+ if (build !== void 0 && proj < 0 && (flags & ~128) === 0) {
14004
+ return plainBuildNode(child, build, trailingTrivia);
13983
14005
  }
13984
- if (build !== void 0 && proj < 0 && flags === 2) {
13985
- return childrenOnlyBuildNode(child, build);
14006
+ if (build !== void 0 && proj < 0 && (flags & ~128) === 2) {
14007
+ return childrenOnlyBuildNode(child, build, trailingTrivia);
13986
14008
  }
13987
14009
  if (build !== void 0 && proj < 0 && flags === 18) {
13988
14010
  return childrenOnlyFieldsBuildNode(child, build);
@@ -16372,13 +16394,24 @@ function digestValue(value, prefix = "", options) {
16372
16394
  }
16373
16395
 
16374
16396
  // src/combinators/attempt.ts
16375
- function attempt(parser2) {
16397
+ function containOption(options) {
16398
+ if (options === void 0) return false;
16399
+ for (const key of Object.keys(options)) {
16400
+ if (key !== "contain") throw new TypeError(`attempt(): unknown option ${JSON.stringify(key)}`);
16401
+ }
16402
+ if (options.contain !== void 0 && typeof options.contain !== "boolean") {
16403
+ throw new TypeError("attempt(): `contain` must be a boolean");
16404
+ }
16405
+ return options.contain === true;
16406
+ }
16407
+ function attempt(parser2, options) {
16408
+ const contain = containOption(options);
16376
16409
  const guardable = parser2._meta.firstSet.kind !== "any" && !matchesEmpty(parser2);
16377
16410
  let failExpected;
16378
16411
  return {
16379
16412
  _tag: "attempt",
16380
16413
  _meta: parser2._meta,
16381
- _def: { tag: "attempt", parser: parser2 },
16414
+ _def: contain ? { tag: "attempt", parser: parser2, contain: true } : { tag: "attempt", parser: parser2 },
16382
16415
  parse(input, pos, ctx) {
16383
16416
  if (guardable && ctx._probe === void 0 && !ctx._tolerant && !startsFirstSet(parser2, input, pos)) {
16384
16417
  if (failExpected === void 0) {
@@ -16395,7 +16428,7 @@ function attempt(parser2) {
16395
16428
  rollbackCstCapture(ctx, mark);
16396
16429
  if (log !== void 0 && ctx._triviaLog && ctx._triviaLog.length !== log) ctx._triviaLog.length = log;
16397
16430
  if (rootLog !== void 0 && ctx._rootTriviaLog && ctx._rootTriviaLog.length !== rootLog) ctx._rootTriviaLog.length = rootLog;
16398
- if (result.committed) return result;
16431
+ if (result.committed && !contain) return result;
16399
16432
  return { ok: false, expected: result.expected, span: { start: pos, end: pos } };
16400
16433
  }
16401
16434
  };
@@ -16562,7 +16595,7 @@ function rebuildCombinator(root, replacements) {
16562
16595
  out = d.polarity === "adjacent" ? adjacent() : d.kinds === void 0 ? notAdjacent() : notAdjacent({ kinds: d.kinds });
16563
16596
  break;
16564
16597
  case "attempt":
16565
- out = attempt(one(d.parser));
16598
+ out = attempt(one(d.parser), d.contain === true ? { contain: true } : void 0);
16566
16599
  break;
16567
16600
  case "not":
16568
16601
  out = not(one(d.parser));