parseman 0.51.1 → 0.51.2

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 (48) hide show
  1. package/dist/analysis/diagnostics.js +48 -15
  2. package/dist/analysis/diagnostics.js.map +1 -1
  3. package/dist/cli/index.js +50 -17
  4. package/dist/cli/index.js.map +1 -1
  5. package/dist/combinators/token.d.ts +8 -8
  6. package/dist/combinators/token.d.ts.map +1 -1
  7. package/dist/coverage.d.ts.map +1 -1
  8. package/dist/index.d.ts +1 -1
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +53 -19
  11. package/dist/index.js.map +1 -1
  12. package/dist/plugin/evaluator.d.ts.map +1 -1
  13. package/dist/plugin/index.js +53 -20
  14. package/dist/plugin/index.js.map +1 -1
  15. package/dist/spec/index.js +27 -5
  16. package/dist/spec/index.js.map +1 -1
  17. package/dist/table/assemble.d.ts.map +1 -1
  18. package/dist/table/emit-assembly.d.ts.map +1 -1
  19. package/dist/table/encode-baseline.d.ts.map +1 -1
  20. package/dist/table/exec-baseline.d.ts.map +1 -1
  21. package/dist/table/exec.d.ts.map +1 -1
  22. package/dist/table/index.js +373 -362
  23. package/dist/table/index.js.map +2 -2
  24. package/dist/table/ops.d.ts +2 -0
  25. package/dist/table/ops.d.ts.map +1 -1
  26. package/dist/types.d.ts +1 -0
  27. package/dist/types.d.ts.map +1 -1
  28. package/dist/version.d.ts +1 -1
  29. package/package.json +1 -1
  30. package/src/analysis/duplication.ts +1 -1
  31. package/src/analysis/rebuild.ts +2 -2
  32. package/src/combinators/token.ts +46 -3
  33. package/src/compiler/ir-serialize.ts +4 -4
  34. package/src/coverage.ts +2 -3
  35. package/src/index.ts +1 -1
  36. package/src/plugin/evaluator.ts +7 -4
  37. package/src/table/assemble.ts +8 -3
  38. package/src/table/child-slots.ts +2 -2
  39. package/src/table/emit-assembly.ts +5 -3
  40. package/src/table/encode-baseline.ts +3 -2
  41. package/src/table/encode.ts +3 -3
  42. package/src/table/exec-baseline.ts +30 -4
  43. package/src/table/exec.ts +8 -3
  44. package/src/table/ops.ts +3 -1
  45. package/src/table/scalar-terminal.ts +5 -5
  46. package/src/table/site-labels.ts +2 -2
  47. package/src/types.ts +1 -1
  48. package/src/version.ts +1 -1
@@ -4253,6 +4253,7 @@ var OP_COV = 40;
4253
4253
  var OP_SCOPE_PLAIN = 41;
4254
4254
  var OP_LEX_BODY = 42;
4255
4255
  var OP_LEX_PROGRAM = 43;
4256
+ var OP_SOURCE_LEAF = 44;
4256
4257
  var OP_DISPATCH = 25;
4257
4258
  var OP_ROUTED = 26;
