parseman 0.42.1 → 0.43.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 (42) hide show
  1. package/dist/combinators/node.d.ts +21 -7
  2. package/dist/combinators/node.d.ts.map +1 -1
  3. package/dist/combinators/parser.d.ts +17 -2
  4. package/dist/combinators/parser.d.ts.map +1 -1
  5. package/dist/compiler/codegen.d.ts +4 -0
  6. package/dist/compiler/codegen.d.ts.map +1 -1
  7. package/dist/compiler/ir-serialize.d.ts.map +1 -1
  8. package/dist/compiler/linker.d.ts +6 -1
  9. package/dist/compiler/linker.d.ts.map +1 -1
  10. package/dist/cst/reflection.d.ts +24 -0
  11. package/dist/cst/reflection.d.ts.map +1 -0
  12. package/dist/cst/types.d.ts +2 -0
  13. package/dist/cst/types.d.ts.map +1 -1
  14. package/dist/cst/walk.d.ts +27 -62
  15. package/dist/cst/walk.d.ts.map +1 -1
  16. package/dist/index.cjs +227 -84
  17. package/dist/index.cjs.map +4 -4
  18. package/dist/index.d.ts +4 -3
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +227 -84
  21. package/dist/index.js.map +4 -4
  22. package/dist/language-service/index.cjs +25 -33
  23. package/dist/language-service/index.cjs.map +4 -4
  24. package/dist/language-service/index.d.ts +1 -1
  25. package/dist/language-service/index.d.ts.map +1 -1
  26. package/dist/language-service/index.js +25 -33
  27. package/dist/language-service/index.js.map +4 -4
  28. package/dist/plugin/evaluator.d.ts +1 -0
  29. package/dist/plugin/evaluator.d.ts.map +1 -1
  30. package/dist/plugin/index.cjs +323 -78
  31. package/dist/plugin/index.cjs.map +4 -4
  32. package/dist/plugin/index.d.ts.map +1 -1
  33. package/dist/plugin/index.js +323 -78
  34. package/dist/plugin/index.js.map +4 -4
  35. package/dist/spec/index.cjs +107 -6
  36. package/dist/spec/index.cjs.map +4 -4
  37. package/dist/spec/index.js +107 -6
  38. package/dist/spec/index.js.map +4 -4
  39. package/dist/types.d.ts +2 -1
  40. package/dist/types.d.ts.map +1 -1
  41. package/dist/version.d.ts +1 -1
  42. package/package.json +1 -1
@@ -476,15 +476,16 @@ function normalizeCstCollapse(collapse) {
476
476
  }
477
477
  return typeof collapse === "function" ? collapse : void 0;
478
478
  }
