parseman 0.51.0 → 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 +59 -21
  11. package/dist/index.js.map +1 -1
  12. package/dist/plugin/evaluator.d.ts.map +1 -1
  13. package/dist/plugin/index.js +59 -22
  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 +11 -7
  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
@@ -4933,6 +4933,12 @@ function field(name, combinator) {
4933
4933
  }
4934
4934
 
4935
4935
  // src/combinators/token.ts
4936
+ function semanticLeafValue(_ctx, _input, _start, _end, value) {
4937
+ return value;
4938
+ }
4939
+ function sourceLeafValue(ctx, input, start, end, value) {
4940
+ return cstOutputHost(ctx.build) ? input.slice(start, end) : value;
4941
+ }
4936
4942
  function token(root) {
4937
4943
  const meta = {
4938
4944
  firstSet: root._meta.firstSet,
@@ -4985,7 +4991,8 @@ function token(root) {
4985
4991
  }
4986
4992
  };
4987
4993
  }
4988
- function leaf(root, fn) {
4994
+ function makeLeaf(root, fn, sourceCstValue) {
4995
+ const cstValue = sourceCstValue ? sourceLeafValue : semanticLeafValue;
4989
4996
  const meta = {
4990
4997
  firstSet: root._meta.firstSet,
4991
4998
  canMatchNewline: root._meta.canMatchNewline,
@@ -4994,7 +5001,12 @@ function leaf(root, fn) {
4994
5001
  return {
4995
5002
  _tag: "leaf",
4996
5003
  _meta: meta,
4997
- _def: { tag: "leaf", parser: root, fn },
5004
+ _def: {
5005
+ tag: "leaf",
5006
+ parser: root,
5007
+ fn,
5008
+ ...sourceCstValue ? { cstValue: "source" } : {}
5009
+ },
4998
5010
  parse(input, pos, ctx) {
4999
5011
  const savedBuf = ctx._cstBuf;
5000
5012
  const savedChildren = ctx._cstChildren;
@@ -5022,11 +5034,21 @@ function leaf(root, fn) {
5022
5034
  }
5023
5035
  if (!result.ok) return result;
5024
5036
  const value = fn(result.value, result.span);
5025
- if (wasCapturing) pushCstLeaf(ctx, { _tag: "leaf", value, span: result.span });
5037
+ if (wasCapturing) pushCstLeaf(ctx, {
5038
+ _tag: "leaf",
5039
+ value: cstValue(ctx, input, pos, result.span.end, value),
5040
+ span: result.span
5041
+ });
5026
5042
  return { ok: true, value, span: result.span };
5027
5043
  }
5028
5044
  };
5029
5045
  }
5046
+ function leaf(root, fn) {
5047
+ return makeLeaf(root, fn, false);
5048
+ }
5049
+ function sourceLeaf(root, fn) {
5050
+ return makeLeaf(root, fn, true);
5051
+ }
5030
5052
 
5031
5053
  // src/combinators/scanTo.ts
5032
5054
  function resolveScanSkip(explicitSkip, raw, ctx) {
@@ -5311,7 +5333,7 @@ function evalRuleMapIR(ir) {
5311
5333
  if (recognitionOnly) t._def.recognitionOnly = true;
5312
5334
  return t;
5313
5335
  };
5314
- const _lf = (child, src) => {
5336
+ const _lf = (child, src, source = false) => {
5315
5337
  let fn2;
5316
5338
  try {
5317
5339
  fn2 = (0, eval)(`(${src})`);
@@ -5320,7 +5342,7 @@ function evalRuleMapIR(ir) {
5320
5342
  throw new Error("IR leaf fn not materialized");
5321
5343
  };
5322
5344
  }
5323
- const l = leaf(child, fn2);
5345
+ const l = source ? sourceLeaf(child, fn2) : leaf(child, fn2);
5324
5346
  l._def.fnSrc = src;
5325
5347
  return l;
5326
5348
  };