4258
4259
  var OP_NAMES = {
@@ -4271,6 +4272,7 @@ var OP_NAMES = {
4271
4272
  [OP_NOT]: "NOT",
4272
4273
  [OP_PEEK]: "PEEK",
4273
4274
  [OP_LEAF]: "LEAF",
4275
+ [OP_SOURCE_LEAF]: "SOURCE_LEAF",
4274
4276
  [OP_EMPTY]: "EMPTY",
4275
4277
  [OP_LIT_TRACK]: "LIT_TRACK",
4276
4278
  [OP_RX_TRACK]: "RX_TRACK",
@@ -7040,7 +7042,7 @@ var Encoder = class {
7040
7042
  }
7041
7043
  case "leaf": {
7042
7044
  const child = this.node(d.parser).ip;
7043
- return this.emit(OP_LEAF, this.fn(d.fn, d.fnSrc ?? null), child);
7045
+ return this.emit(d.cstValue === "source" ? OP_SOURCE_LEAF : OP_LEAF, this.fn(d.fn, d.fnSrc ?? null), child);
7044
7046
  }
7045
7047
  case "node": {
7046
7048
  if (d.type === void 0) missingInferredType();
@@ -7265,6 +7267,7 @@ var Encoder = class {
7265
7267
  case OP_WITHCTX:
7266
7268
  case OP_XFORM:
7267
7269
  case OP_LEAF:
7270
+ case OP_SOURCE_LEAF:
7268
7271
  case OP_NODE:
7269
7272
  case OP_NODE_TRACK:
7270
7273
  return [ip + 2];
@@ -8474,6 +8477,7 @@ function childSlots(code, ip, out) {
8474
8477
  case OP_NODE_TRACK:
8475
8478
  case OP_FIELD:
8476
8479
  case OP_LEAF:
8480
+ case OP_SOURCE_LEAF:
8477
8481
  case OP_ARMGATE:
8478
8482
  out.push(code[ip + 2]);
8479
8483
  return true;
@@ -8582,7 +8586,7 @@ function transfer(code, ip, at, hostCst) {
8582
8586
  if (at.tri === TRI_NONE && !at.buf) return at;
8583
8587
  return { tri: TRI_NONE, buf: false, raw: RAW_UNKNOWN, cap: at.cap };
8584
8588
  }
8585
- if (op === OP_LEAF) {
8589
+ if (op === OP_LEAF || op === OP_SOURCE_LEAF) {
8586
8590
  if (!at.buf) return at;
8587
8591
  return { tri: at.tri, buf: false, raw: RAW_UNKNOWN, cap: at.cap };
8588
8592
  }
@@ -8669,7 +8673,7 @@ function leadingScalarTerminal(code, ip, minDepth = 2, throughAttempt = true, th
8669
8673
  depth++;
8670
8674
  continue;
8671
8675
  }
8672
- if (op === OP_GATE || op === OP_SCOPE || op === OP_SCOPE_CAP || op === OP_SCOPE_PLAIN || op === OP_XFORM || op === OP_NODE || op === OP_FIELD || op === OP_LEAF) {
8676
+ if (op === OP_GATE || op === OP_SCOPE || op === OP_SCOPE_CAP || op === OP_SCOPE_PLAIN || op === OP_XFORM || op === OP_NODE || op === OP_FIELD || (op === OP_LEAF || op === OP_SOURCE_LEAF)) {
8673
8677
  at = code[at + 2];
8674
8678
  depth++;
8675
8679
  continue;
@@ -8702,7 +8706,7 @@ function leadingScalarSequence(code, ip) {
8702
8706
  at2 = code[at2 + 1];
8703
8707
  continue;
8704
8708
  }
8705
- if (op === OP_GATE || op === OP_SCOPE_PLAIN || op === OP_XFORM || op === OP_NODE || op === OP_FIELD || op === OP_LEAF) {
8709
+ if (op === OP_GATE || op === OP_SCOPE_PLAIN || op === OP_XFORM || op === OP_NODE || op === OP_FIELD || (op === OP_LEAF || op === OP_SOURCE_LEAF)) {
8706
8710
  at2 = code[at2 + 2];
8707
8711
  continue;
8708
8712
  }
@@ -8735,7 +8739,7 @@ function leadingScalarSequence(code, ip) {
8735
8739
  at = code[at + 2];
8736
8740
  continue;
8737
8741
  }
8738
- if (op === OP_GATE || op === OP_XFORM || op === OP_NODE || op === OP_FIELD || op === OP_LEAF) {
8742
+ if (op === OP_GATE || op === OP_XFORM || op === OP_NODE || op === OP_FIELD || (op === OP_LEAF || op === OP_SOURCE_LEAF)) {
8739
8743
  at = code[at + 2];
8740
8744
  continue;
8741
8745
  }
@@ -8765,7 +8769,7 @@ function leadingLiteralFamily(code, constants, ip, minDepth = 2, limit = 4) {
8765
8769
  if (op === OP_RULE || op === OP_LABEL || op === OP_TOKEN || op === OP_ATTEMPT || op === OP_PEEK) {
8766
8770
  return walk(code[at + 1], depth + 1);
8767
8771
  }
8768
- if (op === OP_GATE || op === OP_SCOPE || op === OP_SCOPE_CAP || op === OP_SCOPE_PLAIN || op === OP_XFORM || op === OP_NODE || op === OP_FIELD || op === OP_LEAF) {
8772
+ if (op === OP_GATE || op === OP_SCOPE || op === OP_SCOPE_CAP || op === OP_SCOPE_PLAIN || op === OP_XFORM || op === OP_NODE || op === OP_FIELD || (op === OP_LEAF || op === OP_SOURCE_LEAF)) {
8769
8773
  return walk(code[at + 2], depth + 1);
8770
8774
  }
8771
8775
  if (op === OP_SEQ || op === OP_SEQV) {
@@ -9651,8 +9655,10 @@ ${rootCap ? "ctx._rootTriviaCapture=sR\n" : ""}return v
9651
9655
  }
9652
9656
  /* ── boundaries ──────────────────────────────────────────────────────── */
9653
9657
  case OP_TOKEN:
9654
- case OP_LEAF: {
9658
+ case OP_LEAF:
9659
+ case OP_SOURCE_LEAF: {
9655
9660
  const isToken = op === OP_TOKEN;
9661
+ const capturesSource = isToken || op === OP_SOURCE_LEAF && hostCst;
9656
9662
  const fn = isToken ? void 0 : fnRef(code[ip + 1]);
9657
9663
  const child = link(isToken ? code[ip + 1] : code[ip + 2]);
9658
9664
  const wasCap = L.buf ? "true" : "(ctx._cstBuf!==undefined||ctx._cstLeaves!==undefined)";
@@ -9685,7 +9691,7 @@ ctx._triviaLog=sOtl
9685
9691
  if(v===FAIL)return FAIL
9686
9692
  const e=EC.e
9687
9693
  const out=${isToken ? "input.slice(pos,e)" : `${fn}(v,{start:pos,end:e})`}
9688
- if(wasCap)pushCstLeaf(ctx,{_tag:'leaf',value:out,span:{start:pos,end:e}})
9694
+ if(wasCap)pushCstLeaf(ctx,{_tag:'leaf',value:${capturesSource ? "input.slice(pos,e)" : "out"},span:{start:pos,end:e}})
9689
9695
  EC.e=e
9690
9696
  return out
9691
9697
  }`;
@@ -10836,6 +10842,12 @@ function ref() {
10836
10842
  }
10837
10843
 
10838
10844
  // src/combinators/token.ts
10845
+ function semanticLeafValue(_ctx, _input, _start, _end, value) {
10846
+ return value;
10847
+ }
10848
+ function sourceLeafValue(ctx, input, start, end, value) {
10849
+ return cstOutputHost(ctx.build) ? input.slice(start, end) : value;
10850
+ }
10839
10851
  function token(root) {
10840
10852
  const meta = {
10841
10853
  firstSet: root._meta.firstSet,
@@ -10888,7 +10900,8 @@ function token(root) {
10888
10900
  }
10889
10901
  };
10890
10902
  }
10891
- function leaf(root, fn) {
10903
+ function makeLeaf(root, fn, sourceCstValue) {
10904
+ const cstValue = sourceCstValue ? sourceLeafValue : semanticLeafValue;
10892
10905
  const meta = {
10893
10906
  firstSet: root._meta.firstSet,
10894
10907
  canMatchNewline: root._meta.canMatchNewline,
@@ -10897,7 +10910,12 @@ function leaf(root, fn) {
10897
10910
  return {
10898
10911
  _tag: "leaf",
10899
10912
  _meta: meta,
10900
- _def: { tag: "leaf", parser: root, fn },
10913
+ _def: {
10914
+ tag: "leaf",
10915
+ parser: root,
10916
+ fn,
10917
+ ...sourceCstValue ? { cstValue: "source" } : {}
10918
+ },
10901
10919
  parse(input, pos, ctx) {
10902
10920
  const savedBuf = ctx._cstBuf;
10903
10921
  const savedChildren = ctx._cstChildren;
@@ -10925,11 +10943,21 @@ function leaf(root, fn) {
10925
10943
  }
10926
10944
  if (!result.ok) return result;
10927
10945
  const value = fn(result.value, result.span);
10928
- if (wasCapturing) pushCstLeaf(ctx, { _tag: "leaf", value, span: result.span });
10946
+ if (wasCapturing) pushCstLeaf(ctx, {
10947
+ _tag: "leaf",
10948
+ value: cstValue(ctx, input, pos, result.span.end, value),
10949
+ span: result.span
10950
+ });
10929
10951
  return { ok: true, value, span: result.span };
10930
10952
  }
10931
10953
  };
10932
10954
  }
10955
+ function leaf(root, fn) {
10956
+ return makeLeaf(root, fn, false);
10957
+ }
10958
+ function sourceLeaf(root, fn) {
10959
+ return makeLeaf(root, fn, true);
10960
+ }
10933
10961
 
10934
10962
  // src/combinators/scanTo.ts
10935
10963
  function resolveScanSkip(explicitSkip, raw, ctx) {
@@ -12717,7 +12745,8 @@ function assemble(t2, prog, cfg) {
12717
12745
  return value;
12718
12746
  };
12719
12747
  }
12720
- case OP_LEAF: {
12748
+ case OP_LEAF:
12749
+ case OP_SOURCE_LEAF: {
12721
12750
  const fn = fns[code[ip + 1]];
12722
12751
  const child = link(code[ip + 2]);
12723
12752
  return (input, pos, ctx) => {
@@ -12745,7 +12774,11 @@ function assemble(t2, prog, cfg) {
12745
12774
  if (v === FAIL) return FAIL;
12746
12775
  const end = EC.e;
12747
12776
  const out = fn(v, { start: pos, end });
12748
- if (wasCapturing) pushCstLeaf(ctx, { _tag: "leaf", value: out, span: { start: pos, end } });
12777
+ if (wasCapturing) pushCstLeaf(ctx, {
12778
+ _tag: "leaf",
12779
+ value: op === OP_SOURCE_LEAF && hostCst ? input.slice(pos, end) : out,
12780
+ span: { start: pos, end }
12781
+ });
12749
12782
  EC.e = end;
12750
12783
  return out;
12751
12784
  };
@@ -14775,7 +14808,7 @@ function payloadKey(p, d) {
14775
14808
  case "transform":
14776
14809
  return `transform\0${fnKey(d.fnSrc, d.fn)}\0${d.recognitionOnly === true}`;
14777
14810
  case "leaf":
14778
- return `leaf\0${fnKey(d.fnSrc, d.fn)}`;
14811
+ return `leaf\0${d.cstValue ?? "value"}\0${fnKey(d.fnSrc, d.fn)}`;
14779
14812
  case "many":
14780
14813
  case "oneOrMore":
14781
14814
  return `${d.tag}\0${d.min}\0${d.max ?? ""}`;
@@ -16566,7 +16599,7 @@ function rebuildCombinator(root, replacements) {
16566
16599
  out = token(one(d.parser));
16567
16600
  break;
16568
16601
  case "leaf":
16569
- out = leaf(one(d.parser), d.fn);
16602
+ out = d.cstValue === "source" ? sourceLeaf(one(d.parser), d.fn) : leaf(one(d.parser), d.fn);
16570
16603
  break;
16571
16604
  // A LABELLED expect reproduces `d.expected` exactly (`expect` sets it to `[label]`).
16572
16605
  // An unlabelled one RE-DERIVES it from the rebuilt inner parser, so it can differ