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
package/dist/index.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export type { CSTNode, CSTLeaf, CSTError, CSTTrivia, CSTChild, CSTRawChild, Node
|
|
|
33
33
|
export { parseDoc } from './functional/doc.ts';
|
|
34
34
|
export type { ParseDoc, ParseDocOptions, Registry, RuleFn } from './functional/doc.ts';
|
|
35
35
|
export { run } from './functional/run.ts';
|
|
36
|
-
export type { RunResult, RunOptions, Runnable } from './functional/run.ts';
|
|
36
|
+
export type { RunResult, RunOptions, RunProfile, RunProfilePass, Runnable } from './functional/run.ts';
|
|
37
37
|
export { buildTriviaIndex } from './cst/trivia-index.ts';
|
|
38
38
|
export type { TriviaIndex, TriviaToken, TriviaIndexOptions } from './cst/trivia-index.ts';
|
|
39
39
|
export { walk, createVisitor } from './cst/walk.ts';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"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S,EAAE,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AACtG,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AACzF,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AACnD,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AACrF,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACvD,YAAY,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,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
|
@@ -2217,6 +2217,55 @@ function parserHasOwnFields(p, seen = /* @__PURE__ */ new Set()) {
|
|
|
2217
2217
|
return false;
|
|
2218
2218
|
}
|
|
2219
2219
|
}
|
|
2220
|
+
function parserHasTriviaSite(p, seen = /* @__PURE__ */ new Set()) {
|
|
2221
|
+
if (seen.has(p)) return true;
|
|
2222
|
+
seen.add(p);
|
|
2223
|
+
const d = p._def;
|
|
2224
|
+
switch (d.tag) {
|
|
2225
|
+
// Trivia is skipped between/around elements or iterations → a site.
|
|
2226
|
+
case "sequence":
|
|
2227
|
+
case "many":
|
|
2228
|
+
case "oneOrMore":
|
|
2229
|
+
case "sepBy":
|
|
2230
|
+
case "scanTo":
|
|
2231
|
+
case "recover":
|
|
2232
|
+
case "skip":
|
|
2233
|
+
return true;
|
|
2234
|
+
// Nested node manages its own trivia frame; none logs here.
|
|
2235
|
+
case "node":
|
|
2236
|
+
return false;
|
|
2237
|
+
// Pure terminals + trivia-suppressing token: no site.
|
|
2238
|
+
case "regex":
|
|
2239
|
+
case "literal":
|
|
2240
|
+
case "keywords":
|
|
2241
|
+
case "guard":
|
|
2242
|
+
case "token":
|
|
2243
|
+
return false;
|
|
2244
|
+
// Transparent single-child wrappers: recurse.
|
|
2245
|
+
case "optional":
|
|
2246
|
+
case "transform":
|
|
2247
|
+
case "trivia":
|
|
2248
|
+
case "label":
|
|
2249
|
+
case "expect":
|
|
2250
|
+
case "withCtx":
|
|
2251
|
+
case "not":
|
|
2252
|
+
case "field":
|
|
2253
|
+
return parserHasTriviaSite(d.parser, seen);
|
|
2254
|
+
case "choice":
|
|
2255
|
+
return d.parsers.some((x) => parserHasTriviaSite(x, seen));
|
|
2256
|
+
case "grammar":
|
|
2257
|
+
return parserHasTriviaSite(d.parser, seen);
|
|
2258
|
+
case "lazy": {
|
|
2259
|
+
try {
|
|
2260
|
+
return parserHasTriviaSite(d.thunk(), seen);
|
|
2261
|
+
} catch {
|
|
2262
|
+
return true;
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
default:
|
|
2266
|
+
return true;
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2220
2269
|
function buildFieldMap(captures) {
|
|
2221
2270
|
if (!captures?.length) return void 0;
|
|
2222
2271
|
const out = {};
|
|
@@ -5208,32 +5257,49 @@ function emitNode(def, ctx, pos) {
|
|
|
5208
5257
|
const smk = structural ? v(ctx, "_smk") : null;
|
|
5209
5258
|
if (structural) ctx.needsHostReads = true;
|
|
5210
5259
|
const hostTriviaGate = `_ctx.build !== undefined && (_ctx.build._parsemanCaptureTrivia !== undefined ? _ctx.build._parsemanCaptureTrivia(${JSON.stringify(def.type)}) : (_ctx._pmCapTL ??= _hostReads(_ctx.build, 5)))`;
|
|
5211
|
-
const
|
|
5212
|
-
|
|
5260
|
+
const pmV = v(ctx, "_pm"), recV = v(ctx, "_rec"), capV = v(ctx, "_cap");
|
|
5261
|
+
const profHoist = `${i}const ${pmV} = _ctx._pmProfile, ${recV} = ${pmV}?.phase === 'recognizer', ${capV} = ${pmV}?.phase === 'capture'`;
|
|
5262
|
+
const profileRecognizer = recV;
|
|
5263
|
+
const profileCapture = capV;
|
|
5264
|
+
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)))` : ""}
|
|
5265
|
+
${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 : []`;
|
|
5213
5266
|
const innerTl = structural ? `${capTLv} ? ${tlV} : undefined` : capturesTrivia ? tlV : "undefined";
|
|
5214
|
-
const fieldsOn = structural ? capFv ?? "false" : capturesFields ? "true" : "false"
|
|
5267
|
+
const fieldsOn = structural ? capFv ?? "false" : `${profileRecognizer} ? false : ${capturesFields ? "true" : "false"}`;
|
|
5215
5268
|
const sf = hasFields ? v(ctx, "_sf") : null;
|
|
5216
5269
|
const fArr = hasFields ? v(ctx, "_fa") : null;
|
|
5217
5270
|
const fObj = hasFields ? v(ctx, "_fields") : "undefined";
|
|
5271
|
+
const needsTriviaFrame = parserHasTriviaSite(def.parser);
|
|
5272
|
+
const saveTrivia = needsTriviaFrame ? `, ${st} = _ctx.captureTrivia, ${stl} = _ctx._cstTriviaLog${smk ? `, ${smk} = _ctx._triviaCaptureMask` : ""}` : "";
|
|
5273
|
+
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}` : ""}` : "";
|
|
5274
|
+
const restoreTrivia = needsTriviaFrame ? `; _ctx.captureTrivia = ${st}; _ctx._cstTriviaLog = ${stl}${smk ? `; _ctx._triviaCaptureMask = ${smk}` : ""}` : "";
|
|
5218
5275
|
const stmts = [
|
|
5276
|
+
profHoist,
|
|
5219
5277
|
allocStmt,
|
|
5220
|
-
`${i}const ${sc} = _ctx._cstChildren, ${sl} = _ctx._cstLeaves, ${sr} = _ctx._cstRawChildren
|
|
5221
|
-
`${i}_ctx._cstChildren = ${chV}; _ctx._cstLeaves = ${chV}; _ctx._cstRawChildren = ${rawV}
|
|
5278
|
+
`${i}const ${sc} = _ctx._cstChildren, ${sl} = _ctx._cstLeaves, ${sr} = _ctx._cstRawChildren${saveTrivia}${sf ? `, ${sf} = _ctx._fields` : ""}`,
|
|
5279
|
+
`${i}_ctx._cstChildren = ${chV}; _ctx._cstLeaves = ${chV}; _ctx._cstRawChildren = ${rawV}${installTrivia}${sf ? `; _ctx._fields = ${fieldsOn} ? [] : undefined` : ""}`
|
|
5222
5280
|
];
|
|
5223
5281
|
const { stmts: innerStmts, okVar, endVar } = emitFallible(def.parser, ctx, pos);
|
|
5224
5282
|
stmts.push(...innerStmts);
|
|
5225
5283
|
if (sf && fArr) {
|
|
5226
5284
|
stmts.push(`${i}const ${fArr} = _ctx._fields`);
|
|
5227
5285
|
}
|
|
5228
|
-
stmts.push(`${i}_ctx._cstChildren = ${sc}; _ctx._cstLeaves = ${sl}; _ctx._cstRawChildren = ${sr}
|
|
5286
|
+
stmts.push(`${i}_ctx._cstChildren = ${sc}; _ctx._cstLeaves = ${sl}; _ctx._cstRawChildren = ${sr}${restoreTrivia}${sf ? `; _ctx._fields = ${sf}` : ""}`);
|
|
5229
5287
|
stmts.push(...emitIfFail(ctx, `!${okVar}`, propagateFailBody(ctx)));
|
|
5288
|
+
stmts.push(
|
|
5289
|
+
`${i}if (_ctx._pmProfile) {`,
|
|
5290
|
+
`${i} _ctx._pmProfile.nodes++`,
|
|
5291
|
+
`${i} if (${profileCapture}) {`,
|
|
5292
|
+
`${i} _ctx._pmProfile.childSlots += ${chV}.length; _ctx._pmProfile.rawSlots += ${rawV}.length; _ctx._pmProfile.triviaSlots += ${tlV}.length${fArr ? `; _ctx._pmProfile.fieldSlots += ${fArr} ? ${fArr}.length : 0` : ""}`,
|
|
5293
|
+
`${i} }`,
|
|
5294
|
+
`${i}}`
|
|
5295
|
+
);
|
|
5230
5296
|
let stV = "undefined";
|
|
5231
5297
|
if (structural) {
|
|
5232
5298
|
stV = v(ctx, "_nst");
|
|
5233
5299
|
stmts.push(`${i}const ${stV} = ${capSTv} && _ctx.state !== undefined ? Object.assign({}, _ctx.state) : undefined`);
|
|
5234
5300
|
} else if (clonesState) {
|
|
5235
5301
|
stV = v(ctx, "_nst");
|
|
5236
|
-
stmts.push(`${i}const ${stV} = _ctx.state !== undefined ? Object.assign({}, _ctx.state) : undefined`);
|
|
5302
|
+
stmts.push(`${i}const ${stV} = !(${profileRecognizer} || ${profileCapture}) && _ctx.state !== undefined ? Object.assign({}, _ctx.state) : undefined`);
|
|
5237
5303
|
}
|
|
5238
5304
|
if (sf && fArr) {
|
|
5239
5305
|
const fe = v(ctx, "_fe");
|
|
@@ -5253,15 +5319,17 @@ ${i}const ${chV} = [], ${rawV} = [], ${tlV} = ${capTLv} ? [] : _EMPTY_TL` : capt
|
|
|
5253
5319
|
}
|
|
5254
5320
|
const ndV = v(ctx, "_nd");
|
|
5255
5321
|
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})`;
|
|
5256
|
-
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;
|
|
5322
|
+
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;
|
|
5257
5323
|
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;
|
|
5258
5324
|
const unwrapExpr = `${chV}.length === 1 ? (${chV}[0] !== null && typeof ${chV}[0] === 'object' && ${chV}[0]._tag === 'leaf' ? ${chV}[0].value : ${chV}[0]) : (${ndExpr})`;
|
|
5259
5325
|
const collapseExpr = `${chV}.length === 1 ? ${chV}[0] : (${ndExpr})`;
|
|
5260
5326
|
const finalExpr = def.unwrap ? unwrapExpr : def.collapse ? collapseExpr : hostCollapseExpr;
|
|
5261
5327
|
stmts.push(
|
|
5262
|
-
`${i}const ${ndV} = ${finalExpr}`,
|
|
5263
|
-
`${i}if (${
|
|
5264
|
-
`${i}if (${
|
|
5328
|
+
`${i}const ${ndV} = (${profileRecognizer} || ${profileCapture}) ? undefined : (${finalExpr})`,
|
|
5329
|
+
`${i}if (!(${profileRecognizer})) {`,
|
|
5330
|
+
`${i} if (${sc}) ${sc}.push(${ndV})`,
|
|
5331
|
+
`${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} } })`,
|
|
5332
|
+
`${i}}`
|
|
5265
5333
|
);
|
|
5266
5334
|
return { stmts, valueVar: ndV, endVar };
|
|
5267
5335
|
}
|
|
@@ -7229,7 +7297,7 @@ function parseDoc(registry, rootRule, input, opts = {}) {
|
|
|
7229
7297
|
|
|
7230
7298
|
// src/functional/run.ts
|
|
7231
7299
|
var invoke = (r, input, pos, ctx) => typeof r === "function" ? r(input, pos, ctx) : r.parse(input, pos, ctx);
|
|
7232
|
-
function
|
|
7300
|
+
function runOnce(entry, input, options, phase, profileState) {
|
|
7233
7301
|
if (typeof entry !== "function" && typeof entry?.parse !== "function") {
|
|
7234
7302
|
throw new TypeError(
|
|
7235
7303
|
`run(): start production is ${entry === null ? "null" : typeof entry}, not a rule \u2014 the requested grammar rule does not exist (check the rule name).`
|
|
@@ -7237,11 +7305,12 @@ function run(entry, input, options = {}) {
|
|
|
7237
7305
|
}
|
|
7238
7306
|
const triviaLog = [];
|
|
7239
7307
|
const errors = [];
|
|
7308
|
+
const profile = profileState ?? (phase === void 0 ? void 0 : { phase, nodes: 0, childSlots: 0, rawSlots: 0, triviaSlots: 0, fieldSlots: 0, hostCalls: 0 });
|
|
7309
|
+
const skipGlobalSinks = phase === "recognizer" || phase === "capture";
|
|
7240
7310
|
const grammarTrivia = typeof entry !== "function" ? entry._meta.grammarTrivia : void 0;
|
|
7241
7311
|
const ctx = {
|
|
7242
7312
|
trackLines: false,
|
|
7243
|
-
_triviaLog: triviaLog,
|
|
7244
|
-
_errors: errors,
|
|
7313
|
+
...skipGlobalSinks ? { _pmProfile: profile } : { _triviaLog: triviaLog, _errors: errors, ...profile === void 0 ? {} : { _pmProfile: profile } },
|
|
7245
7314
|
build: options.build,
|
|
7246
7315
|
state: options.state,
|
|
7247
7316
|
...grammarTrivia !== void 0 ? { trivia: grammarTrivia, ...grammarTrivia._meta.triviaKindLabels ? { triviaKindLabels: grammarTrivia._meta.triviaKindLabels } : {} } : {},
|
|
@@ -7268,6 +7337,38 @@ function run(entry, input, options = {}) {
|
|
|
7268
7337
|
unconsumedFrom
|
|
7269
7338
|
};
|
|
7270
7339
|
}
|
|
7340
|
+
function clonePassState(state) {
|
|
7341
|
+
if (state === null || typeof state !== "object") return state;
|
|
7342
|
+
return Array.isArray(state) ? [...state] : { ...state };
|
|
7343
|
+
}
|
|
7344
|
+
function profilePass(entry, input, options, phase) {
|
|
7345
|
+
const state = { phase, nodes: 0, childSlots: 0, rawSlots: 0, triviaSlots: 0, fieldSlots: 0, hostCalls: 0 };
|
|
7346
|
+
const passOptions = options.state === void 0 ? options : { ...options, state: clonePassState(options.state) };
|
|
7347
|
+
const start = performance.now();
|
|
7348
|
+
const result = runOnce(entry, input, passOptions, phase, state);
|
|
7349
|
+
const { phase: _phase, ...counts } = state;
|
|
7350
|
+
return { result, profile: { ms: performance.now() - start, ...counts } };
|
|
7351
|
+
}
|
|
7352
|
+
function run(entry, input, options = {}) {
|
|
7353
|
+
if (!options.profile) return runOnce(entry, input, options);
|
|
7354
|
+
if (typeof entry !== "function") {
|
|
7355
|
+
throw new TypeError("run({ profile: true }) requires a compiled parser entry");
|
|
7356
|
+
}
|
|
7357
|
+
const recognizer = profilePass(entry, input, options, "recognizer");
|
|
7358
|
+
const capture = profilePass(entry, input, options, "capture");
|
|
7359
|
+
const host = profilePass(entry, input, options, "host");
|
|
7360
|
+
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) {
|
|
7361
|
+
throw new Error("run({ profile: true }) changed recognition; the grammar is not profile-safe");
|
|
7362
|
+
}
|
|
7363
|
+
return {
|
|
7364
|
+
...host.result,
|
|
7365
|
+
profile: {
|
|
7366
|
+
recognizer: recognizer.profile,
|
|
7367
|
+
structuralCapture: capture.profile,
|
|
7368
|
+
hostConstruction: host.profile
|
|
7369
|
+
}
|
|
7370
|
+
};
|
|
7371
|
+
}
|
|
7271
7372
|
|
|
7272
7373
|
// src/cst/trivia-index.ts
|
|
7273
7374
|
function merge(map, key, run2) {
|