parseman 0.39.1 β 0.40.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 +8 -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/ir-serialize.d.ts.map +1 -1
- package/dist/index.cjs +55 -20
- package/dist/index.cjs.map +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +55 -20
- package/dist/index.js.map +2 -2
- package/dist/plugin/evaluator.d.ts.map +1 -1
- package/dist/plugin/index.cjs +75 -24
- package/dist/plugin/index.cjs.map +2 -2
- package/dist/plugin/index.js +75 -24
- package/dist/plugin/index.js.map +2 -2
- package/dist/spec/index.cjs +31 -9
- package/dist/spec/index.cjs.map +2 -2
- package/dist/spec/index.js +31 -9
- 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/README.md
CHANGED
|
@@ -36,6 +36,12 @@ Reach for it when you want CST/AST nodes with spans and trivia, error recovery a
|
|
|
36
36
|
incremental re-parsing for editor tooling, or simply a fast parser for a DSL, config
|
|
37
37
|
language, formatter, or linter.
|
|
38
38
|
|
|
39
|
+
ParsΓ©man is scannerless without giving up token-style routing. When several branches share
|
|
40
|
+
a meaningful opener, `dispatch(selector, when(...), otherwise(...))` lets the grammar parse
|
|
41
|
+
that head once, then route by the returned value or structural marker. CSS-like grammars use
|
|
42
|
+
that for at-rules, identifier-or-function values, media features, and dialect routes where
|
|
43
|
+
interpolation and dedicated syntax overlap.
|
|
44
|
+
|
|
39
45
|
> **π Full documentation: [matthew-dean.github.io/parseman](https://matthew-dean.github.io/parseman/)**
|
|
40
46
|
|
|
41
47
|
## Install
|
|
@@ -108,6 +114,8 @@ See **[The three modes](https://matthew-dean.github.io/parseman/guide/modes)**.
|
|
|
108
114
|
`compose()` a dialect onto a base grammar instead of forking it.
|
|
109
115
|
- ποΈ **[Context-sensitive parsing](https://matthew-dean.github.io/parseman/guide/context)** β
|
|
110
116
|
`withCtx` / `gate` without mutating shared state.
|
|
117
|
+
- π§ **[Scannerless routing](https://matthew-dean.github.io/parseman/guide/combinators#dispatch)** β
|
|
118
|
+
`dispatch` parses a shared head once and routes at the grammar boundary that matters.
|
|
111
119
|
|
|
112
120
|
**π³ Getting structure out**
|
|
113
121
|
|
|
@@ -26,6 +26,8 @@ export type BuildNode<N> = (children: ReadonlyArray<unknown>, fields: FieldMap |
|
|
|
26
26
|
* returned as-is.
|
|
27
27
|
* - `collapse` β a structural wrapper rule that returns its single child exactly
|
|
28
28
|
* as captured. A leaf stays a CSTLeaf; a node stays a node.
|
|
29
|
+
* - `project` β return one captured semantic child by index while retaining the
|
|
30
|
+
* complete node frame for CST hosts. Leaves unwrap to their string value.
|
|
29
31
|
* - `captureTrivia` β capture trivia consumed inside this node even when its
|
|
30
32
|
* enclosing `parser()` did not opt into document-wide trivia capture. This is
|
|
31
33
|
* scoped to the node; sibling and parent nodes retain their own setting.
|
|
@@ -35,12 +37,25 @@ export type BuildNode<N> = (children: ReadonlyArray<unknown>, fields: FieldMap |
|
|
|
35
37
|
* Both skip `build` only for a one-child match; zero or two-plus children go
|
|
36
38
|
* through `build` normally.
|
|
37
39
|
*/
|
|
40
|
+
type ParserValue<P> = P extends Combinator<infer T> ? T : never;
|
|
41
|
+
type ProjectValue<P extends Combinator<unknown>, I extends number> = ParserValue<P> extends readonly unknown[] ? I extends keyof ParserValue<P> ? ParserValue<P>[I] : unknown : I extends 0 ? ParserValue<P> : unknown;
|
|
38
42
|
export type NodeOptions = {
|
|
39
43
|
unwrap?: boolean;
|
|
40
44
|
collapse?: boolean;
|
|
45
|
+
project?: number;
|
|
41
46
|
captureTrivia?: boolean;
|
|
42
47
|
trailingTrivia?: boolean;
|
|
43
48
|
};
|
|
49
|
+
export type NodeProjectOptions<I extends number = number> = Omit<NodeOptions, 'project' | 'unwrap' | 'collapse'> & {
|
|
50
|
+
project: I;
|
|
51
|
+
unwrap?: never;
|
|
52
|
+
collapse?: never;
|
|
53
|
+
};
|
|
54
|
+
export declare function node<P extends Combinator<unknown>, const I extends number>(combinator: P, opts: NodeProjectOptions<I>): Combinator<ProjectValue<P, I>>;
|
|
44
55
|
export declare function node<N>(combinator: Combinator<unknown>, build?: BuildNode<N>, opts?: NodeOptions): Combinator<N>;
|
|
56
|
+
export declare function node<N>(combinator: Combinator<unknown>, opts?: NodeOptions): Combinator<N>;
|
|
57
|
+
export declare function node<P extends Combinator<unknown>, const I extends number>(type: string, combinator: P, opts: NodeProjectOptions<I>): Combinator<ProjectValue<P, I>>;
|
|
45
58
|
export declare function node<N>(type: string, combinator: Combinator<unknown>, build?: BuildNode<N>, opts?: NodeOptions): Combinator<N>;
|
|
59
|
+
export declare function node<N>(type: string, combinator: Combinator<unknown>, opts?: NodeOptions): Combinator<N>;
|
|
60
|
+
export {};
|
|
46
61
|
//# sourceMappingURL=node.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/combinators/node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAoD,MAAM,aAAa,CAAA;AAQzG;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CACzB,QAAQ,EAAE,aAAa,CAAC,OAAO,CAAC,EAChC,MAAM,EAAE,QAAQ,GAAG,SAAS,EAC5B,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EACpC,WAAW,EAAE,aAAa,CAAC,OAAO,CAAC,EACnC,SAAS,EAAE,SAAS,MAAM,EAAE,EAC5B,KAAK,EAAE,OAAO,KACX,CAAC,CAAA;AAEN
|
|
1
|
+
{"version":3,"file":"node.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Ac,GAAG,IAAI,CAoPvB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,GAC7D,OAAO,CAeT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ir-serialize.d.ts","sourceRoot":"","sources":["../../src/compiler/ir-serialize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,EAAE,UAAU,EAAkC,MAAM,aAAa,CAAA;AAqB7E,KAAK,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"ir-serialize.d.ts","sourceRoot":"","sources":["../../src/compiler/ir-serialize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,EAAE,UAAU,EAAkC,MAAM,aAAa,CAAA;AAqB7E,KAAK,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,CAAA;AA0E/B,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,EAC/C,QAAQ,CAAC,EAAE,SAAS,IAAI,EAAE,GAAG,IAAI,GAChC,MAAM,GAAG,IAAI,CAUf;AAED;;oFAEoF;AACpF,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAqG/D"}
|
package/dist/index.cjs
CHANGED
|
@@ -3115,12 +3115,30 @@ function isCstChild(value) {
|
|
|
3115
3115
|
function missingInferredType() {
|
|
3116
3116
|
throw new Error('node(): inferred node type requires a rules() key; pass node("Type", parser) outside rules()');
|
|
3117
3117
|
}
|
|
3118
|
+
function normalizeProject(project) {
|
|
3119
|
+
if (project === void 0) return void 0;
|
|
3120
|
+
if (!Number.isInteger(project) || project < 0) {
|
|
3121
|
+
throw new Error("node() project child must be a non-negative integer");
|
|
3122
|
+
}
|
|
3123
|
+
return project;
|
|
3124
|
+
}
|
|
3125
|
+
function projectChild(children2, project, type) {
|
|
3126
|
+
if (!(project in children2)) {
|
|
3127
|
+
throw new Error(`node(${JSON.stringify(type)}) project child ${project} was not captured`);
|
|
3128
|
+
}
|
|
3129
|
+
return unwrapChild(children2[project]);
|
|
3130
|
+
}
|
|
3118
3131
|
function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
|
|
3119
3132
|
const hasExplicitType = typeof typeOrCombinator === "string";
|
|
3120
3133
|
const type = hasExplicitType ? typeOrCombinator : void 0;
|
|
3121
3134
|
const combinator = hasExplicitType ? combinatorOrBuild : typeOrCombinator;
|
|
3122
|
-
const
|
|
3123
|
-
const
|
|
3135
|
+
const buildArg = hasExplicitType ? buildOrOpts : combinatorOrBuild;
|
|
3136
|
+
const build = typeof buildArg === "function" ? buildArg : void 0;
|
|
3137
|
+
const opts = typeof buildArg === "function" ? maybeOpts : buildArg ?? maybeOpts;
|
|
3138
|
+
const project = normalizeProject(opts?.project);
|
|
3139
|
+
if (project !== void 0 && build !== void 0) {
|
|
3140
|
+
throw new Error("node() options cannot combine project with a build callback");
|
|
3141
|
+
}
|
|
3124
3142
|
const baseDef = { tag: "node", parser: combinator, ...type === void 0 ? {} : { type }, ...build === void 0 ? {} : { build } };
|
|
3125
3143
|
const meta = {
|
|
3126
3144
|
firstSet: combinator._meta.firstSet,
|
|
@@ -3134,11 +3152,14 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
|
|
|
3134
3152
|
if (unwrap && collapse) {
|
|
3135
3153
|
throw new Error("node() options cannot set both unwrap and collapse");
|
|
3136
3154
|
}
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3155
|
+
if (project !== void 0 && (unwrap || collapse)) {
|
|
3156
|
+
throw new Error("node() options cannot combine project with unwrap or collapse");
|
|
3157
|
+
}
|
|
3158
|
+
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;
|
|
3159
|
+
const capturesTrivia = captureTrivia || trailingTrivia || (build ? buildReadsTrivia(def) : project === void 0);
|
|
3160
|
+
const clonesState = build ? buildReadsState(def) : project === void 0;
|
|
3140
3161
|
const hasOwnFields = parserHasOwnFields(combinator);
|
|
3141
|
-
const capturesFields = hasOwnFields && (build ? buildReadsFields(def) :
|
|
3162
|
+
const capturesFields = hasOwnFields && (build ? buildReadsFields(def) : project === void 0);
|
|
3142
3163
|
const guardable = combinator._meta.firstSet.kind !== "any" && !matchesEmpty(combinator);
|
|
3143
3164
|
let failExpected;
|
|
3144
3165
|
return {
|
|
@@ -3153,14 +3174,15 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
|
|
|
3153
3174
|
}
|
|
3154
3175
|
return { ok: false, expected: failExpected, span: { start: pos, end: pos } };
|
|
3155
3176
|
}
|
|
3156
|
-
const
|
|
3177
|
+
const hasDirectValue = build !== void 0 || project !== void 0;
|
|
3178
|
+
const hostCst = hasDirectValue && cstOutputHost(ctx.build);
|
|
3157
3179
|
const effTrivia = capturesTrivia || hostCst;
|
|
3158
3180
|
const effFields = capturesFields || hostCst && hasOwnFields;
|
|
3159
3181
|
const saved = beginCstNodeCapture(ctx);
|
|
3160
3182
|
const savedFields = ctx._fields;
|
|
3161
3183
|
ctx._fields = effFields ? [] : void 0;
|
|
3162
3184
|
const savedMask = ctx._triviaCaptureMask;
|
|
3163
|
-
if (build === void 0 && ctx.build?._parsemanTriviaKinds !== void 0 && def.type !== void 0) {
|
|
3185
|
+
if (build === void 0 && project === void 0 && ctx.build?._parsemanTriviaKinds !== void 0 && def.type !== void 0) {
|
|
3164
3186
|
ctx._triviaCaptureMask = ctx.build._parsemanTriviaKinds(def.type);
|
|
3165
3187
|
}
|
|
3166
3188
|
if (!effTrivia) ctx.captureTrivia = false;
|
|
@@ -3178,7 +3200,7 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
|
|
|
3178
3200
|
const nodeType = def.type ?? missingInferredType();
|
|
3179
3201
|
const cstOutput = cstOutputHost(ctx.build);
|
|
3180
3202
|
const hostState = clonesState ? st : ctx.state !== void 0 ? Object.assign({}, ctx.state) : void 0;
|
|
3181
|
-
const built = unwrap && children2.length === 1 ? unwrapChild(children2[0]) : collapse && children2.length === 1 ? children2[0] : !build && ctx.build?._parsemanCstCollapse && children2.length === 1 && rawChildren.length === 1 && ctx.build._parsemanCstCollapse(nodeType, children2[0], children2, rawChildren) ? children2[0] : build ? cstOutput && ctx.build ? ctx.build(nodeType, children2, fields, r.span, rawChildren, triviaLog, hostState) : build(children2, fields, r.span, rawChildren, triviaLog, st) : ctx.build ? ctx.build(nodeType, children2, fields, r.span, rawChildren, triviaLog, st) : { _tag: "node", type: nodeType, span: { start: r.span.start, end: r.span.end }, state: st ?? null, children: children2 };
|
|
3203
|
+
const built = unwrap && children2.length === 1 ? unwrapChild(children2[0]) : collapse && children2.length === 1 ? children2[0] : !build && project === void 0 && ctx.build?._parsemanCstCollapse && children2.length === 1 && rawChildren.length === 1 && ctx.build._parsemanCstCollapse(nodeType, children2[0], children2, rawChildren) ? children2[0] : project !== void 0 ? cstOutput && ctx.build ? ctx.build(nodeType, children2, fields, r.span, rawChildren, triviaLog, hostState) : projectChild(children2, project, nodeType) : build ? cstOutput && ctx.build ? ctx.build(nodeType, children2, fields, r.span, rawChildren, triviaLog, hostState) : build(children2, fields, r.span, rawChildren, triviaLog, st) : ctx.build ? ctx.build(nodeType, children2, fields, r.span, rawChildren, triviaLog, st) : { _tag: "node", type: nodeType, span: { start: r.span.start, end: r.span.end }, state: st ?? null, children: children2 };
|
|
3182
3204
|
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 };
|
|
3183
3205
|
if (saved.buf !== void 0 || saved.ch !== void 0) {
|
|
3184
3206
|
pushCstChild(ctx, built, rawEntry);
|
|
@@ -3456,7 +3478,7 @@ function leaf(root, fn) {
|
|
|
3456
3478
|
}
|
|
3457
3479
|
|
|
3458
3480
|
// src/version.ts
|
|
3459
|
-
var PARSEMAN_VERSION = "0.
|
|
3481
|
+
var PARSEMAN_VERSION = "0.40.0";
|
|
3460
3482
|
|
|
3461
3483
|
// src/cst/host-mode.ts
|
|
3462
3484
|
var FUSED_HOST_MODE = /* @__PURE__ */ Symbol.for("parseman.fusedHostMode");
|
|
@@ -8619,14 +8641,20 @@ function emitLeaf(def, ctx, pos) {
|
|
|
8619
8641
|
endVar: inner.endVar
|
|
8620
8642
|
};
|
|
8621
8643
|
}
|
|
8644
|
+
function emitNodeProjectExpr(type, project, chV) {
|
|
8645
|
+
const child = `${chV}[${project}]`;
|
|
8646
|
+
const missing = `(() => { throw new Error(${JSON.stringify(`node(${JSON.stringify(type)}) project child ${project} was not captured`)}) })()`;
|
|
8647
|
+
const value = `(${child} !== null && typeof ${child} === 'object' && ${child}._tag === 'leaf' ? ${child}.value : ${child})`;
|
|
8648
|
+
return `(${project} in ${chV} ? ${value} : ${missing})`;
|
|
8649
|
+
}
|
|
8622
8650
|
function emitNode(def, ctx, pos) {
|
|
8623
8651
|
if (def.type === void 0) {
|
|
8624
8652
|
throw new Error('node(): inferred node type requires a rules() key; pass node("Type", parser) outside rules()');
|
|
8625
8653
|
}
|
|
8626
|
-
const structural = def.build === void 0;
|
|
8627
|
-
const mkType = structural ? null : analyzeMkInlineBuild(def);
|
|
8654
|
+
const structural = def.build === void 0 && def.project === void 0;
|
|
8655
|
+
const mkType = structural || def.project !== void 0 ? null : analyzeMkInlineBuild(def);
|
|
8628
8656
|
let buildIdx = null;
|
|
8629
|
-
if (!mkType && !structural) {
|
|
8657
|
+
if (!mkType && !structural && def.project === void 0) {
|
|
8630
8658
|
buildIdx = ctx.buildFns.length;
|
|
8631
8659
|
ctx.buildFns.push(def.build);
|
|
8632
8660
|
ctx.buildSrcs.push(def.buildSrc ?? null);
|
|
@@ -8634,12 +8662,13 @@ function emitNode(def, ctx, pos) {
|
|
|
8634
8662
|
const i = ind(ctx);
|
|
8635
8663
|
const cstOut = ctx.hostMode === "cst" && !structural;
|
|
8636
8664
|
if (!structural && !cstOut) ctx.hostBranchElided = true;
|
|
8637
|
-
const
|
|
8638
|
-
const
|
|
8639
|
-
const
|
|
8640
|
-
const
|
|
8665
|
+
const hasProject = def.project !== void 0;
|
|
8666
|
+
const capturesTrivia = cstOut || mkType !== null || def.captureTrivia === true || def.trailingTrivia === true || !structural && !hasProject && buildReadsTrivia(def);
|
|
8667
|
+
const clonesState = !structural && (cstOut || !hasProject && buildReadsState(def));
|
|
8668
|
+
const capturesChildren = !structural && (cstOut || mkType !== null || def.unwrap || def.collapse || def.project !== void 0 || buildReadsChildren(def));
|
|
8669
|
+
const capturesRaw = !structural && (cstOut || mkType !== null || def.project === void 0 && buildReadsRaw(def));
|
|
8641
8670
|
const hasFields = parserHasOwnFields(def.parser);
|
|
8642
|
-
const capturesFields = hasFields && !structural && (cstOut || buildReadsFields(def));
|
|
8671
|
+
const capturesFields = hasFields && !structural && (cstOut || !hasProject && buildReadsFields(def));
|
|
8643
8672
|
const innerEnablesTriviaCapture = parserEnablesTriviaCapture(def.parser);
|
|
8644
8673
|
const chV = v(ctx, "_ch");
|
|
8645
8674
|
const rawV = v(ctx, "_raw");
|
|
@@ -8737,7 +8766,7 @@ ${i}const ${chV} = ${chAlloc}, ${rawV} = ${profileRecognizer} ? undefined : [],
|
|
|
8737
8766
|
);
|
|
8738
8767
|
}
|
|
8739
8768
|
const ndV = v(ctx, "_nd");
|
|
8740
|
-
const buildExpr = structural ? `{ _tag: 'node', type: ${JSON.stringify(def.type)}, span: { start: ${pos}, end: ${endVar} }, state: ${stV} ?? null, children: ${chV} }` : mkType ? emitInlineMkNodeExpr(mkType, chV, rawV, pos, endVar, tlV) : `${buildRef(ctx)}[${buildIdx}](${chV}, ${fObj}, { start: ${pos}, end: ${endVar} }, ${rawV}, ${tlV}, ${stV})`;
|
|
8769
|
+
const buildExpr = structural ? `{ _tag: 'node', type: ${JSON.stringify(def.type)}, span: { start: ${pos}, end: ${endVar} }, state: ${stV} ?? null, children: ${chV} }` : mkType ? emitInlineMkNodeExpr(mkType, chV, rawV, pos, endVar, tlV) : def.project !== void 0 ? emitNodeProjectExpr(def.type, def.project, chV) : `${buildRef(ctx)}[${buildIdx}](${chV}, ${fObj}, { start: ${pos}, end: ${endVar} }, ${rawV}, ${tlV}, ${stV})`;
|
|
8741
8770
|
const hostBuildExpr = `_ctx._pmProfile?.phase === 'host' && _ctx._pmProfile.hostCalls++, _ctx.build(${JSON.stringify(def.type)}, ${chV}, ${fObj}, { start: ${pos}, end: ${endVar} }, ${rawV}, ${tlV}, ${stV})`;
|
|
8742
8771
|
const ndExpr = structural ? `_ctx.build !== undefined ? (${hostBuildExpr}) : (${buildExpr})` : cstOut ? hostBuildExpr : buildExpr;
|
|
8743
8772
|
const hostCollapseExpr = structural ? `_ctx.build !== undefined && _ctx.build._parsemanCstCollapse !== undefined && ${chV}.length === 1 && ${rawV}.length === 1 && _ctx.build._parsemanCstCollapse(${JSON.stringify(def.type)}, ${chV}[0], ${chV}, ${rawV}) ? ${chV}[0] : (${ndExpr})` : ndExpr;
|
|
@@ -10022,6 +10051,10 @@ function repeatOpts(min, max, trailing) {
|
|
|
10022
10051
|
if (trailing !== void 0) parts.push(`trailing: ${JSON.stringify(trailing)}`);
|
|
10023
10052
|
return parts.length === 0 ? "" : `, { ${parts.join(", ")} }`;
|
|
10024
10053
|
}
|
|
10054
|
+
function projectOpt(project) {
|
|
10055
|
+
if (project === void 0) return void 0;
|
|
10056
|
+
return `project: ${project}`;
|
|
10057
|
+
}
|
|
10025
10058
|
function matcherExpr(entry) {
|
|
10026
10059
|
switch (entry.kind) {
|
|
10027
10060
|
case "startsWith":
|
|
@@ -10415,9 +10448,11 @@ ${outerDecls.map((d) => " " + d).join("\n")}
|
|
|
10415
10448
|
}
|
|
10416
10449
|
case "node": {
|
|
10417
10450
|
if (def.build !== void 0 && def.buildSrc === void 0) throw new Unserializable("node build without buildSrc");
|
|
10451
|
+
const projectEntry = projectOpt(def.project);
|
|
10418
10452
|
const optEntries = [
|
|
10419
10453
|
...def.unwrap ? ["unwrap: true"] : [],
|
|
10420
10454
|
...def.collapse ? ["collapse: true"] : [],
|
|
10455
|
+
...projectEntry === void 0 ? [] : [projectEntry],
|
|
10421
10456
|
...def.captureTrivia ? ["captureTrivia: true"] : [],
|
|
10422
10457
|
...def.trailingTrivia ? ["trailingTrivia: true"] : []
|
|
10423
10458
|
];
|
|
@@ -11697,7 +11732,7 @@ function coverageEntry(entry, collector, maps, trace) {
|
|
|
11697
11732
|
case "peek":
|
|
11698
11733
|
return peek(build(def.parser));
|
|
11699
11734
|
case "node": {
|
|
11700
|
-
const opts = { ...def.unwrap ? { unwrap: true } : {}, ...def.collapse ? { collapse: true } : {}, ...def.captureTrivia ? { captureTrivia: true } : {}, ...def.trailingTrivia ? { trailingTrivia: true } : {} };
|
|
11735
|
+
const opts = { ...def.unwrap ? { unwrap: true } : {}, ...def.collapse ? { collapse: true } : {}, ...def.project !== void 0 ? { project: def.project } : {}, ...def.captureTrivia ? { captureTrivia: true } : {}, ...def.trailingTrivia ? { trailingTrivia: true } : {} };
|
|
11701
11736
|
return def.type === void 0 ? node(build(def.parser), def.build, opts) : node(def.type, build(def.parser), def.build, opts);
|
|
11702
11737
|
}
|
|
11703
11738
|
case "guard":
|