parseman 0.39.1 → 0.41.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/README.md +9 -0
- package/dist/combinators/node.d.ts +15 -0
- package/dist/combinators/node.d.ts.map +1 -1
- package/dist/compiler/codegen.d.ts.map +1 -1
- package/dist/compiler/inline-callback.d.ts +9 -0
- package/dist/compiler/inline-callback.d.ts.map +1 -1
- package/dist/compiler/ir-serialize.d.ts.map +1 -1
- package/dist/compiler/value-usage.d.ts.map +1 -1
- package/dist/cst/trivia-entries.d.ts +52 -0
- package/dist/cst/trivia-entries.d.ts.map +1 -1
- package/dist/functional/run.d.ts +11 -2
- package/dist/functional/run.d.ts.map +1 -1
- package/dist/index.cjs +326 -91
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +326 -91
- package/dist/index.js.map +4 -4
- package/dist/language-service/index.cjs +155 -2
- package/dist/language-service/index.cjs.map +4 -4
- package/dist/language-service/index.js +155 -2
- package/dist/language-service/index.js.map +4 -4
- package/dist/plugin/evaluator.d.ts.map +1 -1
- package/dist/plugin/index.cjs +196 -58
- package/dist/plugin/index.cjs.map +4 -4
- package/dist/plugin/index.js +196 -58
- package/dist/plugin/index.js.map +4 -4
- package/dist/run/index.cjs +155 -1
- package/dist/run/index.cjs.map +4 -4
- package/dist/run/index.d.ts +7 -4
- package/dist/run/index.d.ts.map +1 -1
- package/dist/run/index.js +155 -1
- package/dist/run/index.js.map +4 -4
- package/dist/spec/index.cjs +35 -11
- package/dist/spec/index.cjs.map +2 -2
- package/dist/spec/index.js +35 -11
- package/dist/spec/index.js.map +2 -2
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +2 -1
package/dist/spec/index.js
CHANGED
|
@@ -320,9 +320,11 @@ function markUnusedValues(root) {
|
|
|
320
320
|
visit(def.parser, consumed);
|
|
321
321
|
visit(def.sentinel, false);
|
|
322
322
|
return;
|
|
323
|
+
case "token":
|
|
324
|
+
visit(def.parser, false);
|
|
325
|
+
return;
|
|
323
326
|
case "label":
|
|
324
327
|
case "trivia":
|
|
325
|
-
case "token":
|
|
326
328
|
case "attempt":
|
|
327
329
|
case "withCtx":
|
|
328
330
|
case "expect":
|
|
@@ -2222,7 +2224,7 @@ var META = new Set("()[]{}*+?|^$.".split(""));
|
|
|
2222
2224
|
var CAP_RECORD = [
|
|
2223
2225
|
` if (_cap && _e > _pos) {`,
|
|
2224
2226
|
` if (_ctx._triviaLog !== undefined) _ctx._triviaLog.push(_pos, _e)`,
|
|
2225
|
-
` if (_ctx._cstTriviaLog !== undefined && _ctx.captureTrivia) _ctx._cstTriviaLog.push(_pos, _e, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0)`,
|
|
2227
|
+
` if (_cap === 1 && _ctx._cstTriviaLog !== undefined && _ctx.captureTrivia) _ctx._cstTriviaLog.push(_pos, _e, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0)`,
|
|
2226
2228
|
` }`
|
|
2227
2229
|
].join("\n");
|
|
2228
2230
|
|
|
@@ -2730,12 +2732,30 @@ function isCstChild(value) {
|
|
|
2730
2732
|
function missingInferredType() {
|
|
2731
2733
|
throw new Error('node(): inferred node type requires a rules() key; pass node("Type", parser) outside rules()');
|
|
2732
2734
|
}
|
|
2735
|
+
function normalizeProject(project) {
|
|
2736
|
+
if (project === void 0) return void 0;
|
|
2737
|
+
if (!Number.isInteger(project) || project < 0) {
|
|
2738
|
+
throw new Error("node() project child must be a non-negative integer");
|
|
2739
|
+
}
|
|
2740
|
+
return project;
|
|
2741
|
+
}
|
|
2742
|
+
function projectChild(children, project, type) {
|
|
2743
|
+
if (!(project in children)) {
|
|
2744
|
+
throw new Error(`node(${JSON.stringify(type)}) project child ${project} was not captured`);
|
|
2745
|
+
}
|
|
2746
|
+
return unwrapChild(children[project]);
|
|
2747
|
+
}
|
|
2733
2748
|
function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
|
|
2734
2749
|
const hasExplicitType = typeof typeOrCombinator === "string";
|
|
2735
2750
|
const type = hasExplicitType ? typeOrCombinator : void 0;
|
|
2736
2751
|
const combinator = hasExplicitType ? combinatorOrBuild : typeOrCombinator;
|
|
2737
|
-
const
|
|
2738
|
-
const
|
|
2752
|
+
const buildArg = hasExplicitType ? buildOrOpts : combinatorOrBuild;
|
|
2753
|
+
const build = typeof buildArg === "function" ? buildArg : void 0;
|
|
2754
|
+
const opts = typeof buildArg === "function" ? maybeOpts : buildArg ?? maybeOpts;
|
|
2755
|
+
const project = normalizeProject(opts?.project);
|
|
2756
|
+
if (project !== void 0 && build !== void 0) {
|
|
2757
|
+
throw new Error("node() options cannot combine project with a build callback");
|
|
2758
|
+
}
|
|
2739
2759
|
const baseDef = { tag: "node", parser: combinator, ...type === void 0 ? {} : { type }, ...build === void 0 ? {} : { build } };
|
|
2740
2760
|
const meta = {
|
|
2741
2761
|
firstSet: combinator._meta.firstSet,
|
|
@@ -2749,11 +2769,14 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
|
|
|
2749
2769
|
if (unwrap && collapse) {
|
|
2750
2770
|
throw new Error("node() options cannot set both unwrap and collapse");
|
|
2751
2771
|
}
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2772
|
+
if (project !== void 0 && (unwrap || collapse)) {
|
|
2773
|
+
throw new Error("node() options cannot combine project with unwrap or collapse");
|
|
2774
|
+
}
|
|
2775
|
+
const def = unwrap || collapse || project !== void 0 || captureTrivia || trailingTrivia ? { ...baseDef, ...unwrap ? { unwrap: true } : {}, ...collapse ? { collapse: true } : {}, ...project !== void 0 ? { project } : {}, ...captureTrivia ? { captureTrivia: true } : {}, ...trailingTrivia ? { trailingTrivia: true } : {} } : baseDef;
|
|
2776
|
+
const capturesTrivia = captureTrivia || trailingTrivia || (build ? buildReadsTrivia(def) : project === void 0);
|
|
2777
|
+
const clonesState = build ? buildReadsState(def) : project === void 0;
|
|
2755
2778
|
const hasOwnFields = parserHasOwnFields(combinator);
|
|
2756
|
-
const capturesFields = hasOwnFields && (build ? buildReadsFields(def) :
|
|
2779
|
+
const capturesFields = hasOwnFields && (build ? buildReadsFields(def) : project === void 0);
|
|
2757
2780
|
const guardable = combinator._meta.firstSet.kind !== "any" && !matchesEmpty(combinator);
|
|
2758
2781
|
let failExpected;
|
|
2759
2782
|
return {
|
|
@@ -2768,14 +2791,15 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
|
|
|
2768
2791
|
}
|
|
2769
2792
|
return { ok: false, expected: failExpected, span: { start: pos, end: pos } };
|
|
2770
2793
|
}
|
|
2771
|
-
const
|
|
2794
|
+
const hasDirectValue = build !== void 0 || project !== void 0;
|
|
2795
|
+
const hostCst = hasDirectValue && cstOutputHost(ctx.build);
|
|
2772
2796
|
const effTrivia = capturesTrivia || hostCst;
|
|
2773
2797
|
const effFields = capturesFields || hostCst && hasOwnFields;
|
|
2774
2798
|
const saved = beginCstNodeCapture(ctx);
|
|
2775
2799
|
const savedFields = ctx._fields;
|
|
2776
2800
|
ctx._fields = effFields ? [] : void 0;
|
|
2777
2801
|
const savedMask = ctx._triviaCaptureMask;
|
|
2778
|
-
if (build === void 0 && ctx.build?._parsemanTriviaKinds !== void 0 && def.type !== void 0) {
|
|
2802
|
+
if (build === void 0 && project === void 0 && ctx.build?._parsemanTriviaKinds !== void 0 && def.type !== void 0) {
|
|
2779
2803
|
ctx._triviaCaptureMask = ctx.build._parsemanTriviaKinds(def.type);
|
|
2780
2804
|
}
|
|
2781
2805
|
if (!effTrivia) ctx.captureTrivia = false;
|
|
@@ -2793,7 +2817,7 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
|
|
|
2793
2817
|
const nodeType = def.type ?? missingInferredType();
|
|
2794
2818
|
const cstOutput = cstOutputHost(ctx.build);
|
|
2795
2819
|
const hostState = clonesState ? st : ctx.state !== void 0 ? Object.assign({}, ctx.state) : void 0;
|
|
2796
|
-
const built = unwrap && children.length === 1 ? unwrapChild(children[0]) : collapse && children.length === 1 ? children[0] : !build && ctx.build?._parsemanCstCollapse && children.length === 1 && rawChildren.length === 1 && ctx.build._parsemanCstCollapse(nodeType, children[0], children, rawChildren) ? children[0] : build ? cstOutput && ctx.build ? ctx.build(nodeType, children, fields, r.span, rawChildren, triviaLog, hostState) : build(children, fields, r.span, rawChildren, triviaLog, st) : ctx.build ? ctx.build(nodeType, children, fields, r.span, rawChildren, triviaLog, st) : { _tag: "node", type: nodeType, span: { start: r.span.start, end: r.span.end }, state: st ?? null, children };
|
|
2820
|
+
const built = unwrap && children.length === 1 ? unwrapChild(children[0]) : collapse && children.length === 1 ? children[0] : !build && project === void 0 && ctx.build?._parsemanCstCollapse && children.length === 1 && rawChildren.length === 1 && ctx.build._parsemanCstCollapse(nodeType, children[0], children, rawChildren) ? children[0] : project !== void 0 ? cstOutput && ctx.build ? ctx.build(nodeType, children, fields, r.span, rawChildren, triviaLog, hostState) : projectChild(children, project, nodeType) : build ? cstOutput && ctx.build ? ctx.build(nodeType, children, fields, r.span, rawChildren, triviaLog, hostState) : build(children, fields, r.span, rawChildren, triviaLog, st) : ctx.build ? ctx.build(nodeType, children, fields, r.span, rawChildren, triviaLog, st) : { _tag: "node", type: nodeType, span: { start: r.span.start, end: r.span.end }, state: st ?? null, children };
|
|
2797
2821
|
const rawEntry = isCstChild(built) ? built : { _tag: "leaf", value: typeof built === "string" ? built : typeof built === "object" && built !== null ? input.slice(r.span.start, r.span.end) : "", span: r.span };
|
|
2798
2822
|
if (saved.buf !== void 0 || saved.ch !== void 0) {
|
|
2799
2823
|
pushCstChild(ctx, built, rawEntry);
|