479
- function buildCstNode(type, children, _fields, span, _rawChildren, _triviaLog, state) {
480
- return { _tag: "node", type, span: { ...span }, state: state ?? null, children: [...children] };
479
+ function buildCstNode(type, children, _fields, span, _rawChildren, _triviaLog, state, tags) {
480
+ return tags !== void 0 && tags.length > 0 ? { _tag: "node", type, tags, span: { ...span }, state: state ?? null, children: [...children] } : { _tag: "node", type, span: { ...span }, state: state ?? null, children: [...children] };
481
481
  }
482
- function cstBuildHost(typeOrOptions, children, _fields, span, rawChildren, triviaLog, state) {
482
+ function cstBuildHost(typeOrOptions, children, _fields, span, rawChildren, triviaLog, state, _tags) {
483
483
  if (typeof typeOrOptions === "string") {
484
484
  return buildCstNode(typeOrOptions, children ?? [], _fields, span ?? { start: 0, end: 0 }, rawChildren, triviaLog, state);
485
485
  }
486
486
  const collapse = normalizeCstCollapse(typeOrOptions?.collapse);
487
- const host = (type, children2, fields, span2, rawChildren2, triviaLog2, state2) => buildCstNode(type, children2 ?? [], fields, span2, rawChildren2, triviaLog2, state2);
487
+ const materializeTags = typeOrOptions?.tags === true;
488
+ const host = (type, children2, fields, span2, rawChildren2, triviaLog2, state2, tags) => buildCstNode(type, children2 ?? [], fields, span2, rawChildren2, triviaLog2, state2, materializeTags ? tags : void 0);
488
489
  host._parsemanCstOutput = true;
489
490
  if (collapse) host._parsemanCstCollapse = collapse;
490
491
  return host;
@@ -498,19 +499,6 @@ function fusedHostElidedOf(registry) {
498
499
  return registry[FUSED_HOST_ELIDED] === true;
499
500
  }
500
501
 
501
- // src/cst/walk.ts
502
- function walk(root, visitor, ctx = void 0) {
503
- const go = (node2, parent) => {
504
- const descend = visitor.enter ? visitor.enter(node2, parent, ctx) : void 0;
505
- const children = node2.children;
506
- if (descend !== false && Array.isArray(children)) {
507
- for (const child of children) go(child, node2);
508
- }
509
- visitor.leave?.(node2, parent, ctx);
510
- };
511
- go(root, null);
512
- }
513
-
514
502
  // src/cst/relative-spans.ts
515
503
  function relativizeCST(node2, parentBase = 0) {
516
504
  const span = { start: node2.span.start - parentBase, end: node2.span.end - parentBase };
@@ -953,6 +941,14 @@ function parseDoc(registry, rootRule, input, opts = {}) {
953
941
 
954
942
  // src/language-service/index.ts
955
943
  var errorMessage = (expected) => expected.length ? `Unexpected input; expected ${expected.join(" or ")}` : "Unexpected input";
944
+ function visitTree(root, enter) {
945
+ const go = (node2) => {
946
+ enter(node2);
947
+ const children = node2.children;
948
+ if (Array.isArray(children)) for (const child of children) go(child);
949
+ };
950
+ go(root);
951
+ }
956
952
  function mergeDiagnostics(tree, flat, unconsumedFrom, inputLength, config) {
957
953
  const out = [];
958
954
  const seen = /* @__PURE__ */ new Set();
@@ -972,17 +968,15 @@ function mergeDiagnostics(tree, flat, unconsumedFrom, inputLength, config) {
972
968
  function diagnoseTree(root, config) {
973
969
  const out = [];
974
970
  const rules2 = config.diagnostics;
975
- walk(root, {
976
- enter(node2) {
977
- if (node2._tag === "parseError") {
978
- out.push({ severity: "error", message: errorMessage(node2.expected ?? []), span: node2.span });
979
- return;
980
- }
981
- const h = rules2 && node2.type !== void 0 ? rules2[node2.type] : void 0;
982
- if (h) {
983
- const d = h(node2);
984
- if (d) out.push(...Array.isArray(d) ? d : [d]);
985
- }
971
+ visitTree(root, (node2) => {
972
+ if (node2._tag === "parseError") {
973
+ out.push({ severity: "error", message: errorMessage(node2.expected ?? []), span: node2.span });
974
+ return;
975
+ }
976
+ const h = rules2 && node2.type !== void 0 ? rules2[node2.type] : void 0;
977
+ if (h) {
978
+ const d = h(node2);
979
+ if (d) out.push(...Array.isArray(d) ? d : [d]);
986
980
  }
987
981
  });
988
982
  return out;
@@ -1040,11 +1034,9 @@ function languageService(grammar, config = {}) {
1040
1034
  function ruleAtCursor(root, offset) {
1041
1035
  if (!root || typeof root !== "object") return null;
1042
1036
  let best = null;
1043
- walk(root, {
1044
- enter(node2) {
1045
- const s = node2.span;
1046
- if (s && s.start <= offset && offset <= s.end && node2.type !== void 0) best = node2.type;
1047
- }
1037
+ visitTree(root, (node2) => {
1038
+ const s = node2.span;
1039
+ if (s && s.start <= offset && offset <= s.end && node2.type !== void 0) best = node2.type;
1048
1040
  });
1049
1041
  return best;
1050
1042
  }