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.
- package/dist/combinators/node.d.ts +21 -7
- package/dist/combinators/node.d.ts.map +1 -1
- package/dist/combinators/parser.d.ts +17 -2
- package/dist/combinators/parser.d.ts.map +1 -1
- package/dist/compiler/codegen.d.ts +4 -0
- package/dist/compiler/codegen.d.ts.map +1 -1
- package/dist/compiler/ir-serialize.d.ts.map +1 -1
- package/dist/compiler/linker.d.ts +6 -1
- package/dist/compiler/linker.d.ts.map +1 -1
- package/dist/cst/reflection.d.ts +24 -0
- package/dist/cst/reflection.d.ts.map +1 -0
- package/dist/cst/types.d.ts +2 -0
- package/dist/cst/types.d.ts.map +1 -1
- package/dist/cst/walk.d.ts +27 -62
- package/dist/cst/walk.d.ts.map +1 -1
- package/dist/index.cjs +227 -84
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +227 -84
- package/dist/index.js.map +4 -4
- package/dist/language-service/index.cjs +25 -33
- package/dist/language-service/index.cjs.map +4 -4
- package/dist/language-service/index.d.ts +1 -1
- package/dist/language-service/index.d.ts.map +1 -1
- package/dist/language-service/index.js +25 -33
- package/dist/language-service/index.js.map +4 -4
- package/dist/plugin/evaluator.d.ts +1 -0
- package/dist/plugin/evaluator.d.ts.map +1 -1
- package/dist/plugin/index.cjs +323 -78
- package/dist/plugin/index.cjs.map +4 -4
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +323 -78
- package/dist/plugin/index.js.map +4 -4
- package/dist/spec/index.cjs +107 -6
- package/dist/spec/index.cjs.map +4 -4
- package/dist/spec/index.js +107 -6
- package/dist/spec/index.js.map +4 -4
- package/dist/types.d.ts +2 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- 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
|
|
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
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
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
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
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
|
}
|