parseman 0.42.0 → 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 +23 -2
- package/dist/combinators/parser.d.ts.map +1 -1
- package/dist/compiler/codegen.d.ts +6 -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 +7 -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 +375 -195
- 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 +375 -195
- 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 +654 -173
- package/dist/plugin/index.cjs.map +4 -4
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +654 -173
- package/dist/plugin/index.js.map +4 -4
- package/dist/spec/index.cjs +429 -313
- package/dist/spec/index.cjs.map +4 -4
- package/dist/spec/index.js +429 -313
- package/dist/spec/index.js.map +4 -4
- package/dist/types.d.ts +8 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* consumer's config, never in the grammar.
|
|
17
17
|
*/
|
|
18
18
|
import type { Combinator, ParseContext, ParseResult, Span, ParseError } from '../types.ts';
|
|
19
|
-
import {
|
|
19
|
+
import type { Walkable } from '../cst/walk.ts';
|
|
20
20
|
import { type Registry } from '../functional/doc.ts';
|
|
21
21
|
import type { NodeLike } from '../cst/types.ts';
|
|
22
22
|
export type Severity = 'error' | 'warning' | 'info';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/language-service/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAI1F,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/language-service/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAI1F,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAE9D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAE/C,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAA;AACnD,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAAA;AAC5E,MAAM,MAAM,cAAc,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAE/D,wFAAwF;AACxF,MAAM,MAAM,M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W,IAAI,UAAU,EAAE,CAAA;IAC3B,0DAA0D;IAC1D,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,EAAE,CAAA;CAChD,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,WAAW,CAAC,OAAO,CAAC,GAAG;QAAE,MAAM,EAAE,UAAU,EAAE,CAAA;KAAE,CAAA;IAClG,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,EAAE,CAAA;IACtC,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,cAAc,EAAE,CAAA;IAC5D,wFAAwF;IACxF,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;CACtC,CAAA;AAqED,wBAAgB,eAAe,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,GAAE,qBAA0B,GAAG,eAAe,CA0D1G"}
|
|
@@ -450,15 +450,16 @@ function normalizeCstCollapse(collapse) {
|
|
|
450
450
|
}
|
|
451
451
|
return typeof collapse === "function" ? collapse : void 0;
|
|
452
452
|
}
|
|
453
|
-
function buildCstNode(type, children, _fields, span, _rawChildren, _triviaLog, state) {
|
|
454
|
-
return { _tag: "node", type, span: { ...span }, state: state ?? null, children: [...children] };
|
|
453
|
+
function buildCstNode(type, children, _fields, span, _rawChildren, _triviaLog, state, tags) {
|
|
454
|
+
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] };
|
|
455
455
|
}
|
|
456
|
-
function cstBuildHost(typeOrOptions, children, _fields, span, rawChildren, triviaLog, state) {
|
|
456
|
+
function cstBuildHost(typeOrOptions, children, _fields, span, rawChildren, triviaLog, state, _tags) {
|
|
457
457
|
if (typeof typeOrOptions === "string") {
|
|
458
458
|
return buildCstNode(typeOrOptions, children ?? [], _fields, span ?? { start: 0, end: 0 }, rawChildren, triviaLog, state);
|
|
459
459
|
}
|
|
460
460
|
const collapse = normalizeCstCollapse(typeOrOptions?.collapse);
|
|
461
|
-
const
|
|
461
|
+
const materializeTags = typeOrOptions?.tags === true;
|
|
462
|
+
const host = (type, children2, fields, span2, rawChildren2, triviaLog2, state2, tags) => buildCstNode(type, children2 ?? [], fields, span2, rawChildren2, triviaLog2, state2, materializeTags ? tags : void 0);
|
|
462
463
|
host._parsemanCstOutput = true;
|
|
463
464
|
if (collapse) host._parsemanCstCollapse = collapse;
|
|
464
465
|
return host;
|
|
@@ -472,19 +473,6 @@ function fusedHostElidedOf(registry) {
|
|
|
472
473
|
return registry[FUSED_HOST_ELIDED] === true;
|
|
473
474
|
}
|
|
474
475
|
|
|
475
|
-
// src/cst/walk.ts
|
|
476
|
-
function walk(root, visitor, ctx = void 0) {
|
|
477
|
-
const go = (node2, parent) => {
|
|
478
|
-
const descend = visitor.enter ? visitor.enter(node2, parent, ctx) : void 0;
|
|
479
|
-
const children = node2.children;
|
|
480
|
-
if (descend !== false && Array.isArray(children)) {
|
|
481
|
-
for (const child of children) go(child, node2);
|
|
482
|
-
}
|
|
483
|
-
visitor.leave?.(node2, parent, ctx);
|
|
484
|
-
};
|
|
485
|
-
go(root, null);
|
|
486
|
-
}
|
|
487
|
-
|
|
488
476
|
// src/cst/relative-spans.ts
|
|
489
477
|
function relativizeCST(node2, parentBase = 0) {
|
|
490
478
|
const span = { start: node2.span.start - parentBase, end: node2.span.end - parentBase };
|
|
@@ -927,6 +915,14 @@ function parseDoc(registry, rootRule, input, opts = {}) {
|
|
|
927
915
|
|
|
928
916
|
// src/language-service/index.ts
|
|
929
917
|
var errorMessage = (expected) => expected.length ? `Unexpected input; expected ${expected.join(" or ")}` : "Unexpected input";
|
|
918
|
+
function visitTree(root, enter) {
|
|
919
|
+
const go = (node2) => {
|
|
920
|
+
enter(node2);
|
|
921
|
+
const children = node2.children;
|
|
922
|
+
if (Array.isArray(children)) for (const child of children) go(child);
|
|
923
|
+
};
|
|
924
|
+
go(root);
|
|
925
|
+
}
|
|
930
926
|
function mergeDiagnostics(tree, flat, unconsumedFrom, inputLength, config) {
|
|
931
927
|
const out = [];
|
|
932
928
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -946,17 +942,15 @@ function mergeDiagnostics(tree, flat, unconsumedFrom, inputLength, config) {
|
|
|
946
942
|
function diagnoseTree(root, config) {
|
|
947
943
|
const out = [];
|
|
948
944
|
const rules2 = config.diagnostics;
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
if (d) out.push(...Array.isArray(d) ? d : [d]);
|
|
959
|
-
}
|
|
945
|
+
visitTree(root, (node2) => {
|
|
946
|
+
if (node2._tag === "parseError") {
|
|
947
|
+
out.push({ severity: "error", message: errorMessage(node2.expected ?? []), span: node2.span });
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
const h = rules2 && node2.type !== void 0 ? rules2[node2.type] : void 0;
|
|
951
|
+
if (h) {
|
|
952
|
+
const d = h(node2);
|
|
953
|
+
if (d) out.push(...Array.isArray(d) ? d : [d]);
|
|
960
954
|
}
|
|
961
955
|
});
|
|
962
956
|
return out;
|
|
@@ -1014,11 +1008,9 @@ function languageService(grammar, config = {}) {
|
|
|
1014
1008
|
function ruleAtCursor(root, offset) {
|
|
1015
1009
|
if (!root || typeof root !== "object") return null;
|
|
1016
1010
|
let best = null;
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
if (s && s.start <= offset && offset <= s.end && node2.type !== void 0) best = node2.type;
|
|
1021
|
-
}
|
|
1011
|
+
visitTree(root, (node2) => {
|
|
1012
|
+
const s = node2.span;
|
|
1013
|
+
if (s && s.start <= offset && offset <= s.end && node2.type !== void 0) best = node2.type;
|
|
1022
1014
|
});
|
|
1023
1015
|
return best;
|
|
1024
1016
|
}
|