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/dist/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export { ref } from './combinators/ref.ts';
|
|
|
16
16
|
export { not } from './combinators/not.ts';
|
|
17
17
|
export { peek } from './combinators/peek.ts';
|
|
18
18
|
export { node } from './combinators/node.ts';
|
|
19
|
-
export type { BuildNode, NodeOptions } from './combinators/node.ts';
|
|
19
|
+
export type { BuildNode, NodeOptions, NodeProjectOptions } from './combinators/node.ts';
|
|
20
20
|
export { transform, skip, trivia, label, field } from './combinators/map.ts';
|
|
21
21
|
export { parse, parser, noTrivia } from './combinators/grammar.ts';
|
|
22
22
|
export type { ParseOptions, ParserOptions, ParsemanParser } from './combinators/grammar.ts';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE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AAyB,CAAA;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEtD,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,WAAW,EACX,WAAW,EACX,UAAU,EACV,gBAAgB,GACjB,MAAM,uBAAuB,CAAA;AAC9B,YAAY,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EACL,UAAU,EACV,UAAU,EACV,cAAc,EACd,aAAa,EACb,SAAS,EACT,aAAa,EACb,aAAa,EACb,eAAe,GAChB,MAAM,yBAAyB,CAAA;AAChC,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -2990,12 +2990,30 @@ function isCstChild(value) {
|
|
|
2990
2990
|
function missingInferredType() {
|
|
2991
2991
|
throw new Error('node(): inferred node type requires a rules() key; pass node("Type", parser) outside rules()');
|
|
2992
2992
|
}
|
|
2993
|
+
function normalizeProject(project) {
|
|
2994
|
+
if (project === void 0) return void 0;
|
|
2995
|
+
if (!Number.isInteger(project) || project < 0) {
|
|
2996
|
+
throw new Error("node() project child must be a non-negative integer");
|
|
2997
|
+
}
|
|
2998
|
+
return project;
|
|
2999
|
+
}
|
|
3000
|
+
function projectChild(children2, project, type) {
|
|
3001
|
+
if (!(project in children2)) {
|
|
3002
|
+
throw new Error(`node(${JSON.stringify(type)}) project child ${project} was not captured`);
|
|
3003
|
+
}
|
|
3004
|
+
return unwrapChild(children2[project]);
|
|
3005
|
+
}
|
|
2993
3006
|
function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
|
|
2994
3007
|
const hasExplicitType = typeof typeOrCombinator === "string";
|
|
2995
3008
|
const type = hasExplicitType ? typeOrCombinator : void 0;
|
|
2996
3009
|
const combinator = hasExplicitType ? combinatorOrBuild : typeOrCombinator;
|
|
2997
|
-
const
|
|
2998
|
-
const
|
|
3010
|
+
const buildArg = hasExplicitType ? buildOrOpts : combinatorOrBuild;
|
|
3011
|
+
const build = typeof buildArg === "function" ? buildArg : void 0;
|
|
3012
|
+
const opts = typeof buildArg === "function" ? maybeOpts : buildArg ?? maybeOpts;
|
|
3013
|
+
const project = normalizeProject(opts?.project);
|
|
3014
|
+
if (project !== void 0 && build !== void 0) {
|
|
3015
|
+
throw new Error("node() options cannot combine project with a build callback");
|
|
3016
|
+
}
|
|
2999
3017
|
const baseDef = { tag: "node", parser: combinator, ...type === void 0 ? {} : { type }, ...build === void 0 ? {} : { build } };
|
|
3000
3018
|
const meta = {
|
|
3001
3019
|
firstSet: combinator._meta.firstSet,
|
|
@@ -3009,11 +3027,14 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
|
|
|
3009
3027
|
if (unwrap && collapse) {
|
|
3010
3028
|
throw new Error("node() options cannot set both unwrap and collapse");
|
|
3011
3029
|
}
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3030
|
+
if (project !== void 0 && (unwrap || collapse)) {
|
|
3031
|
+
throw new Error("node() options cannot combine project with unwrap or collapse");
|
|
3032
|
+
}
|
|
3033
|
+
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;
|
|
3034
|
+
const capturesTrivia = captureTrivia || trailingTrivia || (build ? buildReadsTrivia(def) : project === void 0);
|
|
3035
|
+
const clonesState = build ? buildReadsState(def) : project === void 0;
|
|
3015
3036
|
const hasOwnFields = parserHasOwnFields(combinator);
|
|
3016
|
-
const capturesFields = hasOwnFields && (build ? buildReadsFields(def) :
|
|
3037
|
+
const capturesFields = hasOwnFields && (build ? buildReadsFields(def) : project === void 0);
|
|
3017
3038
|
const guardable = combinator._meta.firstSet.kind !== "any" && !matchesEmpty(combinator);
|
|
3018
3039
|
let failExpected;
|
|
3019
3040
|
return {
|
|
@@ -3028,14 +3049,15 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
|
|
|
3028
3049
|
}
|
|
3029
3050
|
return { ok: false, expected: failExpected, span: { start: pos, end: pos } };
|
|
3030
3051
|
}
|
|
3031
|
-
const
|
|
3052
|
+
const hasDirectValue = build !== void 0 || project !== void 0;
|
|
3053
|
+
const hostCst = hasDirectValue && cstOutputHost(ctx.build);
|
|
3032
3054
|
const effTrivia = capturesTrivia || hostCst;
|
|
3033
3055
|
const effFields = capturesFields || hostCst && hasOwnFields;
|
|
3034
3056
|
const saved = beginCstNodeCapture(ctx);
|
|
3035
3057
|
const savedFields = ctx._fields;
|
|
3036
3058
|
ctx._fields = effFields ? [] : void 0;
|
|
3037
3059
|
const savedMask = ctx._triviaCaptureMask;
|
|
3038
|
-
if (build === void 0 && ctx.build?._parsemanTriviaKinds !== void 0 && def.type !== void 0) {
|
|
3060
|
+
if (build === void 0 && project === void 0 && ctx.build?._parsemanTriviaKinds !== void 0 && def.type !== void 0) {
|
|
3039
3061
|
ctx._triviaCaptureMask = ctx.build._parsemanTriviaKinds(def.type);
|
|
3040
3062
|
}
|
|
3041
3063
|
if (!effTrivia) ctx.captureTrivia = false;
|
|
@@ -3053,7 +3075,7 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
|
|
|
3053
3075
|
const nodeType = def.type ?? missingInferredType();
|
|
3054
3076
|
const cstOutput = cstOutputHost(ctx.build);
|
|
3055
3077
|
const hostState = clonesState ? st : ctx.state !== void 0 ? Object.assign({}, ctx.state) : void 0;
|
|
3056
|
-
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 };
|
|
3078
|
+
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 };
|
|
3057
3079
|
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 };
|
|
3058
3080
|
if (saved.buf !== void 0 || saved.ch !== void 0) {
|
|
3059
3081
|
pushCstChild(ctx, built, rawEntry);
|
|
@@ -3331,7 +3353,7 @@ function leaf(root, fn) {
|
|
|
3331
3353
|
}
|
|
3332
3354
|
|
|
3333
3355
|
// src/version.ts
|
|
3334
|
-
var PARSEMAN_VERSION = "0.
|
|
3356
|
+
var PARSEMAN_VERSION = "0.40.0";
|
|
3335
3357
|
|
|
3336
3358
|
// src/cst/host-mode.ts
|
|
3337
3359
|
var FUSED_HOST_MODE = /* @__PURE__ */ Symbol.for("parseman.fusedHostMode");
|
|
@@ -8494,14 +8516,20 @@ function emitLeaf(def, ctx, pos) {
|
|
|
8494
8516
|
endVar: inner.endVar
|
|
8495
8517
|
};
|
|
8496
8518
|
}
|
|
8519
|
+
function emitNodeProjectExpr(type, project, chV) {
|
|
8520
|
+
const child = `${chV}[${project}]`;
|
|
8521
|
+
const missing = `(() => { throw new Error(${JSON.stringify(`node(${JSON.stringify(type)}) project child ${project} was not captured`)}) })()`;
|
|
8522
|
+
const value = `(${child} !== null && typeof ${child} === 'object' && ${child}._tag === 'leaf' ? ${child}.value : ${child})`;
|
|
8523
|
+
return `(${project} in ${chV} ? ${value} : ${missing})`;
|
|
8524
|
+
}
|
|
8497
8525
|
function emitNode(def, ctx, pos) {
|
|
8498
8526
|
if (def.type === void 0) {
|
|
8499
8527
|
throw new Error('node(): inferred node type requires a rules() key; pass node("Type", parser) outside rules()');
|
|
8500
8528
|
}
|
|
8501
|
-
const structural = def.build === void 0;
|
|
8502
|
-
const mkType = structural ? null : analyzeMkInlineBuild(def);
|
|
8529
|
+
const structural = def.build === void 0 && def.project === void 0;
|
|
8530
|
+
const mkType = structural || def.project !== void 0 ? null : analyzeMkInlineBuild(def);
|
|
8503
8531
|
let buildIdx = null;
|
|
8504
|
-
if (!mkType && !structural) {
|
|
8532
|
+
if (!mkType && !structural && def.project === void 0) {
|
|
8505
8533
|
buildIdx = ctx.buildFns.length;
|
|
8506
8534
|
ctx.buildFns.push(def.build);
|
|
8507
8535
|
ctx.buildSrcs.push(def.buildSrc ?? null);
|
|
@@ -8509,12 +8537,13 @@ function emitNode(def, ctx, pos) {
|
|
|
8509
8537
|
const i = ind(ctx);
|
|
8510
8538
|
const cstOut = ctx.hostMode === "cst" && !structural;
|
|
8511
8539
|
if (!structural && !cstOut) ctx.hostBranchElided = true;
|
|
8512
|
-
const
|
|
8513
|
-
const
|
|
8514
|
-
const
|
|
8515
|
-
const
|
|
8540
|
+
const hasProject = def.project !== void 0;
|
|
8541
|
+
const capturesTrivia = cstOut || mkType !== null || def.captureTrivia === true || def.trailingTrivia === true || !structural && !hasProject && buildReadsTrivia(def);
|
|
8542
|
+
const clonesState = !structural && (cstOut || !hasProject && buildReadsState(def));
|
|
8543
|
+
const capturesChildren = !structural && (cstOut || mkType !== null || def.unwrap || def.collapse || def.project !== void 0 || buildReadsChildren(def));
|
|
8544
|
+
const capturesRaw = !structural && (cstOut || mkType !== null || def.project === void 0 && buildReadsRaw(def));
|
|
8516
8545
|
const hasFields = parserHasOwnFields(def.parser);
|
|
8517
|
-
const capturesFields = hasFields && !structural && (cstOut || buildReadsFields(def));
|
|
8546
|
+
const capturesFields = hasFields && !structural && (cstOut || !hasProject && buildReadsFields(def));
|
|
8518
8547
|
const innerEnablesTriviaCapture = parserEnablesTriviaCapture(def.parser);
|
|
8519
8548
|
const chV = v(ctx, "_ch");
|
|
8520
8549
|
const rawV = v(ctx, "_raw");
|
|
@@ -8612,7 +8641,7 @@ ${i}const ${chV} = ${chAlloc}, ${rawV} = ${profileRecognizer} ? undefined : [],
|
|
|
8612
8641
|
);
|
|
8613
8642
|
}
|
|
8614
8643
|
const ndV = v(ctx, "_nd");
|
|
8615
|
-
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})`;
|
|
8644
|
+
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})`;
|
|
8616
8645
|
const hostBuildExpr = `_ctx._pmProfile?.phase === 'host' && _ctx._pmProfile.hostCalls++, _ctx.build(${JSON.stringify(def.type)}, ${chV}, ${fObj}, { start: ${pos}, end: ${endVar} }, ${rawV}, ${tlV}, ${stV})`;
|
|
8617
8646
|
const ndExpr = structural ? `_ctx.build !== undefined ? (${hostBuildExpr}) : (${buildExpr})` : cstOut ? hostBuildExpr : buildExpr;
|
|
8618
8647
|
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;
|
|
@@ -9897,6 +9926,10 @@ function repeatOpts(min, max, trailing) {
|
|
|
9897
9926
|
if (trailing !== void 0) parts.push(`trailing: ${JSON.stringify(trailing)}`);
|
|
9898
9927
|
return parts.length === 0 ? "" : `, { ${parts.join(", ")} }`;
|
|
9899
9928
|
}
|
|
9929
|
+
function projectOpt(project) {
|
|
9930
|
+
if (project === void 0) return void 0;
|
|
9931
|
+
return `project: ${project}`;
|
|
9932
|
+
}
|
|
9900
9933
|
function matcherExpr(entry) {
|
|
9901
9934
|
switch (entry.kind) {
|
|
9902
9935
|
case "startsWith":
|
|
@@ -10290,9 +10323,11 @@ ${outerDecls.map((d) => " " + d).join("\n")}
|
|
|
10290
10323
|
}
|
|
10291
10324
|
case "node": {
|
|
10292
10325
|
if (def.build !== void 0 && def.buildSrc === void 0) throw new Unserializable("node build without buildSrc");
|
|
10326
|
+
const projectEntry = projectOpt(def.project);
|
|
10293
10327
|
const optEntries = [
|
|
10294
10328
|
...def.unwrap ? ["unwrap: true"] : [],
|
|
10295
10329
|
...def.collapse ? ["collapse: true"] : [],
|
|
10330
|
+
...projectEntry === void 0 ? [] : [projectEntry],
|
|
10296
10331
|
...def.captureTrivia ? ["captureTrivia: true"] : [],
|
|
10297
10332
|
...def.trailingTrivia ? ["trailingTrivia: true"] : []
|
|
10298
10333
|
];
|
|
@@ -11572,7 +11607,7 @@ function coverageEntry(entry, collector, maps, trace) {
|
|
|
11572
11607
|
case "peek":
|
|
11573
11608
|
return peek(build(def.parser));
|
|
11574
11609
|
case "node": {
|
|
11575
|
-
const opts = { ...def.unwrap ? { unwrap: true } : {}, ...def.collapse ? { collapse: true } : {}, ...def.captureTrivia ? { captureTrivia: true } : {}, ...def.trailingTrivia ? { trailingTrivia: true } : {} };
|
|
11610
|
+
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 } : {} };
|
|
11576
11611
|
return def.type === void 0 ? node(build(def.parser), def.build, opts) : node(def.type, build(def.parser), def.build, opts);
|
|
11577
11612
|
}
|
|
11578
11613
|
case "guard":
|