parseman 0.26.3 → 0.27.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/compiler/codegen.d.ts.map +1 -1
- package/dist/compiler/fields.d.ts +13 -0
- package/dist/compiler/fields.d.ts.map +1 -1
- package/dist/functional/run.d.ts +29 -0
- package/dist/functional/run.d.ts.map +1 -1
- package/dist/index.cjs +115 -14
- 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 +115 -14
- package/dist/index.js.map +2 -2
- package/dist/language-service/index.cjs +36 -3
- package/dist/language-service/index.cjs.map +2 -2
- package/dist/language-service/index.js +36 -3
- package/dist/language-service/index.js.map +2 -2
- package/dist/plugin/index.cjs +79 -11
- package/dist/plugin/index.cjs.map +2 -2
- package/dist/plugin/index.js +79 -11
- package/dist/plugin/index.js.map +2 -2
- package/dist/types.d.ts +14 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../../src/compiler/codegen.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,UAAU,EAAa,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAA4B,MAAM,aAAa,CAAA;AA0BnI;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,uTAC0R,CAAA;AActT,8EAA8E;AAC9E,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C;AAED,+EAA+E;AAC/E,wBAAgB,kBAAkB,IAAI,MAAM,EAAE,CAI7C;AAudD,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,GAAG,MAAM,CAQlE;AAcD,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,OAAO,GAAG,IAAI,CAA0B;
|
|
1
|
+
{"version":3,"file":"codegen.d.ts","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C,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,CAAA;CACzD,CAAA;AAED,wBAAgB,eAAe,CAC7B,UAAU,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EACjE,EAAE,EAAE,MAAM,EACV,IAAI,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,GAC1D,cAAc,GAAG,IAAI,CAsLvB"}
|
|
@@ -4,6 +4,19 @@ type NodeDef = Extract<ParserDef, {
|
|
|
4
4
|
}>;
|
|
5
5
|
export declare function buildReadsFields(def: NodeDef): boolean;
|
|
6
6
|
export declare function parserHasOwnFields(p: Combinator<unknown>, seen?: Set<Combinator<unknown>>): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Does the node's OWN parse frame ever have a trivia run logged into it?
|
|
9
|
+
* Trivia is logged only by the trivia-skip fn, which runs at `sequence`/`many`/
|
|
10
|
+
* repeat boundaries. A bare terminal (regex/literal/keywords/…) has NO trivia
|
|
11
|
+
* site, so its `_cstTriviaLog` stays empty and its `captureTrivia`/`_cstTriviaLog`/
|
|
12
|
+
* `_triviaCaptureMask` save+install+restore is dead work — the per-node scope
|
|
13
|
+
* trivia frame can be elided for it (see emitNode `needsTriviaFrame`).
|
|
14
|
+
*
|
|
15
|
+
* Stops at a nested `node()` (it manages its OWN trivia frame; trivia inside it
|
|
16
|
+
* never logs to THIS node's frame). CONSERVATIVE: any unknown / trivia-bearing
|
|
17
|
+
* shape returns `true` (keep the frame) — we only elide when provably safe.
|
|
18
|
+
*/
|
|
19
|
+
export declare function parserHasTriviaSite(p: Combinator<unknown>, seen?: Set<Combinator<unknown>>): boolean;
|
|
7
20
|
export declare function buildFieldMap(captures: ReadonlyArray<{
|
|
8
21
|
name: string;
|
|
9
22
|
value: unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../src/compiler/fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAGlE,KAAK,OAAO,GAAG,OAAO,CAAC,SAAS,EAAE;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAElD,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAMtD;AAED,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI,GAAE,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAa,GAAG,OAAO,CA+B9G;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,aAAa,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAAC,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAW/J"}
|
|
1
|
+
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../src/compiler/fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAGlE,KAAK,OAAO,GAAG,OAAO,CAAC,SAAS,EAAE;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAElD,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAMtD;AAED,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI,GAAE,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAa,GAAG,OAAO,CA+B9G;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI,GAAE,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAa,GAAG,OAAO,CAwC/G;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,aAAa,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAAC,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAW/J"}
|
package/dist/functional/run.d.ts
CHANGED
|
@@ -51,6 +51,33 @@ export type RunOptions = {
|
|
|
51
51
|
* fails, so none of the machinery runs.
|
|
52
52
|
*/
|
|
53
53
|
tolerant?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Run three compiled-parser-only profiling passes: recognizer (no global
|
|
56
|
+
* sinks), structural capture without the host, then the normal host path. This
|
|
57
|
+
* is a measurement boundary, not a parser mode; ordinary `run()` output is
|
|
58
|
+
* unchanged when omitted. The input is parsed THREE times — each pass gets its
|
|
59
|
+
* own shallow copy of `options.state`, so keep per-parse state shallow (only
|
|
60
|
+
* the top level is isolated between passes).
|
|
61
|
+
*/
|
|
62
|
+
profile?: boolean;
|
|
63
|
+
};
|
|
64
|
+
export type RunProfilePass = {
|
|
65
|
+
ms: number;
|
|
66
|
+
nodes: number;
|
|
67
|
+
childSlots: number;
|
|
68
|
+
rawSlots: number;
|
|
69
|
+
triviaSlots: number;
|
|
70
|
+
fieldSlots: number;
|
|
71
|
+
hostCalls: number;
|
|
72
|
+
};
|
|
73
|
+
export type RunProfile = {
|
|
74
|
+
/** Existing `voidOf(transform(..., () => undefined))` semantics, generalized
|
|
75
|
+
* to compiled structural nodes: no `ch`/`raw`/`tl` capture or raw entries. */
|
|
76
|
+
recognizer: RunProfilePass;
|
|
77
|
+
/** Captures children/raw/trivia/fields but suppresses node construction. */
|
|
78
|
+
structuralCapture: RunProfilePass;
|
|
79
|
+
/** The ordinary parser path, including its injected build host. */
|
|
80
|
+
hostConstruction: RunProfilePass;
|
|
54
81
|
};
|
|
55
82
|
export type RunResult = {
|
|
56
83
|
ok: boolean;
|
|
@@ -78,6 +105,8 @@ export type RunResult = {
|
|
|
78
105
|
* there's junk here". Only meaningful on success — a failed parse reports its own
|
|
79
106
|
* `span`/`expected`. */
|
|
80
107
|
unconsumedFrom: number | null;
|
|
108
|
+
/** Present only when `RunOptions.profile` is true. */
|
|
109
|
+
profile?: RunProfile;
|
|
81
110
|
};
|
|
82
111
|
export declare function run(entry: Runnable, input: string, options?: RunOptions): RunResult;
|
|
83
112
|
//# sourceMappingURL=run.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/functional/run.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAGpF;;;;;;;;;;;;GAYG;AAEH,+EAA+E;AAC/E,MAAM,MAAM,QAAQ,GAChB,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,KAAK,WAAW,CAAC,OAAO,CAAC,CAAC,GACzE,UAAU,CAAC,OAAO,CAAC,CAAA;AAEvB,MAAM,MAAM,UAAU,GAAG;IACvB;qFACiF;IACjF,KAAK,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,CAAA;IAC7B,uDAAuD;IACvD,KAAK,CAAC,EAAE,OAAO,CAAA;IACf;;;;;;;;;OASG;IACH,MAAM,CAAC,EAAE,QAAQ,CAAA;IACjB;;;;;;;OAOG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B;;;;;;;;;OASG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"run.d.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O,CAAA;IACX,0DAA0D;IAC1D,KAAK,EAAE,OAAO,CAAA;IACd,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;IACpC,6EAA6E;IAC7E,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,gGAAgG;IAChG,MAAM,EAAE,UAAU,EAAE,CAAA;IACpB;;;;;;OAMG;IACH,SAAS,EAAE,MAAM,EAAE,CAAA;IACnB;;;;4BAIwB;IACxB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7B,sDAAsD;IACtD,OAAO,CAAC,EAAE,UAAU,CAAA;CACrB,CAAA;AAoFD,wBAAgB,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,GAAG,SAAS,CAsBvF"}
|
package/dist/index.cjs
CHANGED
|
@@ -2305,6 +2305,55 @@ function parserHasOwnFields(p, seen = /* @__PURE__ */ new Set()) {
|
|
|
2305
2305
|
return false;
|
|
2306
2306
|
}
|
|
2307
2307
|
}
|
|
2308
|
+
function parserHasTriviaSite(p, seen = /* @__PURE__ */ new Set()) {
|
|
2309
|
+
if (seen.has(p)) return true;
|
|
2310
|
+
seen.add(p);
|
|
2311
|
+
const d = p._def;
|
|
2312
|
+
switch (d.tag) {
|
|
2313
|
+
// Trivia is skipped between/around elements or iterations → a site.
|
|
2314
|
+
case "sequence":
|
|
2315
|
+
case "many":
|
|
2316
|
+
case "oneOrMore":
|
|
2317
|
+
case "sepBy":
|
|
2318
|
+
case "scanTo":
|
|
2319
|
+
case "recover":
|
|
2320
|
+
case "skip":
|
|
2321
|
+
return true;
|
|
2322
|
+
// Nested node manages its own trivia frame; none logs here.
|
|
2323
|
+
case "node":
|
|
2324
|
+
return false;
|
|
2325
|
+
// Pure terminals + trivia-suppressing token: no site.
|
|
2326
|
+
case "regex":
|
|
2327
|
+
case "literal":
|
|
2328
|
+
case "keywords":
|
|
2329
|
+
case "guard":
|
|
2330
|
+
case "token":
|
|
2331
|
+
return false;
|
|
2332
|
+
// Transparent single-child wrappers: recurse.
|
|
2333
|
+
case "optional":
|
|
2334
|
+
case "transform":
|
|
2335
|
+
case "trivia":
|
|
2336
|
+
case "label":
|
|
2337
|
+
case "expect":
|
|
2338
|
+
case "withCtx":
|
|
2339
|
+
case "not":
|
|
2340
|
+
case "field":
|
|
2341
|
+
return parserHasTriviaSite(d.parser, seen);
|
|
2342
|
+
case "choice":
|
|
2343
|
+
return d.parsers.some((x) => parserHasTriviaSite(x, seen));
|
|
2344
|
+
case "grammar":
|
|
2345
|
+
return parserHasTriviaSite(d.parser, seen);
|
|
2346
|
+
case "lazy": {
|
|
2347
|
+
try {
|
|
2348
|
+
return parserHasTriviaSite(d.thunk(), seen);
|
|
2349
|
+
} catch {
|
|
2350
|
+
return true;
|
|
2351
|
+
}
|
|
2352
|
+
}
|
|
2353
|
+
default:
|
|
2354
|
+
return true;
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2308
2357
|
function buildFieldMap(captures) {
|
|
2309
2358
|
if (!captures?.length) return void 0;
|
|
2310
2359
|
const out = {};
|
|
@@ -5296,32 +5345,49 @@ function emitNode(def, ctx, pos) {
|
|
|
5296
5345
|
const smk = structural ? v(ctx, "_smk") : null;
|
|
5297
5346
|
if (structural) ctx.needsHostReads = true;
|
|
5298
5347
|
const hostTriviaGate = `_ctx.build !== undefined && (_ctx.build._parsemanCaptureTrivia !== undefined ? _ctx.build._parsemanCaptureTrivia(${JSON.stringify(def.type)}) : (_ctx._pmCapTL ??= _hostReads(_ctx.build, 5)))`;
|
|
5299
|
-
const
|
|
5300
|
-
|
|
5348
|
+
const pmV = v(ctx, "_pm"), recV = v(ctx, "_rec"), capV = v(ctx, "_cap");
|
|
5349
|
+
const profHoist = `${i}const ${pmV} = _ctx._pmProfile, ${recV} = ${pmV}?.phase === 'recognizer', ${capV} = ${pmV}?.phase === 'capture'`;
|
|
5350
|
+
const profileRecognizer = recV;
|
|
5351
|
+
const profileCapture = capV;
|
|
5352
|
+
const allocStmt = structural ? `${i}const ${capTLv} = !(${profileRecognizer}) && (${profileCapture} || ${hostTriviaGate}), ${capSTv} = !(${profileRecognizer} || ${profileCapture}) && (_ctx._pmCapST ??= (_ctx.build === undefined || _hostReads(_ctx.build, 6)))${capFv ? `, ${capFv} = !(${profileRecognizer}) && (${profileCapture} || (_ctx.build !== undefined && _hostReads(_ctx.build, 2)))` : ""}
|
|
5353
|
+
${i}const ${chV} = ${profileRecognizer} ? undefined : [], ${rawV} = ${profileRecognizer} ? undefined : [], ${tlV} = ${capTLv} ? [] : _EMPTY_TL` : capturesTrivia ? `${i}const ${chV} = ${profileRecognizer} ? undefined : [], ${rawV} = ${profileRecognizer} ? undefined : [], ${tlV} = ${profileRecognizer} ? undefined : []` : `${i}const ${chV} = ${profileRecognizer} ? undefined : [], ${rawV} = ${profileRecognizer} ? undefined : []`;
|
|
5301
5354
|
const innerTl = structural ? `${capTLv} ? ${tlV} : undefined` : capturesTrivia ? tlV : "undefined";
|
|
5302
|
-
const fieldsOn = structural ? capFv ?? "false" : capturesFields ? "true" : "false"
|
|
5355
|
+
const fieldsOn = structural ? capFv ?? "false" : `${profileRecognizer} ? false : ${capturesFields ? "true" : "false"}`;
|
|
5303
5356
|
const sf = hasFields ? v(ctx, "_sf") : null;
|
|
5304
5357
|
const fArr = hasFields ? v(ctx, "_fa") : null;
|
|
5305
5358
|
const fObj = hasFields ? v(ctx, "_fields") : "undefined";
|
|
5359
|
+
const needsTriviaFrame = parserHasTriviaSite(def.parser);
|
|
5360
|
+
const saveTrivia = needsTriviaFrame ? `, ${st} = _ctx.captureTrivia, ${stl} = _ctx._cstTriviaLog${smk ? `, ${smk} = _ctx._triviaCaptureMask` : ""}` : "";
|
|
5361
|
+
const installTrivia = needsTriviaFrame ? `; _ctx.captureTrivia = true; _ctx._cstTriviaLog = ${innerTl}${smk ? `; _ctx._triviaCaptureMask = ${capTLv} && _ctx.build._parsemanTriviaKinds !== undefined ? _ctx.build._parsemanTriviaKinds(${JSON.stringify(def.type)}) : ${smk}` : ""}` : "";
|
|
5362
|
+
const restoreTrivia = needsTriviaFrame ? `; _ctx.captureTrivia = ${st}; _ctx._cstTriviaLog = ${stl}${smk ? `; _ctx._triviaCaptureMask = ${smk}` : ""}` : "";
|
|
5306
5363
|
const stmts = [
|
|
5364
|
+
profHoist,
|
|
5307
5365
|
allocStmt,
|
|
5308
|
-
`${i}const ${sc} = _ctx._cstChildren, ${sl} = _ctx._cstLeaves, ${sr} = _ctx._cstRawChildren
|
|
5309
|
-
`${i}_ctx._cstChildren = ${chV}; _ctx._cstLeaves = ${chV}; _ctx._cstRawChildren = ${rawV}
|
|
5366
|
+
`${i}const ${sc} = _ctx._cstChildren, ${sl} = _ctx._cstLeaves, ${sr} = _ctx._cstRawChildren${saveTrivia}${sf ? `, ${sf} = _ctx._fields` : ""}`,
|
|
5367
|
+
`${i}_ctx._cstChildren = ${chV}; _ctx._cstLeaves = ${chV}; _ctx._cstRawChildren = ${rawV}${installTrivia}${sf ? `; _ctx._fields = ${fieldsOn} ? [] : undefined` : ""}`
|
|
5310
5368
|
];
|
|
5311
5369
|
const { stmts: innerStmts, okVar, endVar } = emitFallible(def.parser, ctx, pos);
|
|
5312
5370
|
stmts.push(...innerStmts);
|
|
5313
5371
|
if (sf && fArr) {
|
|
5314
5372
|
stmts.push(`${i}const ${fArr} = _ctx._fields`);
|
|
5315
5373
|
}
|
|
5316
|
-
stmts.push(`${i}_ctx._cstChildren = ${sc}; _ctx._cstLeaves = ${sl}; _ctx._cstRawChildren = ${sr}
|
|
5374
|
+
stmts.push(`${i}_ctx._cstChildren = ${sc}; _ctx._cstLeaves = ${sl}; _ctx._cstRawChildren = ${sr}${restoreTrivia}${sf ? `; _ctx._fields = ${sf}` : ""}`);
|
|
5317
5375
|
stmts.push(...emitIfFail(ctx, `!${okVar}`, propagateFailBody(ctx)));
|
|
5376
|
+
stmts.push(
|
|
5377
|
+
`${i}if (_ctx._pmProfile) {`,
|
|
5378
|
+
`${i} _ctx._pmProfile.nodes++`,
|
|
5379
|
+
`${i} if (${profileCapture}) {`,
|
|
5380
|
+
`${i} _ctx._pmProfile.childSlots += ${chV}.length; _ctx._pmProfile.rawSlots += ${rawV}.length; _ctx._pmProfile.triviaSlots += ${tlV}.length${fArr ? `; _ctx._pmProfile.fieldSlots += ${fArr} ? ${fArr}.length : 0` : ""}`,
|
|
5381
|
+
`${i} }`,
|
|
5382
|
+
`${i}}`
|
|
5383
|
+
);
|
|
5318
5384
|
let stV = "undefined";
|
|
5319
5385
|
if (structural) {
|
|
5320
5386
|
stV = v(ctx, "_nst");
|
|
5321
5387
|
stmts.push(`${i}const ${stV} = ${capSTv} && _ctx.state !== undefined ? Object.assign({}, _ctx.state) : undefined`);
|
|
5322
5388
|
} else if (clonesState) {
|
|
5323
5389
|
stV = v(ctx, "_nst");
|
|
5324
|
-
stmts.push(`${i}const ${stV} = _ctx.state !== undefined ? Object.assign({}, _ctx.state) : undefined`);
|
|
5390
|
+
stmts.push(`${i}const ${stV} = !(${profileRecognizer} || ${profileCapture}) && _ctx.state !== undefined ? Object.assign({}, _ctx.state) : undefined`);
|
|
5325
5391
|
}
|
|
5326
5392
|
if (sf && fArr) {
|
|
5327
5393
|
const fe = v(ctx, "_fe");
|
|
@@ -5341,15 +5407,17 @@ ${i}const ${chV} = [], ${rawV} = [], ${tlV} = ${capTLv} ? [] : _EMPTY_TL` : capt
|
|
|
5341
5407
|
}
|
|
5342
5408
|
const ndV = v(ctx, "_nd");
|
|
5343
5409
|
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})`;
|
|
5344
|
-
const ndExpr = ctx.ns || structural ? `_ctx.build !== undefined ? _ctx.build(${JSON.stringify(def.type)}, ${chV}, ${fObj}, { start: ${pos}, end: ${endVar} }, ${rawV}, ${tlV}, ${stV}) : (${buildExpr})` : buildExpr;
|
|
5410
|
+
const ndExpr = ctx.ns || structural ? `_ctx.build !== undefined ? (_ctx._pmProfile?.phase === 'host' && _ctx._pmProfile.hostCalls++, _ctx.build(${JSON.stringify(def.type)}, ${chV}, ${fObj}, { start: ${pos}, end: ${endVar} }, ${rawV}, ${tlV}, ${stV})) : (${buildExpr})` : buildExpr;
|
|
5345
5411
|
const hostCollapseExpr = ctx.ns || 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;
|
|
5346
5412
|
const unwrapExpr = `${chV}.length === 1 ? (${chV}[0] !== null && typeof ${chV}[0] === 'object' && ${chV}[0]._tag === 'leaf' ? ${chV}[0].value : ${chV}[0]) : (${ndExpr})`;
|
|
5347
5413
|
const collapseExpr = `${chV}.length === 1 ? ${chV}[0] : (${ndExpr})`;
|
|
5348
5414
|
const finalExpr = def.unwrap ? unwrapExpr : def.collapse ? collapseExpr : hostCollapseExpr;
|
|
5349
5415
|
stmts.push(
|
|
5350
|
-
`${i}const ${ndV} = ${finalExpr}`,
|
|
5351
|
-
`${i}if (${
|
|
5352
|
-
`${i}if (${
|
|
5416
|
+
`${i}const ${ndV} = (${profileRecognizer} || ${profileCapture}) ? undefined : (${finalExpr})`,
|
|
5417
|
+
`${i}if (!(${profileRecognizer})) {`,
|
|
5418
|
+
`${i} if (${sc}) ${sc}.push(${ndV})`,
|
|
5419
|
+
`${i} if (${sr}) ${sr}.push((typeof ${ndV} === 'object' && ${ndV} !== null && (${ndV}._tag === 'node' || ${ndV}._tag === 'leaf' || ${ndV}._tag === 'parseError')) ? ${ndV} : { _tag: 'leaf', value: typeof ${ndV} === 'string' ? ${ndV} : '', span: { start: ${pos}, end: ${endVar} } })`,
|
|
5420
|
+
`${i}}`
|
|
5353
5421
|
);
|
|
5354
5422
|
return { stmts, valueVar: ndV, endVar };
|
|
5355
5423
|
}
|
|
@@ -7317,7 +7385,7 @@ function parseDoc(registry, rootRule, input, opts = {}) {
|
|
|
7317
7385
|
|
|
7318
7386
|
// src/functional/run.ts
|
|
7319
7387
|
var invoke = (r, input, pos, ctx) => typeof r === "function" ? r(input, pos, ctx) : r.parse(input, pos, ctx);
|
|
7320
|
-
function
|
|
7388
|
+
function runOnce(entry, input, options, phase, profileState) {
|
|
7321
7389
|
if (typeof entry !== "function" && typeof entry?.parse !== "function") {
|
|
7322
7390
|
throw new TypeError(
|
|
7323
7391
|
`run(): start production is ${entry === null ? "null" : typeof entry}, not a rule \u2014 the requested grammar rule does not exist (check the rule name).`
|
|
@@ -7325,11 +7393,12 @@ function run(entry, input, options = {}) {
|
|
|
7325
7393
|
}
|
|
7326
7394
|
const triviaLog = [];
|
|
7327
7395
|
const errors = [];
|
|
7396
|
+
const profile = profileState ?? (phase === void 0 ? void 0 : { phase, nodes: 0, childSlots: 0, rawSlots: 0, triviaSlots: 0, fieldSlots: 0, hostCalls: 0 });
|
|
7397
|
+
const skipGlobalSinks = phase === "recognizer" || phase === "capture";
|
|
7328
7398
|
const grammarTrivia = typeof entry !== "function" ? entry._meta.grammarTrivia : void 0;
|
|
7329
7399
|
const ctx = {
|
|
7330
7400
|
trackLines: false,
|
|
7331
|
-
_triviaLog: triviaLog,
|
|
7332
|
-
_errors: errors,
|
|
7401
|
+
...skipGlobalSinks ? { _pmProfile: profile } : { _triviaLog: triviaLog, _errors: errors, ...profile === void 0 ? {} : { _pmProfile: profile } },
|
|
7333
7402
|
build: options.build,
|
|
7334
7403
|
state: options.state,
|
|
7335
7404
|
...grammarTrivia !== void 0 ? { trivia: grammarTrivia, ...grammarTrivia._meta.triviaKindLabels ? { triviaKindLabels: grammarTrivia._meta.triviaKindLabels } : {} } : {},
|
|
@@ -7356,6 +7425,38 @@ function run(entry, input, options = {}) {
|
|
|
7356
7425
|
unconsumedFrom
|
|
7357
7426
|
};
|
|
7358
7427
|
}
|
|
7428
|
+
function clonePassState(state) {
|
|
7429
|
+
if (state === null || typeof state !== "object") return state;
|
|
7430
|
+
return Array.isArray(state) ? [...state] : { ...state };
|
|
7431
|
+
}
|
|
7432
|
+
function profilePass(entry, input, options, phase) {
|
|
7433
|
+
const state = { phase, nodes: 0, childSlots: 0, rawSlots: 0, triviaSlots: 0, fieldSlots: 0, hostCalls: 0 };
|
|
7434
|
+
const passOptions = options.state === void 0 ? options : { ...options, state: clonePassState(options.state) };
|
|
7435
|
+
const start = performance.now();
|
|
7436
|
+
const result = runOnce(entry, input, passOptions, phase, state);
|
|
7437
|
+
const { phase: _phase, ...counts } = state;
|
|
7438
|
+
return { result, profile: { ms: performance.now() - start, ...counts } };
|
|
7439
|
+
}
|
|
7440
|
+
function run(entry, input, options = {}) {
|
|
7441
|
+
if (!options.profile) return runOnce(entry, input, options);
|
|
7442
|
+
if (typeof entry !== "function") {
|
|
7443
|
+
throw new TypeError("run({ profile: true }) requires a compiled parser entry");
|
|
7444
|
+
}
|
|
7445
|
+
const recognizer = profilePass(entry, input, options, "recognizer");
|
|
7446
|
+
const capture = profilePass(entry, input, options, "capture");
|
|
7447
|
+
const host = profilePass(entry, input, options, "host");
|
|
7448
|
+
if (recognizer.result.ok !== host.result.ok || capture.result.ok !== host.result.ok || recognizer.result.unconsumedFrom !== host.result.unconsumedFrom || capture.result.unconsumedFrom !== host.result.unconsumedFrom) {
|
|
7449
|
+
throw new Error("run({ profile: true }) changed recognition; the grammar is not profile-safe");
|
|
7450
|
+
}
|
|
7451
|
+
return {
|
|
7452
|
+
...host.result,
|
|
7453
|
+
profile: {
|
|
7454
|
+
recognizer: recognizer.profile,
|
|
7455
|
+
structuralCapture: capture.profile,
|
|
7456
|
+
hostConstruction: host.profile
|
|
7457
|
+
}
|
|
7458
|
+
};
|
|
7459
|
+
}
|
|
7359
7460
|
|
|
7360
7461
|
// src/cst/trivia-index.ts
|
|
7361
7462
|
function merge(map, key, run2) {
|