parseman 0.20.0 → 0.22.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/combinators/grammar.d.ts +8 -0
- package/dist/combinators/grammar.d.ts.map +1 -1
- package/dist/combinators/parser.d.ts +12 -0
- package/dist/combinators/parser.d.ts.map +1 -1
- package/dist/compiler/codegen.d.ts +3 -1
- package/dist/compiler/codegen.d.ts.map +1 -1
- package/dist/cst/trivia-kinds.d.ts +16 -0
- package/dist/cst/trivia-kinds.d.ts.map +1 -1
- package/dist/functional/run.d.ts +9 -0
- package/dist/functional/run.d.ts.map +1 -1
- package/dist/index.cjs +51 -11
- package/dist/index.cjs.map +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +51 -11
- package/dist/index.js.map +2 -2
- package/dist/plugin/index.cjs +65 -15
- package/dist/plugin/index.cjs.map +2 -2
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +65 -15
- package/dist/plugin/index.js.map +2 -2
- package/dist/types.d.ts +32 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -21,6 +21,14 @@ export type ParserOptions = ParseOptions & {
|
|
|
21
21
|
trivia?: Combinator<unknown> | null;
|
|
22
22
|
/** Record consumed trivia as CSTTrivia tokens in rawChildren. Default: skip. */
|
|
23
23
|
captureTrivia?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Restrict PER-NODE CST trivia capture to these trivia kinds (label names from
|
|
26
|
+
* the trivia's `label()` arms). Whitespace and any other unlisted kind is still
|
|
27
|
+
* skipped over but NOT recorded into a node's `triviaLog` — so a host that only
|
|
28
|
+
* consumes (say) comments pays nothing to log every whitespace run. The global
|
|
29
|
+
* trivia log is unaffected. Requires labeled trivia; ignored otherwise.
|
|
30
|
+
*/
|
|
31
|
+
captureTriviaKinds?: readonly string[];
|
|
24
32
|
};
|
|
25
33
|
export interface ParsemanParser<T> extends Combinator<T> {
|
|
26
34
|
parse(input: string): ParseResult<T>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grammar.d.ts","sourceRoot":"","sources":["../../src/combinators/grammar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAa,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"grammar.d.ts","sourceRoot":"","sources":["../../src/combinators/grammar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAa,MAAM,aAAa,CAAA;AAKnF,MAAM,MAAM,YAAY,GAAG;IACzB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,YAAY,GAAG;IACzC;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,IAAI,CAAA;IACnC,gFAAgF;IAChF,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CACvC,CAAA;AAED,MAAM,WAAW,cAAc,CAAC,CAAC,CAAE,SAAQ,UAAU,CAAC,CAAC,CAAC;IACtD,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;IACpC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;CACrE;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAgDrF;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAElE;AAOD,wBAAgB,KAAK,CAAC,CAAC,EACrB,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EACzB,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,YAAiB,GACtB,WAAW,CAAC,CAAC,CAAC,CAiChB"}
|
|
@@ -21,5 +21,17 @@ import type { Combinator } from '../types.ts';
|
|
|
21
21
|
* rules<{ value: Combinator<JSONValue>; array: Combinator<JSONValue[]> }>(g => ({ ... }))
|
|
22
22
|
* Without it, `g.*` accesses are typed as `any` but the return is still inferred.
|
|
23
23
|
*/
|
|
24
|
+
/**
|
|
25
|
+
* Grammar-level options for `rules()`. Parity with `parser({...})`, but declared
|
|
26
|
+
* ONCE for the whole grammar instead of wrapped around a scope. `trivia` becomes
|
|
27
|
+
* the ambient trivia for every rule (installed at the parse entry, inherited
|
|
28
|
+
* everywhere, incremental parse included); `parser({trivia})` / `noTrivia` still
|
|
29
|
+
* override it locally for a sub-region.
|
|
30
|
+
*/
|
|
31
|
+
export type RulesOptions = {
|
|
32
|
+
/** Ambient trivia for the whole grammar. See `parser({ trivia })` for the shape. */
|
|
33
|
+
trivia?: Combinator<unknown>;
|
|
34
|
+
};
|
|
24
35
|
export declare function rules<T extends Record<string, Combinator<unknown>>>(factory: (self: any) => T): T;
|
|
36
|
+
export declare function rules<T extends Record<string, Combinator<unknown>>>(options: RulesOptions, factory: (self: any) => T): T;
|
|
25
37
|
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/combinators/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAS7C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/combinators/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAS7C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,oFAAoF;IACpF,MAAM,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAA;CAC7B,CAAA;AAKD,wBAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,CAAA;AAClG,wBAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,CAAA"}
|
|
@@ -65,7 +65,9 @@ export declare function ruleDependencies(ruleMap: ReadonlyArray<readonly [string
|
|
|
65
65
|
* @see https://www.greadme.com/blog/security/what-is-content-security-policy-complete-guide
|
|
66
66
|
*/
|
|
67
67
|
export declare function compile<T>(combinator: Combinator<T>, mapFnSources?: string[]): CompiledParser<T>;
|
|
68
|
-
export declare function compileRuleMap(ruleMap: ReadonlyArray<readonly [string, Combinator<unknown>]
|
|
68
|
+
export declare function compileRuleMap(ruleMap: ReadonlyArray<readonly [string, Combinator<unknown>]>, opts?: {
|
|
69
|
+
trivia?: Combinator<unknown>;
|
|
70
|
+
}): {
|
|
69
71
|
keys: string[];
|
|
70
72
|
replacement: string;
|
|
71
73
|
} | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../../src/compiler/codegen.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AA;IAC5B,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC7B;;;;OAIG;IACH,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;IAChC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;IAC3B,YAAY,EAAE,OAAO,CAAA;IACrB,cAAc,EAAE,OAAO,CAAA;IACvB;;;;;OAKG;IACH,KAAK,EAAE,aAAa,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,CAAA;IACrD,QAAQ,EAAE,aAAa,CAAC,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,GACT,cAAc,GAAG,IAAI,CAyKvB"}
|
|
@@ -44,4 +44,20 @@ export declare function tryFastLabeledScan(input: string, cur: number, trivia: C
|
|
|
44
44
|
chunks: TriviaChunk[];
|
|
45
45
|
} | null;
|
|
46
46
|
export declare function recordTriviaChunks(ctx: ParseContext, chunks: readonly TriviaChunk[]): void;
|
|
47
|
+
/**
|
|
48
|
+
* Resolve a per-node trivia capture mask (`ctx._triviaCaptureMask`) from a trivia
|
|
49
|
+
* label table and the kind names a host wants to keep. Returns `undefined` when
|
|
50
|
+
* `labels` is absent (nothing to key on → capture everything).
|
|
51
|
+
*
|
|
52
|
+
* Names in `keep` that aren't in `labels` are **ignored by design**: `keep` is
|
|
53
|
+
* often a dialect-independent list (e.g. `['blockComment', 'lineComment']`) applied
|
|
54
|
+
* to a grammar whose trivia only defines some of them (CSS has no `lineComment`) —
|
|
55
|
+
* so an unknown name is a normal cross-dialect no-op, not necessarily a typo, and
|
|
56
|
+
* is not worth a warning that would cry wolf on legitimate superset lists. An empty
|
|
57
|
+
* `keep` (or one where nothing matches) yields `0`, which means "capture NO trivia
|
|
58
|
+
* into per-node logs" — an intentional, valid state (the global `_triviaLog` is
|
|
59
|
+
* unaffected either way). If you expect comments and get an empty per-node log,
|
|
60
|
+
* check the name against the grammar's `triviaKindLabels`.
|
|
61
|
+
*/
|
|
62
|
+
export declare function triviaKindMask(labels: readonly string[] | undefined, keep: readonly string[]): number | undefined;
|
|
47
63
|
//# sourceMappingURL=trivia-kinds.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trivia-kinds.d.ts","sourceRoot":"","sources":["../../src/cst/trivia-kinds.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI3D,MAAM,MAAM,WAAW,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAA;AAE3E,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;IAClC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAA;KAAE,CAAC,CAAA;IAC/F,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAC5B,CAAA;AAQD,kEAAkE;AAClE,wBAAgB,SAAS,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAA;CAAE,GAAG,IAAI,CAGvG;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,iBAAiB,GAAG,IA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AAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,WAAW,EAAE,CAAA;CAAE,GAAG,IAAI,CAiB/C;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,WAAW,EAAE,GAAG,IAAI,CAe1F;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,EACrC,IAAI,EAAE,SAAS,MAAM,EAAE,GACtB,MAAM,GAAG,SAAS,CAQpB"}
|
package/dist/functional/run.d.ts
CHANGED
|
@@ -31,6 +31,15 @@ export type RunOptions = {
|
|
|
31
31
|
* at its start. Omit to require the parse to reach the exact end itself.
|
|
32
32
|
*/
|
|
33
33
|
trivia?: Runnable;
|
|
34
|
+
/**
|
|
35
|
+
* Restrict PER-NODE CST trivia capture (the `triviaLog` a node's builder sees)
|
|
36
|
+
* to these trivia kinds — a bitmask over the grammar's `triviaKindLabels`
|
|
37
|
+
* indices (build it with `triviaKindMask(labels, ['comment', …])`). Unlisted
|
|
38
|
+
* kinds (e.g. whitespace) are skipped over but not recorded per node, so a host
|
|
39
|
+
* that only reads comments doesn't pay to log every whitespace run. The global
|
|
40
|
+
* `triviaLog` returned by `run()` is unaffected. Omit to capture every kind.
|
|
41
|
+
*/
|
|
42
|
+
triviaCaptureMask?: number;
|
|
34
43
|
};
|
|
35
44
|
export type RunResult = {
|
|
36
45
|
ok: boolean;
|
|
@@ -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;AAEpF;;;;;;;;;;;;GAYG;AAEH,+EAA+E;AAC/E,MAAM,MAAM,QAAQ,GAChB,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM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AClF,MAAM,EAAE,UAAU,EAAE,CAAA;IACpB;;;;;;OAMG;IACH,SAAS,EAAE,MAAM,EAAE,CAAA;IACnB;;;;4BAIwB;IACxB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;CAC9B,CAAA;AAKD,wBAAgB,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,GAAG,SAAS,CA8CvF"}
|
package/dist/index.cjs
CHANGED
|
@@ -80,6 +80,7 @@ __export(index_exports, {
|
|
|
80
80
|
transform: () => transform,
|
|
81
81
|
trivia: () => trivia,
|
|
82
82
|
triviaEntries: () => triviaEntries,
|
|
83
|
+
triviaKindMask: () => triviaKindMask,
|
|
83
84
|
walk: () => walk,
|
|
84
85
|
withCtx: () => withCtx,
|
|
85
86
|
word: () => word
|
|
@@ -1266,13 +1267,25 @@ function tryFastLabeledScan(input, cur, trivia2) {
|
|
|
1266
1267
|
}
|
|
1267
1268
|
function recordTriviaChunks(ctx, chunks) {
|
|
1268
1269
|
const kinds = ctx.triviaKindLabels;
|
|
1270
|
+
const mask = ctx._triviaCaptureMask;
|
|
1269
1271
|
for (const ch of chunks) {
|
|
1270
1272
|
pushTriviaLogEntry(ctx, ch.start, ch.end, kinds ? ch.kindIndex : void 0);
|
|
1271
1273
|
if (ctx.captureTrivia && (ctx._cstBuf !== void 0 || ctx._cstTriviaLog !== void 0)) {
|
|
1272
|
-
|
|
1274
|
+
if (mask === void 0 || kinds === void 0 || (mask & 1 << ch.kindIndex) !== 0) {
|
|
1275
|
+
pushCstTriviaEntry(ctx, ch.start, ch.end, kinds ? ch.kindIndex : void 0);
|
|
1276
|
+
}
|
|
1273
1277
|
}
|
|
1274
1278
|
}
|
|
1275
1279
|
}
|
|
1280
|
+
function triviaKindMask(labels, keep) {
|
|
1281
|
+
if (!labels) return void 0;
|
|
1282
|
+
let mask = 0;
|
|
1283
|
+
for (const name of keep) {
|
|
1284
|
+
const idx = labels.indexOf(name);
|
|
1285
|
+
if (idx >= 0) mask |= 1 << idx;
|
|
1286
|
+
}
|
|
1287
|
+
return mask;
|
|
1288
|
+
}
|
|
1276
1289
|
|
|
1277
1290
|
// src/combinators/trivia-skip.ts
|
|
1278
1291
|
var NOOP_COMMIT = () => {
|
|
@@ -1766,7 +1779,9 @@ function tagRule(r, key) {
|
|
|
1766
1779
|
r._ruleName = key;
|
|
1767
1780
|
if (r._def.tag === "node" && r._def.type === void 0) r._def.type = key;
|
|
1768
1781
|
}
|
|
1769
|
-
function rules(
|
|
1782
|
+
function rules(a, b) {
|
|
1783
|
+
const factory = typeof a === "function" ? a : b;
|
|
1784
|
+
const options = typeof a === "function" ? b : a;
|
|
1770
1785
|
const cache = {};
|
|
1771
1786
|
const proxy = new Proxy(cache, {
|
|
1772
1787
|
get(target, key) {
|
|
@@ -1794,6 +1809,12 @@ function rules(factory) {
|
|
|
1794
1809
|
cache[key] = parser2;
|
|
1795
1810
|
}
|
|
1796
1811
|
}
|
|
1812
|
+
if (options?.trivia !== void 0) {
|
|
1813
|
+
for (const key of Object.keys(definitions)) {
|
|
1814
|
+
const rule = cache[key];
|
|
1815
|
+
if (rule && !rule._meta.isTrivia) rule._meta.grammarTrivia = options.trivia;
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1797
1818
|
for (const key of Object.keys(definitions)) {
|
|
1798
1819
|
markUnusedValues(cache[key]);
|
|
1799
1820
|
}
|
|
@@ -1961,10 +1982,15 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
|
|
|
1961
1982
|
const saved = beginCstNodeCapture(ctx);
|
|
1962
1983
|
const savedFields = ctx._fields;
|
|
1963
1984
|
ctx._fields = capturesFields ? [] : void 0;
|
|
1985
|
+
const savedMask = ctx._triviaCaptureMask;
|
|
1986
|
+
if (build === void 0 && ctx.build?._parsemanTriviaKinds !== void 0 && def.type !== void 0) {
|
|
1987
|
+
ctx._triviaCaptureMask = ctx.build._parsemanTriviaKinds(def.type);
|
|
1988
|
+
}
|
|
1964
1989
|
if (!capturesTrivia) ctx.captureTrivia = false;
|
|
1965
1990
|
const r = combinator.parse(input, pos, ctx);
|
|
1966
1991
|
const fields = capturesFields ? buildFieldMap(ctx._fields) : void 0;
|
|
1967
1992
|
ctx._fields = savedFields;
|
|
1993
|
+
ctx._triviaCaptureMask = savedMask;
|
|
1968
1994
|
const { children, rawChildren, triviaLog } = endCstNodeCapture(ctx, saved);
|
|
1969
1995
|
if (!r.ok) return r;
|
|
1970
1996
|
const st = clonesState && ctx.state !== void 0 ? Object.assign({}, ctx.state) : void 0;
|
|
@@ -2102,7 +2128,13 @@ function parser(opts, root) {
|
|
|
2102
2128
|
trivia: opts.trivia,
|
|
2103
2129
|
...opts.trivia._meta.triviaKindLabels ? { triviaKindLabels: opts.trivia._meta.triviaKindLabels } : {}
|
|
2104
2130
|
} : {},
|
|
2105
|
-
...opts.captureTrivia || _ctx?.captureTrivia ? { captureTrivia: true } : {}
|
|
2131
|
+
...opts.captureTrivia || _ctx?.captureTrivia ? { captureTrivia: true } : {},
|
|
2132
|
+
// Kind-filter for per-node capture. Resolve against this scope's trivia
|
|
2133
|
+
// labels — this parser's own trivia if it declares one, else the INHERITED
|
|
2134
|
+
// labels (`_ctx.triviaKindLabels`), so captureTriviaKinds still applies when
|
|
2135
|
+
// trivia is inherited rather than re-declared here. No labels → undefined
|
|
2136
|
+
// (capture all).
|
|
2137
|
+
...opts.captureTriviaKinds && !clearTrivia ? { _triviaCaptureMask: triviaKindMask(opts.trivia?._meta.triviaKindLabels ?? _ctx?.triviaKindLabels, opts.captureTriviaKinds) } : {}
|
|
2106
2138
|
};
|
|
2107
2139
|
const result = root.parse(input, pos ?? 0, ctx);
|
|
2108
2140
|
if (trackLines) {
|
|
@@ -2125,8 +2157,10 @@ function parse(combinator, input, opts = {}) {
|
|
|
2125
2157
|
const trackLines = opts.trackLines ?? false;
|
|
2126
2158
|
const _errors = opts.recover ? [] : void 0;
|
|
2127
2159
|
const _probe = opts.recover ? { offset: input.length, best: null } : void 0;
|
|
2160
|
+
const grammarTrivia = combinator._meta.grammarTrivia;
|
|
2128
2161
|
const ctx = {
|
|
2129
2162
|
trackLines,
|
|
2163
|
+
...grammarTrivia !== void 0 ? { trivia: grammarTrivia, ...grammarTrivia._meta.triviaKindLabels ? { triviaKindLabels: grammarTrivia._meta.triviaKindLabels } : {} } : {},
|
|
2130
2164
|
..._errors !== void 0 ? { _errors } : {},
|
|
2131
2165
|
..._probe !== void 0 ? { _probe } : {}
|
|
2132
2166
|
};
|
|
@@ -3275,7 +3309,7 @@ function scanBranchLabeled(shape, kindIndex, mint) {
|
|
|
3275
3309
|
` if (${m.end} > _e) {`,
|
|
3276
3310
|
` if (_cap) {`,
|
|
3277
3311
|
` if (_ctx._triviaLog !== undefined) _ctx._triviaLog.push(_e, ${m.end}, ${kindIndex})`,
|
|
3278
|
-
` if (_ctx._cstTriviaLog !== undefined) _ctx._cstTriviaLog.push(_e, ${m.end}, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0, ${kindIndex})`,
|
|
3312
|
+
` if (_ctx._cstTriviaLog !== undefined && (_ctx._triviaCaptureMask === undefined || (_ctx._triviaCaptureMask & ${1 << kindIndex}))) _ctx._cstTriviaLog.push(_e, ${m.end}, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0, ${kindIndex})`,
|
|
3279
3313
|
` }`,
|
|
3280
3314
|
` _e = ${m.end}`,
|
|
3281
3315
|
` continue`,
|
|
@@ -3391,7 +3425,7 @@ function buildLabeledRegexTriviaFnDecl(fnName, spec, reNames) {
|
|
|
3391
3425
|
` const _ce = _e + _m${i}[0].length`,
|
|
3392
3426
|
` if (_cap) {`,
|
|
3393
3427
|
` if (_ctx._triviaLog !== undefined) _ctx._triviaLog.push(_e, _ce, ${k})`,
|
|
3394
|
-
` if (_ctx._cstTriviaLog !== undefined) _ctx._cstTriviaLog.push(_e, _ce, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0, ${k})`,
|
|
3428
|
+
` if (_ctx._cstTriviaLog !== undefined && (_ctx._triviaCaptureMask === undefined || (_ctx._triviaCaptureMask & ${1 << k}))) _ctx._cstTriviaLog.push(_e, _ce, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0, ${k})`,
|
|
3395
3429
|
` }`,
|
|
3396
3430
|
` _e = _ce`,
|
|
3397
3431
|
` _matched = true`,
|
|
@@ -3429,7 +3463,7 @@ function buildLabeledRuntimeTriviaFnDecl(fnName, spec, rpStartIndex) {
|
|
|
3429
3463
|
` const _ce = _r${i}.span.end`,
|
|
3430
3464
|
` if (_cap) {`,
|
|
3431
3465
|
` if (_ctx._triviaLog !== undefined) _ctx._triviaLog.push(_e, _ce, ${k})`,
|
|
3432
|
-
` if (_ctx._cstTriviaLog !== undefined) _ctx._cstTriviaLog.push(_e, _ce, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0, ${k})`,
|
|
3466
|
+
` if (_ctx._cstTriviaLog !== undefined && (_ctx._triviaCaptureMask === undefined || (_ctx._triviaCaptureMask & ${1 << k}))) _ctx._cstTriviaLog.push(_e, _ce, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0, ${k})`,
|
|
3433
3467
|
` }`,
|
|
3434
3468
|
` _e = _ce`,
|
|
3435
3469
|
` _matched = true`,
|
|
@@ -4819,6 +4853,7 @@ function emitNode(def, ctx, pos) {
|
|
|
4819
4853
|
const tlV = capturesTrivia || structural ? v(ctx, "_tl") : "_EMPTY_TL";
|
|
4820
4854
|
if (!capturesTrivia) ctx.needsEmptyTl = true;
|
|
4821
4855
|
const sc = v(ctx, "_sc"), sl = v(ctx, "_sl"), sr = v(ctx, "_sr"), st = v(ctx, "_st"), stl = v(ctx, "_stl");
|
|
4856
|
+
const smk = structural ? v(ctx, "_smk") : null;
|
|
4822
4857
|
if (structural) ctx.needsHostReads = true;
|
|
4823
4858
|
const hostTriviaGate = `_ctx.build !== undefined && (_ctx.build._parsemanCaptureTrivia !== undefined ? _ctx.build._parsemanCaptureTrivia(${JSON.stringify(def.type)}) : (_ctx._pmCapTL ??= _hostReads(_ctx.build, 5)))`;
|
|
4824
4859
|
const allocStmt = structural ? `${i}const ${capTLv} = ${hostTriviaGate}, ${capSTv} = _ctx._pmCapST ??= (_ctx.build === undefined || _hostReads(_ctx.build, 6))${capFv ? `, ${capFv} = _ctx.build !== undefined && _hostReads(_ctx.build, 2)` : ""}
|
|
@@ -4830,15 +4865,15 @@ ${i}const ${chV} = [], ${rawV} = [], ${tlV} = ${capTLv} ? [] : _EMPTY_TL` : capt
|
|
|
4830
4865
|
const fObj = hasFields ? v(ctx, "_fields") : "undefined";
|
|
4831
4866
|
const stmts = [
|
|
4832
4867
|
allocStmt,
|
|
4833
|
-
`${i}const ${sc} = _ctx._cstChildren, ${sl} = _ctx._cstLeaves, ${sr} = _ctx._cstRawChildren, ${st} = _ctx.captureTrivia, ${stl} = _ctx._cstTriviaLog${sf ? `, ${sf} = _ctx._fields` : ""}`,
|
|
4834
|
-
`${i}_ctx._cstChildren = ${chV}; _ctx._cstLeaves = ${chV}; _ctx._cstRawChildren = ${rawV}; _ctx.captureTrivia = true; _ctx._cstTriviaLog = ${innerTl}${sf ? `; _ctx._fields = ${fieldsOn} ? [] : undefined` : ""}`
|
|
4868
|
+
`${i}const ${sc} = _ctx._cstChildren, ${sl} = _ctx._cstLeaves, ${sr} = _ctx._cstRawChildren, ${st} = _ctx.captureTrivia, ${stl} = _ctx._cstTriviaLog${smk ? `, ${smk} = _ctx._triviaCaptureMask` : ""}${sf ? `, ${sf} = _ctx._fields` : ""}`,
|
|
4869
|
+
`${i}_ctx._cstChildren = ${chV}; _ctx._cstLeaves = ${chV}; _ctx._cstRawChildren = ${rawV}; _ctx.captureTrivia = true; _ctx._cstTriviaLog = ${innerTl}${smk ? `; _ctx._triviaCaptureMask = ${capTLv} && _ctx.build._parsemanTriviaKinds !== undefined ? _ctx.build._parsemanTriviaKinds(${JSON.stringify(def.type)}) : ${smk}` : ""}${sf ? `; _ctx._fields = ${fieldsOn} ? [] : undefined` : ""}`
|
|
4835
4870
|
];
|
|
4836
4871
|
const { stmts: innerStmts, okVar, endVar } = emitFallible(def.parser, ctx, pos);
|
|
4837
4872
|
stmts.push(...innerStmts);
|
|
4838
4873
|
if (sf && fArr) {
|
|
4839
4874
|
stmts.push(`${i}const ${fArr} = _ctx._fields`);
|
|
4840
4875
|
}
|
|
4841
|
-
stmts.push(`${i}_ctx._cstChildren = ${sc}; _ctx._cstLeaves = ${sl}; _ctx._cstRawChildren = ${sr}; _ctx.captureTrivia = ${st}; _ctx._cstTriviaLog = ${stl}${sf ? `; _ctx._fields = ${sf}` : ""}`);
|
|
4876
|
+
stmts.push(`${i}_ctx._cstChildren = ${sc}; _ctx._cstLeaves = ${sl}; _ctx._cstRawChildren = ${sr}; _ctx.captureTrivia = ${st}; _ctx._cstTriviaLog = ${stl}${smk ? `; _ctx._triviaCaptureMask = ${smk}` : ""}${sf ? `; _ctx._fields = ${sf}` : ""}`);
|
|
4842
4877
|
stmts.push(...emitIfFail(ctx, `!${okVar}`, propagateFailBody(ctx)));
|
|
4843
4878
|
let stV = "undefined";
|
|
4844
4879
|
if (structural) {
|
|
@@ -5391,6 +5426,7 @@ function ruleDependencies(ruleMap) {
|
|
|
5391
5426
|
}
|
|
5392
5427
|
function compile(combinator, mapFnSources) {
|
|
5393
5428
|
markUnusedValues(combinator);
|
|
5429
|
+
const grammarTrivia = combinator._meta.grammarTrivia;
|
|
5394
5430
|
const ctx = {
|
|
5395
5431
|
vars: 0,
|
|
5396
5432
|
indent: 1,
|
|
@@ -5409,7 +5445,8 @@ function compile(combinator, mapFnSources) {
|
|
|
5409
5445
|
triviaFnNames: /* @__PURE__ */ new Map(),
|
|
5410
5446
|
namedFnDecls: [],
|
|
5411
5447
|
capturing: hasNodeDef(combinator),
|
|
5412
|
-
lazyUsage: analyzeLazyUsage(combinator)
|
|
5448
|
+
lazyUsage: analyzeLazyUsage(combinator),
|
|
5449
|
+
...grammarTrivia ? { activeTrivia: grammarTrivia, triviaKindLabels: grammarTrivia._meta.triviaKindLabels } : {}
|
|
5413
5450
|
};
|
|
5414
5451
|
const r = emit(combinator, ctx, "_pos");
|
|
5415
5452
|
const namedPrelude = ctx.namedFnDecls.length > 0 ? [...namedFnPrelude(), ""] : [];
|
|
@@ -6267,12 +6304,15 @@ function run(entry, input, options = {}) {
|
|
|
6267
6304
|
}
|
|
6268
6305
|
const triviaLog = [];
|
|
6269
6306
|
const errors = [];
|
|
6307
|
+
const grammarTrivia = typeof entry !== "function" ? entry._meta.grammarTrivia : void 0;
|
|
6270
6308
|
const ctx = {
|
|
6271
6309
|
trackLines: false,
|
|
6272
6310
|
_triviaLog: triviaLog,
|
|
6273
6311
|
_errors: errors,
|
|
6274
6312
|
build: options.build,
|
|
6275
|
-
state: options.state
|
|
6313
|
+
state: options.state,
|
|
6314
|
+
...grammarTrivia !== void 0 ? { trivia: grammarTrivia, ...grammarTrivia._meta.triviaKindLabels ? { triviaKindLabels: grammarTrivia._meta.triviaKindLabels } : {} } : {},
|
|
6315
|
+
...options.triviaCaptureMask !== void 0 ? { _triviaCaptureMask: options.triviaCaptureMask } : {}
|
|
6276
6316
|
};
|
|
6277
6317
|
const r = invoke(entry, input, 0, ctx);
|
|
6278
6318
|
let unconsumedFrom = null;
|