parseman 0.27.0 → 0.27.1
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.map +1 -1
- package/dist/combinators/node.d.ts +8 -0
- package/dist/combinators/node.d.ts.map +1 -1
- package/dist/compiler/codegen.d.ts.map +1 -1
- package/dist/compiler/fields.d.ts +7 -0
- package/dist/compiler/fields.d.ts.map +1 -1
- package/dist/compiler/inline-callback.d.ts.map +1 -1
- package/dist/compiler/ir-serialize.d.ts.map +1 -1
- package/dist/compiler/linker.d.ts.map +1 -1
- package/dist/cst/trivia-entries.d.ts +2 -0
- package/dist/cst/trivia-entries.d.ts.map +1 -1
- package/dist/index.cjs +122 -28
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +122 -28
- package/dist/index.js.map +2 -2
- package/dist/language-service/index.cjs +3 -1
- package/dist/language-service/index.cjs.map +2 -2
- package/dist/language-service/index.js +3 -1
- package/dist/language-service/index.js.map +2 -2
- package/dist/plugin/direct-builder-static.d.ts +8 -0
- package/dist/plugin/direct-builder-static.d.ts.map +1 -0
- package/dist/plugin/evaluator.d.ts.map +1 -1
- package/dist/plugin/index.cjs +305 -39
- package/dist/plugin/index.cjs.map +4 -4
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +305 -39
- package/dist/plugin/index.js.map +4 -4
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -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;AAKnF,MAAM,MAAM,YAAY,GAAG;IACzB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;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AC,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,CAiDrF;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"}
|
|
@@ -26,12 +26,20 @@ 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
|
+
* - `captureTrivia` — capture trivia consumed inside this node even when its
|
|
30
|
+
* enclosing `parser()` did not opt into document-wide trivia capture. This is
|
|
31
|
+
* scoped to the node; sibling and parent nodes retain their own setting.
|
|
32
|
+
* - `trailingTrivia` — after a successful node body, consume the active grammar
|
|
33
|
+
* trivia once into THIS node's log. Intended for a document root whose body is
|
|
34
|
+
* a repetition; do not set it on a block that already has a closing delimiter.
|
|
29
35
|
* Both skip `build` only for a one-child match; zero or two-plus children go
|
|
30
36
|
* through `build` normally.
|
|
31
37
|
*/
|
|
32
38
|
export type NodeOptions = {
|
|
33
39
|
unwrap?: boolean;
|
|
34
40
|
collapse?: boolean;
|
|
41
|
+
captureTrivia?: boolean;
|
|
42
|
+
trailingTrivia?: boolean;
|
|
35
43
|
};
|
|
36
44
|
export declare function node<N>(combinator: Combinator<unknown>, build?: BuildNode<N>, opts?: NodeOptions): Combinator<N>;
|
|
37
45
|
export declare function node<N>(type: string, combinator: Combinator<unknown>, build?: BuildNode<N>, opts?: NodeOptions): Combinator<N>;
|
|
@@ -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;
|
|
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;AAMzG;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,WAAW,GAAG;IAAE,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IAAC,cAAc,CAAC,EAAE,OAAO,CAAA;CAAE,CAAA;AAqBrH,wBAAgB,IAAI,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;AACjH,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -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","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,CAE3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IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,GAC1D,cAAc,GAAG,IAAI,CAsLvB"}
|
|
@@ -17,6 +17,13 @@ export declare function parserHasOwnFields(p: Combinator<unknown>, seen?: Set<Co
|
|
|
17
17
|
* shape returns `true` (keep the frame) — we only elide when provably safe.
|
|
18
18
|
*/
|
|
19
19
|
export declare function parserHasTriviaSite(p: Combinator<unknown>, seen?: Set<Combinator<unknown>>): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Can this node's inner grammar explicitly enable trivia capture? A surrounding
|
|
22
|
+
* node owns the collector, so a nested `parser({ captureTrivia: true })` must
|
|
23
|
+
* allocate that collector before it enters the grammar scope. Nested node()
|
|
24
|
+
* rules own their separate collector and therefore do not contribute here.
|
|
25
|
+
*/
|
|
26
|
+
export declare function parserEnablesTriviaCapture(p: Combinator<unknown>, seen?: Set<Combinator<unknown>>): boolean;
|
|
20
27
|
export declare function buildFieldMap(captures: ReadonlyArray<{
|
|
21
28
|
name: string;
|
|
22
29
|
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;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI,G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;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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inline-callback.d.ts","sourceRoot":"","sources":["../../src/compiler/inline-callback.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"inline-callback.d.ts","sourceRoot":"","sources":["../../src/compiler/inline-callback.ts"],"names":[],"mappings":"AASA,kFAAkF;AAClF,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAKpF;AAwBD,6EAA6E;AAC7E,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAWpF;AAED,4DAA4D;AAC5D,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAQvF;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,EAAE,GAClB,MAAM,GAAG,IAAI,CAWf"}
|
|
@@ -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,EAAa,MAAM,aAAa,CAAA;AAkBxD,KAAK,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,CAAA;AA4C/B,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,GAC9C,MAAM,GAAG,IAAI,CAUf;AAED;;oFAEoF;AACpF,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"ir-serialize.d.ts","sourceRoot":"","sources":["../../src/compiler/ir-serialize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,EAAE,UAAU,EAAa,MAAM,aAAa,CAAA;AAkBxD,KAAK,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,CAAA;AA4C/B,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,GAC9C,MAAM,GAAG,IAAI,CAUf;AAED;;oFAEoF;AACpF,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CA4F/D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linker.d.ts","sourceRoot":"","sources":["../../src/compiler/linker.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,oBAAoB,EAAY,MAAM,aAAa,CAAA;AAaxF,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,EAC7C,EAAE,CAAC,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAC3B,cAAc,CAIhB;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,MAAM,EAAE,GAAG,oBAAoB,CAAA;CAC9D,CAAA;AAyBD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,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C,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACrD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAe3B"}
|
|
@@ -5,6 +5,8 @@ export type TriviaEntriesView = {
|
|
|
5
5
|
readonly stride: number;
|
|
6
6
|
start(i: number): number;
|
|
7
7
|
end(i: number): number;
|
|
8
|
+
/** Raw-child insertion boundary; defined only for a per-node trivia log. */
|
|
9
|
+
insertIndex(i: number): number | undefined;
|
|
8
10
|
kindIndex(i: number): number | undefined;
|
|
9
11
|
kind(i: number): string | undefined;
|
|
10
12
|
text(i: number, input: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trivia-entries.d.ts","sourceRoot":"","sources":["../../src/cst/trivia-entries.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAA;IAC9C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACxB,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACtB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IACxC,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IACnC,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CACvC,CAAA;AAMD;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,SAAS,MAAM,EAAE,EACtB,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,EAC1B,IAAI,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,GAC3B,iBAAiB,
|
|
1
|
+
{"version":3,"file":"trivia-entries.d.ts","sourceRoot":"","sources":["../../src/cst/trivia-entries.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAA;IAC9C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACxB,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACtB,4EAA4E;IAC5E,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IAC1C,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IACxC,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IACnC,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CACvC,CAAA;AAMD;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,SAAS,MAAM,EAAE,EACtB,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,EAC1B,IAAI,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,GAC3B,iBAAiB,CAgCnB"}
|
package/dist/index.cjs
CHANGED
|
@@ -1525,6 +1525,12 @@ function scanTrivia(input, cur, ctx) {
|
|
|
1525
1525
|
const tr = triviaP.parse(input, cur, { trackLines: ctx.trackLines, state: ctx.state });
|
|
1526
1526
|
return { end: tr.ok ? tr.span.end : cur, commit: NOOP_COMMIT };
|
|
1527
1527
|
}
|
|
1528
|
+
function consumeTrivia(input, cur, ctx) {
|
|
1529
|
+
if (!needsDeferredTriviaCommit(ctx)) return advanceTrivia(input, cur, ctx);
|
|
1530
|
+
const scan = scanTrivia(input, cur, ctx);
|
|
1531
|
+
scan.commit();
|
|
1532
|
+
return scan.end;
|
|
1533
|
+
}
|
|
1528
1534
|
function fastTriviaScanner(trivia2) {
|
|
1529
1535
|
const cached = fastTriviaCache.get(trivia2);
|
|
1530
1536
|
if (cached !== void 0) return cached;
|
|
@@ -2354,6 +2360,49 @@ function parserHasTriviaSite(p, seen = /* @__PURE__ */ new Set()) {
|
|
|
2354
2360
|
return true;
|
|
2355
2361
|
}
|
|
2356
2362
|
}
|
|
2363
|
+
function parserEnablesTriviaCapture(p, seen = /* @__PURE__ */ new Set()) {
|
|
2364
|
+
if (seen.has(p)) return false;
|
|
2365
|
+
seen.add(p);
|
|
2366
|
+
const d = p._def;
|
|
2367
|
+
switch (d.tag) {
|
|
2368
|
+
case "grammar":
|
|
2369
|
+
return d.captureTrivia === true || parserEnablesTriviaCapture(d.parser, seen);
|
|
2370
|
+
case "node":
|
|
2371
|
+
return false;
|
|
2372
|
+
case "sequence":
|
|
2373
|
+
case "choice":
|
|
2374
|
+
return d.parsers.some((x) => parserEnablesTriviaCapture(x, seen));
|
|
2375
|
+
case "sepBy":
|
|
2376
|
+
return parserEnablesTriviaCapture(d.parser, seen) || parserEnablesTriviaCapture(d.separator, seen);
|
|
2377
|
+
case "skip":
|
|
2378
|
+
return parserEnablesTriviaCapture(d.main, seen) || parserEnablesTriviaCapture(d.skipped, seen);
|
|
2379
|
+
case "scanTo":
|
|
2380
|
+
return parserEnablesTriviaCapture(d.sentinel, seen) || d.skip.some((x) => parserEnablesTriviaCapture(x, seen));
|
|
2381
|
+
case "recover":
|
|
2382
|
+
return parserEnablesTriviaCapture(d.parser, seen) || parserEnablesTriviaCapture(d.sentinel, seen);
|
|
2383
|
+
case "many":
|
|
2384
|
+
case "oneOrMore":
|
|
2385
|
+
case "optional":
|
|
2386
|
+
case "transform":
|
|
2387
|
+
case "trivia":
|
|
2388
|
+
case "token":
|
|
2389
|
+
case "label":
|
|
2390
|
+
case "field":
|
|
2391
|
+
case "expect":
|
|
2392
|
+
case "withCtx":
|
|
2393
|
+
case "not":
|
|
2394
|
+
return parserEnablesTriviaCapture(d.parser, seen);
|
|
2395
|
+
case "lazy": {
|
|
2396
|
+
try {
|
|
2397
|
+
return parserEnablesTriviaCapture(d.thunk(), seen);
|
|
2398
|
+
} catch {
|
|
2399
|
+
return false;
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
default:
|
|
2403
|
+
return false;
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2357
2406
|
function buildFieldMap(captures) {
|
|
2358
2407
|
if (!captures?.length) return void 0;
|
|
2359
2408
|
const out = {};
|
|
@@ -2391,11 +2440,13 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
|
|
|
2391
2440
|
};
|
|
2392
2441
|
const unwrap = opts?.unwrap === true;
|
|
2393
2442
|
const collapse = opts?.collapse === true;
|
|
2443
|
+
const captureTrivia = opts?.captureTrivia === true;
|
|
2444
|
+
const trailingTrivia = opts?.trailingTrivia === true;
|
|
2394
2445
|
if (unwrap && collapse) {
|
|
2395
2446
|
throw new Error("node() options cannot set both unwrap and collapse");
|
|
2396
2447
|
}
|
|
2397
|
-
const def = unwrap || collapse ? { ...baseDef, ...unwrap ? { unwrap: true } : {}, ...collapse ? { collapse: true } : {} } : baseDef;
|
|
2398
|
-
const capturesTrivia = build ? buildReadsTrivia(def) : true;
|
|
2448
|
+
const def = unwrap || collapse || captureTrivia || trailingTrivia ? { ...baseDef, ...unwrap ? { unwrap: true } : {}, ...collapse ? { collapse: true } : {}, ...captureTrivia ? { captureTrivia: true } : {}, ...trailingTrivia ? { trailingTrivia: true } : {} } : baseDef;
|
|
2449
|
+
const capturesTrivia = captureTrivia || trailingTrivia || (build ? buildReadsTrivia(def) : true);
|
|
2399
2450
|
const clonesState = build ? buildReadsState(def) : true;
|
|
2400
2451
|
const capturesFields = parserHasOwnFields(combinator) && (build ? buildReadsFields(def) : true);
|
|
2401
2452
|
return {
|
|
@@ -2411,7 +2462,11 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
|
|
|
2411
2462
|
ctx._triviaCaptureMask = ctx.build._parsemanTriviaKinds(def.type);
|
|
2412
2463
|
}
|
|
2413
2464
|
if (!capturesTrivia) ctx.captureTrivia = false;
|
|
2414
|
-
|
|
2465
|
+
let r = combinator.parse(input, pos, ctx);
|
|
2466
|
+
if (r.ok && trailingTrivia && ctx.trivia) {
|
|
2467
|
+
const end = consumeTrivia(input, r.span.end, ctx);
|
|
2468
|
+
r = { ...r, span: { start: r.span.start, end } };
|
|
2469
|
+
}
|
|
2415
2470
|
const fields = capturesFields ? buildFieldMap(ctx._fields) : void 0;
|
|
2416
2471
|
ctx._fields = savedFields;
|
|
2417
2472
|
ctx._triviaCaptureMask = savedMask;
|
|
@@ -2419,8 +2474,9 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
|
|
|
2419
2474
|
if (!r.ok) return r;
|
|
2420
2475
|
const st = clonesState && ctx.state !== void 0 ? Object.assign({}, ctx.state) : void 0;
|
|
2421
2476
|
const nodeType = def.type ?? missingInferredType();
|
|
2422
|
-
const
|
|
2423
|
-
const
|
|
2477
|
+
const cstOutput = ctx.build?._parsemanCstOutput === true;
|
|
2478
|
+
const built = unwrap && children.length === 1 ? unwrapChild(children[0]) : collapse && children.length === 1 ? children[0] : !build && ctx.build?._parsemanCstCollapse && children.length === 1 && rawChildren.length === 1 && ctx.build._parsemanCstCollapse(nodeType, children[0], children, rawChildren) ? children[0] : build ? cstOutput && ctx.build ? ctx.build(nodeType, children, fields, r.span, rawChildren, triviaLog, st) : build(children, fields, r.span, rawChildren, triviaLog, st) : ctx.build ? ctx.build(nodeType, children, fields, r.span, rawChildren, triviaLog, st) : { _tag: "node", type: nodeType, span: { start: r.span.start, end: r.span.end }, state: st ?? null, children };
|
|
2479
|
+
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 };
|
|
2424
2480
|
if (saved.buf !== void 0 || saved.ch !== void 0) {
|
|
2425
2481
|
pushCstChild(ctx, built, rawEntry);
|
|
2426
2482
|
}
|
|
@@ -2537,6 +2593,7 @@ function parser(opts, root) {
|
|
|
2537
2593
|
parser: root,
|
|
2538
2594
|
triviaParser: clearTrivia ? void 0 : opts.trivia ?? void 0,
|
|
2539
2595
|
clearTrivia,
|
|
2596
|
+
...opts.captureTrivia ? { captureTrivia: true } : {},
|
|
2540
2597
|
trackLines: opts.trackLines ?? false
|
|
2541
2598
|
},
|
|
2542
2599
|
parse(input, pos, _ctx) {
|
|
@@ -3698,7 +3755,7 @@ function scanBranchLabeled(shape, kindIndex, mint) {
|
|
|
3698
3755
|
` if (${m.end} > _e) {`,
|
|
3699
3756
|
` if (_cap) {`,
|
|
3700
3757
|
` if (_ctx._triviaLog !== undefined) _ctx._triviaLog.push(_e, ${m.end}, ${kindIndex})`,
|
|
3701
|
-
` if (_ctx._cstTriviaLog !== undefined && (_ctx._triviaCaptureMask === undefined || (_ctx._triviaCaptureMask & ${1 << kindIndex}))) _ctx._cstTriviaLog.push(_e, ${m.end}, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0, ${kindIndex})`,
|
|
3758
|
+
` if (_ctx._cstTriviaLog !== undefined && _ctx.captureTrivia && (_ctx._triviaCaptureMask === undefined || (_ctx._triviaCaptureMask & ${1 << kindIndex}))) _ctx._cstTriviaLog.push(_e, ${m.end}, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0, ${kindIndex})`,
|
|
3702
3759
|
` }`,
|
|
3703
3760
|
` _e = ${m.end}`,
|
|
3704
3761
|
` continue`,
|
|
@@ -3754,7 +3811,7 @@ function analyzeTriviaFastPath(trivia2) {
|
|
|
3754
3811
|
var CAP_RECORD = [
|
|
3755
3812
|
` if (_cap && _e > _pos) {`,
|
|
3756
3813
|
` if (_ctx._triviaLog !== undefined) _ctx._triviaLog.push(_pos, _e)`,
|
|
3757
|
-
` if (_ctx._cstTriviaLog !== undefined) _ctx._cstTriviaLog.push(_pos, _e, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0)`,
|
|
3814
|
+
` if (_ctx._cstTriviaLog !== undefined && _ctx.captureTrivia) _ctx._cstTriviaLog.push(_pos, _e, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0)`,
|
|
3758
3815
|
` }`
|
|
3759
3816
|
].join("\n");
|
|
3760
3817
|
function composeFastLoop(shapes) {
|
|
@@ -3814,7 +3871,7 @@ function buildLabeledRegexTriviaFnDecl(fnName, spec, reNames) {
|
|
|
3814
3871
|
` const _ce = _e + _m${i}[0].length`,
|
|
3815
3872
|
` if (_cap) {`,
|
|
3816
3873
|
` if (_ctx._triviaLog !== undefined) _ctx._triviaLog.push(_e, _ce, ${k})`,
|
|
3817
|
-
` if (_ctx._cstTriviaLog !== undefined && (_ctx._triviaCaptureMask === undefined || (_ctx._triviaCaptureMask & ${1 << k}))) _ctx._cstTriviaLog.push(_e, _ce, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0, ${k})`,
|
|
3874
|
+
` if (_ctx._cstTriviaLog !== undefined && _ctx.captureTrivia && (_ctx._triviaCaptureMask === undefined || (_ctx._triviaCaptureMask & ${1 << k}))) _ctx._cstTriviaLog.push(_e, _ce, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0, ${k})`,
|
|
3818
3875
|
` }`,
|
|
3819
3876
|
` _e = _ce`,
|
|
3820
3877
|
` _matched = true`,
|
|
@@ -3852,7 +3909,7 @@ function buildLabeledRuntimeTriviaFnDecl(fnName, spec, rpStartIndex) {
|
|
|
3852
3909
|
` const _ce = _r${i}.span.end`,
|
|
3853
3910
|
` if (_cap) {`,
|
|
3854
3911
|
` if (_ctx._triviaLog !== undefined) _ctx._triviaLog.push(_e, _ce, ${k})`,
|
|
3855
|
-
` if (_ctx._cstTriviaLog !== undefined && (_ctx._triviaCaptureMask === undefined || (_ctx._triviaCaptureMask & ${1 << k}))) _ctx._cstTriviaLog.push(_e, _ce, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0, ${k})`,
|
|
3912
|
+
` if (_ctx._cstTriviaLog !== undefined && _ctx.captureTrivia && (_ctx._triviaCaptureMask === undefined || (_ctx._triviaCaptureMask & ${1 << k}))) _ctx._cstTriviaLog.push(_e, _ce, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0, ${k})`,
|
|
3856
3913
|
` }`,
|
|
3857
3914
|
` _e = _ce`,
|
|
3858
3915
|
` _matched = true`,
|
|
@@ -4195,7 +4252,7 @@ function ensureTriviaFn(ctx) {
|
|
|
4195
4252
|
` }`,
|
|
4196
4253
|
` if (_cap && _e > _pos) {`,
|
|
4197
4254
|
` if (_ctx._triviaLog !== undefined) _ctx._triviaLog.push(_pos, _e)`,
|
|
4198
|
-
` if (_ctx._cstTriviaLog !== undefined) _ctx._cstTriviaLog.push(_pos, _e, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0)`,
|
|
4255
|
+
` if (_ctx._cstTriviaLog !== undefined && _ctx.captureTrivia) _ctx._cstTriviaLog.push(_pos, _e, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0)`,
|
|
4199
4256
|
` }`,
|
|
4200
4257
|
` return _e`,
|
|
4201
4258
|
`}`
|
|
@@ -5330,17 +5387,18 @@ function emitNode(def, ctx, pos) {
|
|
|
5330
5387
|
ctx.buildSrcs.push(def.buildSrc ?? null);
|
|
5331
5388
|
}
|
|
5332
5389
|
const i = ind(ctx);
|
|
5333
|
-
const capturesTrivia = mkType !== null || !structural && buildReadsTrivia(def);
|
|
5390
|
+
const capturesTrivia = mkType !== null || def.captureTrivia === true || def.trailingTrivia === true || !structural && buildReadsTrivia(def);
|
|
5334
5391
|
const clonesState = !structural && buildReadsState(def);
|
|
5335
5392
|
const hasFields = parserHasOwnFields(def.parser);
|
|
5336
5393
|
const capturesFields = hasFields && !structural && buildReadsFields(def);
|
|
5394
|
+
const innerEnablesTriviaCapture = parserEnablesTriviaCapture(def.parser);
|
|
5337
5395
|
const chV = v(ctx, "_ch");
|
|
5338
5396
|
const rawV = v(ctx, "_raw");
|
|
5339
|
-
const capTLv = structural ? v(ctx, "_ctl") : null;
|
|
5397
|
+
const capTLv = structural || capturesTrivia ? v(ctx, "_ctl") : null;
|
|
5340
5398
|
const capSTv = structural ? v(ctx, "_cst") : null;
|
|
5341
5399
|
const capFv = structural && hasFields ? v(ctx, "_cf") : null;
|
|
5342
5400
|
const tlV = capturesTrivia || structural ? v(ctx, "_tl") : "_EMPTY_TL";
|
|
5343
|
-
if (!capturesTrivia) ctx.needsEmptyTl = true;
|
|
5401
|
+
if (!capturesTrivia || structural) ctx.needsEmptyTl = true;
|
|
5344
5402
|
const sc = v(ctx, "_sc"), sl = v(ctx, "_sl"), sr = v(ctx, "_sr"), st = v(ctx, "_st"), stl = v(ctx, "_stl");
|
|
5345
5403
|
const smk = structural ? v(ctx, "_smk") : null;
|
|
5346
5404
|
if (structural) ctx.needsHostReads = true;
|
|
@@ -5349,16 +5407,17 @@ function emitNode(def, ctx, pos) {
|
|
|
5349
5407
|
const profHoist = `${i}const ${pmV} = _ctx._pmProfile, ${recV} = ${pmV}?.phase === 'recognizer', ${capV} = ${pmV}?.phase === 'capture'`;
|
|
5350
5408
|
const profileRecognizer = recV;
|
|
5351
5409
|
const profileCapture = capV;
|
|
5352
|
-
const
|
|
5353
|
-
|
|
5354
|
-
|
|
5410
|
+
const structuralCapturesTrivia = structural && (def.captureTrivia === true || def.trailingTrivia === true);
|
|
5411
|
+
const allocStmt = structural ? `${i}const ${capTLv} = !(${profileRecognizer}) && (${profileCapture} || ${structuralCapturesTrivia ? "true" : hostTriviaGate}), ${capSTv} = !(${profileRecognizer} || ${profileCapture}) && (_ctx._pmCapST ??= (_ctx.build === undefined || _hostReads(_ctx.build, 6)))${capFv ? `, ${capFv} = !(${profileRecognizer}) && (${profileCapture} || (_ctx.build !== undefined && _hostReads(_ctx.build, 2)))` : ""}
|
|
5412
|
+
${i}const ${chV} = ${profileRecognizer} ? undefined : [], ${rawV} = ${profileRecognizer} ? undefined : [], ${tlV} = ${profileRecognizer} ? undefined : ${innerEnablesTriviaCapture ? "[]" : `${capTLv} ? [] : _EMPTY_TL`}` : capturesTrivia ? `${i}const ${capTLv} = !(${profileRecognizer}), ${chV} = ${profileRecognizer} ? undefined : [], ${rawV} = ${profileRecognizer} ? undefined : [], ${tlV} = ${profileRecognizer} ? undefined : []` : `${i}const ${chV} = ${profileRecognizer} ? undefined : [], ${rawV} = ${profileRecognizer} ? undefined : []`;
|
|
5413
|
+
const innerTl = structural || capturesTrivia ? structural && !innerEnablesTriviaCapture ? `${capTLv} ? ${tlV} : undefined` : tlV : "undefined";
|
|
5355
5414
|
const fieldsOn = structural ? capFv ?? "false" : `${profileRecognizer} ? false : ${capturesFields ? "true" : "false"}`;
|
|
5356
5415
|
const sf = hasFields ? v(ctx, "_sf") : null;
|
|
5357
5416
|
const fArr = hasFields ? v(ctx, "_fa") : null;
|
|
5358
5417
|
const fObj = hasFields ? v(ctx, "_fields") : "undefined";
|
|
5359
|
-
const needsTriviaFrame = parserHasTriviaSite(def.parser);
|
|
5418
|
+
const needsTriviaFrame = def.trailingTrivia === true || parserHasTriviaSite(def.parser);
|
|
5360
5419
|
const saveTrivia = needsTriviaFrame ? `, ${st} = _ctx.captureTrivia, ${stl} = _ctx._cstTriviaLog${smk ? `, ${smk} = _ctx._triviaCaptureMask` : ""}` : "";
|
|
5361
|
-
const installTrivia = needsTriviaFrame ? `; _ctx.captureTrivia =
|
|
5420
|
+
const installTrivia = needsTriviaFrame ? `; _ctx.captureTrivia = ${capTLv ?? "false"}; _ctx._cstTriviaLog = ${innerTl}${smk ? `; _ctx._triviaCaptureMask = ${capTLv} && _ctx.build !== undefined && _ctx.build._parsemanTriviaKinds !== undefined ? _ctx.build._parsemanTriviaKinds(${JSON.stringify(def.type)}) : ${smk}` : ""}` : "";
|
|
5362
5421
|
const restoreTrivia = needsTriviaFrame ? `; _ctx.captureTrivia = ${st}; _ctx._cstTriviaLog = ${stl}${smk ? `; _ctx._triviaCaptureMask = ${smk}` : ""}` : "";
|
|
5363
5422
|
const stmts = [
|
|
5364
5423
|
profHoist,
|
|
@@ -5366,8 +5425,13 @@ ${i}const ${chV} = ${profileRecognizer} ? undefined : [], ${rawV} = ${profileRec
|
|
|
5366
5425
|
`${i}const ${sc} = _ctx._cstChildren, ${sl} = _ctx._cstLeaves, ${sr} = _ctx._cstRawChildren${saveTrivia}${sf ? `, ${sf} = _ctx._fields` : ""}`,
|
|
5367
5426
|
`${i}_ctx._cstChildren = ${chV}; _ctx._cstLeaves = ${chV}; _ctx._cstRawChildren = ${rawV}${installTrivia}${sf ? `; _ctx._fields = ${fieldsOn} ? [] : undefined` : ""}`
|
|
5368
5427
|
];
|
|
5369
|
-
const { stmts: innerStmts, okVar, endVar } = emitFallible(def.parser, ctx, pos);
|
|
5428
|
+
const { stmts: innerStmts, okVar, endVar: innerEndVar } = emitFallible(def.parser, ctx, pos);
|
|
5429
|
+
const endVar = def.trailingTrivia === true && ctx.activeTrivia ? v(ctx, "_trailend") : innerEndVar;
|
|
5370
5430
|
stmts.push(...innerStmts);
|
|
5431
|
+
if (def.trailingTrivia === true && ctx.activeTrivia) {
|
|
5432
|
+
const triviaFn = ensureTriviaFn(ctx);
|
|
5433
|
+
stmts.push(`${i}const ${endVar} = ${okVar} ? ${triviaFn}(input, ${innerEndVar}, _ctx, 1) : ${innerEndVar}`);
|
|
5434
|
+
}
|
|
5371
5435
|
if (sf && fArr) {
|
|
5372
5436
|
stmts.push(`${i}const ${fArr} = _ctx._fields`);
|
|
5373
5437
|
}
|
|
@@ -5407,8 +5471,9 @@ ${i}const ${chV} = ${profileRecognizer} ? undefined : [], ${rawV} = ${profileRec
|
|
|
5407
5471
|
}
|
|
5408
5472
|
const ndV = v(ctx, "_nd");
|
|
5409
5473
|
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})`;
|
|
5410
|
-
const
|
|
5411
|
-
const
|
|
5474
|
+
const hostBuildExpr = `_ctx._pmProfile?.phase === 'host' && _ctx._pmProfile.hostCalls++, _ctx.build(${JSON.stringify(def.type)}, ${chV}, ${fObj}, { start: ${pos}, end: ${endVar} }, ${rawV}, ${tlV}, ${stV})`;
|
|
5475
|
+
const ndExpr = structural ? `_ctx.build !== undefined ? (${hostBuildExpr}) : (${buildExpr})` : `_ctx.build?._parsemanCstOutput === true ? (${hostBuildExpr}) : (${buildExpr})`;
|
|
5476
|
+
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;
|
|
5412
5477
|
const unwrapExpr = `${chV}.length === 1 ? (${chV}[0] !== null && typeof ${chV}[0] === 'object' && ${chV}[0]._tag === 'leaf' ? ${chV}[0].value : ${chV}[0]) : (${ndExpr})`;
|
|
5413
5478
|
const collapseExpr = `${chV}.length === 1 ? ${chV}[0] : (${ndExpr})`;
|
|
5414
5479
|
const finalExpr = def.unwrap ? unwrapExpr : def.collapse ? collapseExpr : hostCollapseExpr;
|
|
@@ -5416,7 +5481,7 @@ ${i}const ${chV} = ${profileRecognizer} ? undefined : [], ${rawV} = ${profileRec
|
|
|
5416
5481
|
`${i}const ${ndV} = (${profileRecognizer} || ${profileCapture}) ? undefined : (${finalExpr})`,
|
|
5417
5482
|
`${i}if (!(${profileRecognizer})) {`,
|
|
5418
5483
|
`${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} } })`,
|
|
5484
|
+
`${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} : (typeof ${ndV} === 'object' && ${ndV} !== null ? input.slice(${pos}, ${endVar}) : ''), span: { start: ${pos}, end: ${endVar} } })`,
|
|
5420
5485
|
`${i}}`
|
|
5421
5486
|
);
|
|
5422
5487
|
return { stmts, valueVar: ndV, endVar };
|
|
@@ -5659,10 +5724,19 @@ function emitDispatch(p, ctx, pos) {
|
|
|
5659
5724
|
ctx.triviaKindLabels = def.triviaParser._meta.triviaKindLabels;
|
|
5660
5725
|
}
|
|
5661
5726
|
}
|
|
5727
|
+
const savedCapture = def.captureTrivia ? v(ctx, "_gcap") : null;
|
|
5662
5728
|
const r = emit(def.parser, ctx, pos);
|
|
5663
5729
|
ctx.activeTrivia = savedTrivia;
|
|
5664
5730
|
ctx.triviaKindLabels = savedKindLabels;
|
|
5665
|
-
return r;
|
|
5731
|
+
if (!savedCapture) return r;
|
|
5732
|
+
return {
|
|
5733
|
+
...r,
|
|
5734
|
+
stmts: [
|
|
5735
|
+
`${ind(ctx)}const ${savedCapture} = _ctx.captureTrivia; _ctx.captureTrivia = true`,
|
|
5736
|
+
...r.stmts,
|
|
5737
|
+
`${ind(ctx)}_ctx.captureTrivia = ${savedCapture}`
|
|
5738
|
+
]
|
|
5739
|
+
};
|
|
5666
5740
|
}
|
|
5667
5741
|
case "not":
|
|
5668
5742
|
return emitNot(def, ctx, pos);
|
|
@@ -6425,9 +6499,15 @@ function evalRuleMapIR(ir) {
|
|
|
6425
6499
|
t._def.fnSrc = src;
|
|
6426
6500
|
return t;
|
|
6427
6501
|
};
|
|
6428
|
-
const _nd = (type, child, src, opts) => {
|
|
6429
|
-
|
|
6502
|
+
const _nd = (type, child, src, opts, staticError) => {
|
|
6503
|
+
if (staticError !== void 0 && staticError.length > 0) {
|
|
6504
|
+
throw new Error(`IR direct node builder for ${type} must be macro-static and self-contained; unsupported binding(s): ${staticError.join(", ")}`);
|
|
6505
|
+
}
|
|
6506
|
+
const n = node(type, child, (() => {
|
|
6507
|
+
throw new Error("IR node build requires static re-lowering");
|
|
6508
|
+
}), opts);
|
|
6430
6509
|
n._def.buildSrc = src;
|
|
6510
|
+
if (staticError !== void 0) n._def.buildStaticError = staticError;
|
|
6431
6511
|
return n;
|
|
6432
6512
|
};
|
|
6433
6513
|
const _gch = (items) => {
|
|
@@ -6677,17 +6757,26 @@ ${body}
|
|
|
6677
6757
|
}
|
|
6678
6758
|
case "node": {
|
|
6679
6759
|
if (def.build !== void 0 && def.buildSrc === void 0) throw new Unserializable("node build without buildSrc");
|
|
6680
|
-
const
|
|
6760
|
+
const optEntries = [
|
|
6761
|
+
...def.unwrap ? ["unwrap: true"] : [],
|
|
6762
|
+
...def.collapse ? ["collapse: true"] : [],
|
|
6763
|
+
...def.captureTrivia ? ["captureTrivia: true"] : [],
|
|
6764
|
+
...def.trailingTrivia ? ["trailingTrivia: true"] : []
|
|
6765
|
+
];
|
|
6766
|
+
const opts = optEntries.length > 0 ? `, { ${optEntries.join(", ")} }` : "";
|
|
6681
6767
|
if (def.type === void 0) {
|
|
6682
6768
|
if (def.buildSrc !== void 0) throw new Unserializable("inferred node build without inferred type");
|
|
6683
6769
|
return opts ? `node(${kid(def.parser)}, undefined${opts})` : `node(${kid(def.parser)})`;
|
|
6684
6770
|
}
|
|
6685
|
-
if (def.buildSrc !== void 0)
|
|
6771
|
+
if (def.buildSrc !== void 0) {
|
|
6772
|
+
const staticError = def.buildStaticError === void 0 ? "" : `${opts ? "" : ", undefined"}, ${JSON.stringify(def.buildStaticError)}`;
|
|
6773
|
+
return `_nd(${JSON.stringify(def.type)}, ${kid(def.parser)}, ${JSON.stringify(def.buildSrc)}${opts}${staticError})`;
|
|
6774
|
+
}
|
|
6686
6775
|
return opts ? `node(${JSON.stringify(def.type)}, ${kid(def.parser)}, undefined${opts})` : `node(${JSON.stringify(def.type)}, ${kid(def.parser)})`;
|
|
6687
6776
|
}
|
|
6688
6777
|
case "grammar": {
|
|
6689
6778
|
const trivia2 = def.clearTrivia ? "null" : def.triviaParser ? kid(def.triviaParser) : "undefined";
|
|
6690
|
-
return `parser({ trivia: ${trivia2}${def.trackLines ? ", trackLines: true" : ""} }, ${kid(def.parser)})`;
|
|
6779
|
+
return `parser({ trivia: ${trivia2}${def.captureTrivia ? ", captureTrivia: true" : ""}${def.trackLines ? ", trackLines: true" : ""} }, ${kid(def.parser)})`;
|
|
6691
6780
|
}
|
|
6692
6781
|
case "withCtx": {
|
|
6693
6782
|
if (def.extraSrc === void 0) throw new Unserializable("withCtx without extraSrc");
|
|
@@ -6725,9 +6814,11 @@ function cstBuildHost(typeOrOptions, children, _fields, span, rawChildren, trivi
|
|
|
6725
6814
|
}
|
|
6726
6815
|
const collapse = normalizeCstCollapse(typeOrOptions?.collapse);
|
|
6727
6816
|
const host = (type, children2, fields, span2, rawChildren2, triviaLog2, state2) => buildCstNode(type, children2, fields, span2, rawChildren2, triviaLog2, state2);
|
|
6817
|
+
host._parsemanCstOutput = true;
|
|
6728
6818
|
if (collapse) host._parsemanCstCollapse = collapse;
|
|
6729
6819
|
return host;
|
|
6730
6820
|
}
|
|
6821
|
+
cstBuildHost._parsemanCstOutput = true;
|
|
6731
6822
|
function fusedBody(pieces) {
|
|
6732
6823
|
const winner = /* @__PURE__ */ new Map();
|
|
6733
6824
|
for (const p of pieces) for (const k of p.keys) winner.set(k, p);
|
|
@@ -7577,6 +7668,9 @@ function triviaEntries(log, labels, opts) {
|
|
|
7577
7668
|
end(i) {
|
|
7578
7669
|
return log[entryOffset(i, stride) + 1];
|
|
7579
7670
|
},
|
|
7671
|
+
insertIndex(i) {
|
|
7672
|
+
return opts?.nodeLog ? log[entryOffset(i, stride) + 2] : void 0;
|
|
7673
|
+
},
|
|
7580
7674
|
kindIndex(i) {
|
|
7581
7675
|
if (!labels) return void 0;
|
|
7582
7676
|
return log[entryOffset(i, stride) + baseStride];
|