parseman 0.5.0 → 0.6.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.
Files changed (65) hide show
  1. package/README.md +15 -11
  2. package/dist/combinators/choice.d.ts.map +1 -1
  3. package/dist/combinators/completions.d.ts +1 -1
  4. package/dist/combinators/completions.d.ts.map +1 -1
  5. package/dist/combinators/grammar.d.ts.map +1 -1
  6. package/dist/combinators/keywords.d.ts +22 -0
  7. package/dist/combinators/keywords.d.ts.map +1 -1
  8. package/dist/combinators/literal.d.ts.map +1 -1
  9. package/dist/combinators/map.d.ts +8 -2
  10. package/dist/combinators/map.d.ts.map +1 -1
  11. package/dist/combinators/node.d.ts +10 -11
  12. package/dist/combinators/node.d.ts.map +1 -1
  13. package/dist/combinators/not.d.ts +3 -3
  14. package/dist/combinators/not.d.ts.map +1 -1
  15. package/dist/combinators/recover.d.ts +2 -2
  16. package/dist/combinators/recover.d.ts.map +1 -1
  17. package/dist/combinators/regex.d.ts.map +1 -1
  18. package/dist/combinators/repeat.d.ts +4 -4
  19. package/dist/combinators/repeat.d.ts.map +1 -1
  20. package/dist/combinators/scanTo.d.ts.map +1 -1
  21. package/dist/combinators/sequence.d.ts.map +1 -1
  22. package/dist/combinators/trivia-skip.d.ts +16 -10
  23. package/dist/combinators/trivia-skip.d.ts.map +1 -1
  24. package/dist/combinators/withCtx.d.ts +2 -2
  25. package/dist/combinators/withCtx.d.ts.map +1 -1
  26. package/dist/compiler/codegen.d.ts +4 -2
  27. package/dist/compiler/codegen.d.ts.map +1 -1
  28. package/dist/compiler/inline-build.d.ts +11 -0
  29. package/dist/compiler/inline-build.d.ts.map +1 -0
  30. package/dist/compiler/inline-callback.d.ts +12 -0
  31. package/dist/compiler/inline-callback.d.ts.map +1 -0
  32. package/dist/compiler/trivia-fast-path.d.ts +24 -0
  33. package/dist/compiler/trivia-fast-path.d.ts.map +1 -0
  34. package/dist/cst/capture-buffer.d.ts +46 -0
  35. package/dist/cst/capture-buffer.d.ts.map +1 -0
  36. package/dist/cst/trivia-entries.d.ts +20 -0
  37. package/dist/cst/trivia-entries.d.ts.map +1 -0
  38. package/dist/cst/trivia-index.d.ts +11 -11
  39. package/dist/cst/trivia-index.d.ts.map +1 -1
  40. package/dist/cst/trivia-kinds.d.ts +47 -0
  41. package/dist/cst/trivia-kinds.d.ts.map +1 -0
  42. package/dist/cst/types.d.ts +9 -13
  43. package/dist/cst/types.d.ts.map +1 -1
  44. package/dist/functional/doc.d.ts +2 -20
  45. package/dist/functional/doc.d.ts.map +1 -1
  46. package/dist/index.cjs +1238 -662
  47. package/dist/index.cjs.map +4 -4
  48. package/dist/index.d.ts +4 -5
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +1256 -6241
  51. package/dist/index.js.map +4 -4
  52. package/dist/plugin/evaluator.d.ts +7 -0
  53. package/dist/plugin/evaluator.d.ts.map +1 -1
  54. package/dist/plugin/index.cjs +1249 -369
  55. package/dist/plugin/index.cjs.map +4 -4
  56. package/dist/plugin/index.d.ts.map +1 -1
  57. package/dist/plugin/index.js +1249 -369
  58. package/dist/plugin/index.js.map +4 -4
  59. package/dist/types.d.ts +32 -9
  60. package/dist/types.d.ts.map +1 -1
  61. package/package.json +2 -1
  62. package/dist/cst/grammar.d.ts +0 -115
  63. package/dist/cst/grammar.d.ts.map +0 -1
  64. package/dist/cst/incremental.d.ts +0 -40
  65. package/dist/cst/incremental.d.ts.map +0 -1
package/README.md CHANGED
@@ -410,22 +410,26 @@ vscode.workspace.onDidChangeTextDocument(event => {
410
410
  })
411
411
  ```
412
412
 
413
- ### Inheritance — by composition
413
+ ### Extending grammars
414
414
 
415
- Share rules across grammar variants by composition: factor common rules into helpers, and let each variant swap the ones it needs. Because every rule is a plain value, a variant is just different pieces passed into the same `rules()` shape — and it all stays macro-compilable.
415
+ Don't copy a `rules()` factory to make a variant — export what stays the same and pass in (or wrap) what changes. `examples/json/` is the template:
416
+
417
+ | File | What changes |
418
+ |------|----------------|
419
+ | `parser.ts` | Base grammar + `makeJSONParser(customWs)` |
420
+ | `jsonc.ts` | Trivia only — `makeJSONParser(jsoncWs)` |
421
+ | `jsonl.ts` | Document shape — `sepBy(jsonValue, '\n')` with tighter trivia |
416
422
 
417
423
  ```ts
418
- // shared building blocks
419
- const makeIdent = () => regex(/[a-zA-Z_]\w*/)
420
-
421
- export const { Expr } = rules<{ Expr: Combinator<Node> }>(g => {
422
- const ident = makeIdent() // base
423
- // a JSX variant would use regex(/[a-zA-Z_$][\w$]*/) here instead
424
- /* ...rules referencing ident... */
425
- return { Expr: /* ... */ }
426
- })
424
+ // jsonc.ts — same recursive grammar, different trivia
425
+ export const jsoncValue = makeJSONParser(jsoncWs)
426
+
427
+ // jsonl.ts — reuse jsonValue, wrap at the top
428
+ export const jsonl = parser({ trivia: lineWs }, sepBy(jsonValue, literal('\n')))
427
429
  ```
428
430
 
431
+ `makeJSONParser` in `parser.ts` is the knob: one `rules()` body, trivia passed in, `parser({ trivia }, value)` returned. Unchanged core → parameterize; unchanged rule, different document → wrap the export.
432
+
429
433
  ---
430
434
 
431
435
  ## Context-sensitive parsing
@@ -1 +1 @@
1
- {"version":3,"file":"choice.d.ts","sourceRoot":"","sources":["../../src/combinators/choice.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAC+B,QAAQ,EAClD,MAAM,aAAa,CAAA;AAGpB,KAAK,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,KAAK,CAAA;AACvH,KAAK,SAAS,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI;KACrE,CAAC,IAAI,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC,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,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;AAEjD,wBAAgB,MAAM,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,EACxH,GAAG,IAAI,EAAE,CAAC,GACT,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAiI1B;AAwFD,uEAAuE;AACvE,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI,CAKzE;AAED,qEAAqE;AACrE,wBAAgB,eAAe,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAMhG"}
@@ -13,5 +13,5 @@ import type { Combinator } from '../types.ts';
13
13
  * The returned strings use the same labels as ParseFail.expected:
14
14
  * quoted literals like `"\"{\""` and regex patterns like `"/[0-9]+/"`.
15
15
  */
16
- export declare function completionsAt(parser: Combinator<unknown>, input: string, offset: number): string[];
16
+ export declare function completionsAt(combinator: Combinator<unknown>, input: string, offset: number): string[];
17
17
  //# sourceMappingURL=completions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"completions.d.ts","sourceRoot":"","sources":["../../src/combinators/completions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA2B,MAAM,aAAa,CAAA;AAEtE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,EAC3B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,MAAM,EAAE,CAYV"}
1
+ {"version":3,"file":"completions.d.ts","sourceRoot":"","sources":["../../src/combinators/completions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA2B,MAAM,aAAa,CAAA;AAEtE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAC3B,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,EAC/B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,MAAM,EAAE,CAYV"}
@@ -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,EAAE,MAAM,aAAa,CAAA;AAGxE,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,MAAM,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAA;IAC5B,gFAAgF;IAChF,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB,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,CA6BrF;AAED,wBAAgB,KAAK,CAAC,CAAC,EACrB,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EACzB,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,YAAiB,GACtB,WAAW,CAAC,CAAC,CAAC,CAehB"}
1
+ {"version":3,"file":"grammar.d.ts","sourceRoot":"","sources":["../../src/combinators/grammar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAGxE,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,MAAM,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAA;IAC5B,gFAAgF;IAChF,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB,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,CAkCrF;AAED,wBAAgB,KAAK,CAAC,CAAC,EACrB,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EACzB,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,YAAiB,GACtB,WAAW,CAAC,CAAC,CAAC,CAehB"}
@@ -8,6 +8,28 @@ export type KeywordsOptions = {
8
8
  */
9
9
  boundary?: string;
10
10
  };
11
+ /**
12
+ * Match a single keyword with an automatic word-boundary guard. Prevents
13
+ * matching `true` inside `trueish`. The boundary defaults to `_0-9A-Za-z`,
14
+ * which covers most programming-language identifiers.
15
+ *
16
+ * word('true') // matches "true" but not "trueish"
17
+ * word('color', 'A-Za-z-') // CSS-style identifier boundary
18
+ */
19
+ export declare function word(str: string, boundary?: string): Combinator<string>;
20
+ /**
21
+ * Create a keyword factory with a fixed word-boundary class. Use when many
22
+ * keywords share the same boundary (e.g. CSS identifiers). For a single keyword,
23
+ * `word(str, boundary?)` is enough; you can also roll your own factory with
24
+ * `(s) => word(s, boundary)`.
25
+ *
26
+ * const kw = makeWord() // default: '_0-9A-Za-z'
27
+ * const cssKw = makeWord('A-Za-z0-9_-') // dashes allowed in CSS idents
28
+ *
29
+ * const query = kw('query')
30
+ * const color = cssKw('color') // matches "color" but not "color-scheme"
31
+ */
32
+ export declare function makeWord(boundary?: string): (str: string) => Combinator<string>;
11
33
  /**
12
34
  * Match any one of a set of fixed keywords, longest-first (so `border` wins over
13
35
  * `bord`), with an optional trailing word-boundary guard. Compiles to a single
@@ -1 +1 @@
1
- {"version":3,"file":"keywords.d.ts","sourceRoot":"","sources":["../../src/combinators/keywords.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAmD,MAAM,aAAa,CAAA;AAI9F,MAAM,MAAM,eAAe,GAAG;IAC5B,gCAAgC;IAChC,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AAMD;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,GAAE,eAAoB,GAAG,UAAU,CAAC,MAAM,CAAC,CA4CjG"}
1
+ {"version":3,"file":"keywords.d.ts","sourceRoot":"","sources":["../../src/combinators/keywords.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAmD,MAAM,aAAa,CAAA;AAK9F,MAAM,MAAM,eAAe,GAAG;IAC5B,gCAAgC;IAChC,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AAED;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,SAAe,GAAG,UAAU,CAAC,MAAM,CAAC,CAE7E;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,SAAe,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,UAAU,CAAC,MAAM,CAAC,CAErF;AAMD;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,GAAE,eAAoB,GAAG,UAAU,CAAC,MAAM,CAAC,CA2CjG"}
@@ -1 +1 @@
1
- {"version":3,"file":"literal.d.ts","sourceRoot":"","sources":["../../src/combinators/literal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;AAYpF,MAAM,MAAM,cAAc,GAAG;IAC3B,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B,CAAA;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE,cAAmB,GAAG,UAAU,CAAC,MAAM,CAAC,CAgDpF"}
1
+ {"version":3,"file":"literal.d.ts","sourceRoot":"","sources":["../../src/combinators/literal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;AAapF,MAAM,MAAM,cAAc,GAAG;IAC3B,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B,CAAA;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE,cAAmB,GAAG,UAAU,CAAC,MAAM,CAAC,CA+CpF"}
@@ -1,8 +1,14 @@
1
1
  import type { Combinator } from '../types.ts';
2
- export declare function transform<T, U>(parser: Combinator<T>, fn: (value: T, span: {
2
+ export declare function transform<T, U>(combinator: Combinator<T>, fn: (value: T, span: {
3
3
  start: number;
4
4
  end: number;
5
5
  }) => U): Combinator<U>;
6
6
  export declare function skip<T, S>(main: Combinator<T>, skipped: Combinator<S>): Combinator<T>;
7
- export declare function trivia<T>(parser: Combinator<T>): Combinator<T>;
7
+ export declare function trivia<T>(combinator: Combinator<T>): Combinator<T>;
8
+ /**
9
+ * Attach a string label to a parser arm (e.g. trivia `choice` branches).
10
+ * Parse behavior is unchanged; the label is metadata for tooling and future
11
+ * trivia-kind capture (`'whitespace'`, `'blockComment'`, …).
12
+ */
13
+ export declare function label<T>(name: string, combinator: Combinator<T>): Combinator<T>;
8
14
  //# sourceMappingURL=map.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/combinators/map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA6B,MAAM,aAAa,CAAA;AAExE,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,EAC5B,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EACrB,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,KAAK,CAAC,GACxD,UAAU,CAAC,CAAC,CAAC,CAWf;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAarF;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAO9D"}
1
+ {"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/combinators/map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA6B,MAAM,aAAa,CAAA;AAGxE,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,EAC5B,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EACzB,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,KAAK,CAAC,GACxD,UAAU,CAAC,CAAC,CAAC,CAWf;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAarF;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAYlE;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAO/E"}
@@ -1,17 +1,16 @@
1
1
  import type { Combinator } from '../types.ts';
2
2
  /**
3
- * A CST/AST node rule. Runs `parser` while collecting its terminals (and, when
4
- * trivia capture is on, the trivia between them) into `children` / `rawChildren`
5
- * arrays, then calls `build(children, rawChildren, span)` to produce the node.
6
- *
7
- * This is the functional replacement for the class `Parser`'s capital-letter
8
- * rules + `buildNode`: capture is owned by the library (here and in the
9
- * compiler), so grammar authors don't hand-wrap terminals or reconstruct trivia.
3
+ * A CST/AST node rule. Runs `combinator` while collecting its terminals into
4
+ * `children` / `rawChildren` arrays and trivia spans into `triviaLog`, then
5
+ * calls `build(children, rawChildren, span, triviaLog)` to produce the node.
10
6
  *
11
7
  * - `children` — structural items in source order: spanned CSTLeaf terminals
12
8
  * and sub-nodes (whatever `build` returned for inner nodes).
13
- * - `rawChildren` — the same, plus CSTTrivia tokens for trivia consumed between
14
- * terms (only when the parse runs with `captureTrivia`).
9
+ * - `rawChildren` — structural children only (same items as `children`).
10
+ * - `triviaLog` — flat log of trivia entries: each entry is `[start, end, insertIdx]`
11
+ * consumed between terms. `insertIdx` is the rawChildren index
12
+ * before which the trivia was consumed. Use `buildTriviaIndex`
13
+ * to turn this into a before/after lookup table.
15
14
  *
16
15
  * If `build` returns a non-node value (e.g. a bare string for a collapsed rule),
17
16
  * the parent records it as a spanned leaf so its source span is still recoverable.
@@ -19,6 +18,6 @@ import type { Combinator } from '../types.ts';
19
18
  export type BuildNode<N> = (children: ReadonlyArray<unknown>, rawChildren: ReadonlyArray<unknown>, span: {
20
19
  start: number;
21
20
  end: number;
22
- }) => N;
23
- export declare function node<N>(type: string, parser: Combinator<unknown>, build: BuildNode<N>): Combinator<N>;
21
+ }, triviaLog: readonly number[], state: unknown) => N;
22
+ export declare function node<N>(type: string, combinator: Combinator<unknown>, build: BuildNode<N>): Combinator<N>;
24
23
  //# sourceMappingURL=node.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/combinators/node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;AAEpF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CACzB,QAAQ,EAAE,aAAa,CAAC,OAAO,CAAC,EAChC,WAAW,EAAE,aAAa,CAAC,OAAO,CAAC,EACnC,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,KACjC,CAAC,CAAA;AAEN,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAoCrG"}
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/combinators/node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;AAGpF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CACzB,QAAQ,EAAE,aAAa,CAAC,OAAO,CAAC,EAChC,WAAW,EAAE,aAAa,CAAC,OAAO,CAAC,EACnC,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EACpC,SAAS,EAAE,SAAS,MAAM,EAAE,EAC5B,KAAK,EAAE,OAAO,KACX,CAAC,CAAA;AAEN,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CA+BzG"}
@@ -1,7 +1,7 @@
1
1
  import type { Combinator } from '../types.ts';
2
2
  /**
3
- * Negative lookahead. Succeeds (consuming nothing) when `parser` fails;
4
- * fails when `parser` succeeds.
3
+ * Negative lookahead. Succeeds (consuming nothing) when `combinator` fails;
4
+ * fails when `combinator` succeeds.
5
5
  *
6
6
  * The standard way to match a keyword without also matching the prefix
7
7
  * of a longer identifier:
@@ -9,5 +9,5 @@ import type { Combinator } from '../types.ts';
9
9
  * const kwTrue = sequence(literal('true'), not(regex(/\w/)))
10
10
  * // matches "true" in "true && x" but NOT in "trueish" or "trueness"
11
11
  */
12
- export declare function not(parser: Combinator<unknown>): Combinator<null>;
12
+ export declare function not(combinator: Combinator<unknown>): Combinator<null>;
13
13
  //# sourceMappingURL=not.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"not.d.ts","sourceRoot":"","sources":["../../src/combinators/not.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;AAGpF;;;;;;;;;GASG;AACH,wBAAgB,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,CAmBjE"}
1
+ {"version":3,"file":"not.d.ts","sourceRoot":"","sources":["../../src/combinators/not.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;AAGpF;;;;;;;;;GASG;AACH,wBAAgB,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,CAmBrE"}
@@ -1,7 +1,7 @@
1
1
  import type { Combinator, ParseError } from '../types.ts';
2
2
  export type { ParseError };
3
3
  /**
4
- * Error-recovery combinator. Tries `parser`; on success returns normally.
4
+ * Error-recovery combinator. Tries `combinator`; on success returns normally.
5
5
  * On failure, scans forward one character at a time until `sentinel` matches
6
6
  * (or EOF), then returns a ParseError node spanning the skipped range.
7
7
  * The sentinel is NOT consumed — the caller's grammar continues from there.
@@ -15,6 +15,6 @@ export type { ParseError };
15
15
  * recover(exprStmt, literal(';'))
16
16
  * )
17
17
  */
18
- export declare function recover<T>(parser: Combinator<T>, sentinel: Combinator<unknown>): Combinator<T | ParseError>;
18
+ export declare function recover<T>(combinator: Combinator<T>, sentinel: Combinator<unknown>): Combinator<T | ParseError>;
19
19
  export declare function isParseError(value: unknown): value is ParseError;
20
20
  //# sourceMappingURL=recover.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"recover.d.ts","sourceRoot":"","sources":["../../src/combinators/recover.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,UAAU,EAAE,MAAM,aAAa,CAAA;AAEhG,YAAY,EAAE,UAAU,EAAE,CAAA;AAE1B;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,OAAO,CAAC,CAAC,EACvB,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EACrB,QAAQ,EAAE,UAAU,CAAC,OAAO,CAAC,GAC5B,UAAU,CAAC,CAAC,GAAG,UAAU,CAAC,CA6B5B;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAEhE"}
1
+ {"version":3,"file":"recover.d.ts","sourceRoot":"","sources":["../../src/combinators/recover.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,UAAU,EAAE,MAAM,aAAa,CAAA;AAEhG,YAAY,EAAE,UAAU,EAAE,CAAA;AAE1B;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,OAAO,CAAC,CAAC,EACvB,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EACzB,QAAQ,EAAE,UAAU,CAAC,OAAO,CAAC,GAC5B,UAAU,CAAC,CAAC,GAAG,UAAU,CAAC,CA6B5B;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAEhE"}
@@ -1 +1 @@
1
- {"version":3,"file":"regex.d.ts","sourceRoot":"","sources":["../../src/combinators/regex.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAmD,MAAM,aAAa,CAAA;AA4H9F,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,SAAK,GAAG,UAAU,CAAC,MAAM,CAAC,CA2B9E"}
1
+ {"version":3,"file":"regex.d.ts","sourceRoot":"","sources":["../../src/combinators/regex.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAmD,MAAM,aAAa,CAAA;AA6H9F,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,SAAK,GAAG,UAAU,CAAC,MAAM,CAAC,CA0B9E"}
@@ -1,6 +1,6 @@
1
1
  import type { Combinator } from '../types.ts';
2
- export declare function many<T>(parser: Combinator<T>): Combinator<T[]>;
3
- export declare function oneOrMore<T>(parser: Combinator<T>): Combinator<T[]>;
4
- export declare function optional<T>(parser: Combinator<T>): Combinator<T | null>;
5
- export declare function sepBy<T, S>(parser: Combinator<T>, separator: Combinator<S>): Combinator<T[]>;
2
+ export declare function many<T>(combinator: Combinator<T>): Combinator<T[]>;
3
+ export declare function oneOrMore<T>(combinator: Combinator<T>): Combinator<T[]>;
4
+ export declare function optional<T>(combinator: Combinator<T>): Combinator<T | null>;
5
+ export declare function sepBy<T, S>(combinator: Combinator<T>, separator: Combinator<S>): Combinator<T[]>;
6
6
  //# sourceMappingURL=repeat.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"repeat.d.ts","sourceRoot":"","sources":["../../src/combinators/repeat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;AA+CpF,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAuB9D;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CA2BnE;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,GAAG,IAAI,CAAC,CAiBvE;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CA6B5F"}
1
+ {"version":3,"file":"repeat.d.ts","sourceRoot":"","sources":["../../src/combinators/repeat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;AAkDpF,wBAAgB,IAAI,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAuBlE;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CA2BvE;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,GAAG,IAAI,CAAC,CAiB3E;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAuDhG"}
@@ -1 +1 @@
1
- {"version":3,"file":"scanTo.d.ts","sourceRoot":"","sources":["../../src/combinators/scanTo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;AAMpF,MAAM,MAAM,aAAa,GAAG;IAC1B,uGAAuG;IACvG,IAAI,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,CAAA;IAC5B;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CACpB,QAAQ,EAAE,UAAU,CAAC,OAAO,CAAC,EAC7B,EAAE,IAAS,EAAE,KAAa,EAAE,GAAE,aAAkB,GAC/C,UAAU,CAAC,MAAM,CAAC,CA+DpB;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,aAAkB,GAC1B,UAAU,CAAC,MAAM,CAAC,CAYpB"}
1
+ {"version":3,"file":"scanTo.d.ts","sourceRoot":"","sources":["../../src/combinators/scanTo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;AAOpF,MAAM,MAAM,aAAa,GAAG;IAC1B,uGAAuG;IACvG,IAAI,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,CAAA;IAC5B;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CACpB,QAAQ,EAAE,UAAU,CAAC,OAAO,CAAC,EAC7B,EAAE,IAAS,EAAE,KAAa,EAAE,GAAE,aAAkB,GAC/C,UAAU,CAAC,MAAM,CAAC,CA8DpB;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,aAAkB,GAC1B,UAAU,CAAC,MAAM,CAAC,CAYpB"}
@@ -1 +1 @@
1
- {"version":3,"file":"sequence.d.ts","sourceRoot":"","sources":["../../src/combinators/sequence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAoD,MAAM,aAAa,CAAA;AAI/F,KAAK,aAAa,CAAC,CAAC,SAAS,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI;KACnD,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CAC7D,CAAA;AAED,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,EAChF,GAAG,OAAO,EAAE,CAAC,GACZ,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAqD9B"}
1
+ {"version":3,"file":"sequence.d.ts","sourceRoot":"","sources":["../../src/combinators/sequence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAoD,MAAM,aAAa,CAAA;AAI/F,KAAK,aAAa,CAAC,CAAC,SAAS,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI;KACnD,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CAC7D,CAAA;AAED,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,EAChF,GAAG,OAAO,EAAE,CAAC,GACZ,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAuD9B"}
@@ -10,19 +10,25 @@ export type TriviaScan = {
10
10
  end: number;
11
11
  commit: () => void;
12
12
  };
13
+ /** Saved lengths for rolling back speculative trivia commits. */
14
+ export type TriviaRollbackMark = {
15
+ raw: number;
16
+ tlog: number;
17
+ leaves: number;
18
+ log: number;
19
+ };
20
+ /** True when trivia recording must be deferred until the following term commits. */
21
+ export declare function needsDeferredTriviaCommit(ctx: ParseContext): boolean;
22
+ export declare function saveTriviaMark(ctx: ParseContext): TriviaRollbackMark;
23
+ export declare function rollbackTrivia(ctx: ParseContext, mark: TriviaRollbackMark): void;
24
+ /**
25
+ * Skip trivia at `cur` and return the new position. No recording, no wrapper
26
+ * object — use between sequence/repeat terms when CST trivia capture is off.
27
+ */
28
+ export declare function advanceTrivia(input: string, cur: number, ctx: ParseContext): number;
13
29
  /**
14
30
  * Scan trivia at `cur` using `ctx.trivia`, WITHOUT recording it. Returns the
15
31
  * position after the trivia (or `cur` if none) and a `commit()` to record it.
16
- *
17
- * Recording is gated on `ctx.captureTrivia`:
18
- * - capture off (default): commit() is a no-op; trivia is skipped silently.
19
- * - capture on (and a rawChildren collector is active): commit() records each
20
- * maximal trivia sub-match (a whitespace run or a comment) as a separate
21
- * CSTTrivia token. Relies on the trivia parser being structured so each
22
- * token is a distinct leaf match.
23
- *
24
- * The trivia parser always runs with `trivia` unset in its sub-context so it
25
- * cannot recurse into itself.
26
32
  */
27
33
  export declare function scanTrivia(input: string, cur: number, ctx: ParseContext): TriviaScan;
28
34
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"trivia-skip.d.ts","sourceRoot":"","sources":["../../src/combinators/trivia-skip.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI/C;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,IAAI,CAAA;CAAE,CAAA;AAI5D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,GAAG,UAAU,CA0CpF;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,GAAG,MAAM,CAInF"}
1
+ {"version":3,"file":"trivia-skip.d.ts","sourceRoot":"","sources":["../../src/combinators/trivia-skip.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAc/C;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,IAAI,CAAA;CAAE,CAAA;AAE5D,iEAAiE;AACjE,MAAM,MAAM,kBAAkB,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAA;AAI3F,oFAAoF;AACpF,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAEpE;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,YAAY,GAAG,kBAAkB,CAGpE;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,kBAAkB,GAAG,IAAI,CAGhF;AAiBD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,GAAG,MAAM,CASnF;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,GAAG,UAAU,CA6BpF;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,GAAG,MAAM,CAKnF"}
@@ -1,6 +1,6 @@
1
1
  import type { Combinator } from '../types.ts';
2
2
  /**
3
- * Runs `parser` with `ctx.state` set to `extra` for the duration of the parse.
3
+ * Runs `combinator` with `ctx.state` set to `extra` for the duration of the parse.
4
4
  * The outer user context is restored on exit (lexical scoping).
5
5
  *
6
6
  * const functionBody = withCtx({ inFn: true },
@@ -9,5 +9,5 @@ import type { Combinator } from '../types.ts';
9
9
  *
10
10
  * Read back with guard() or from within a transform's span argument.
11
11
  */
12
- export declare function withCtx<U, T>(extra: U, parser: Combinator<T>): Combinator<T>;
12
+ export declare function withCtx<U, T>(extra: U, combinator: Combinator<T>): Combinator<T>;
13
13
  //# sourceMappingURL=withCtx.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"withCtx.d.ts","sourceRoot":"","sources":["../../src/combinators/withCtx.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;AAEpF;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAc5E"}
1
+ {"version":3,"file":"withCtx.d.ts","sourceRoot":"","sources":["../../src/combinators/withCtx.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;AAEpF;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAchF"}
@@ -6,9 +6,11 @@
6
6
  * `break <label>` rather than an IIFE return — no function call, no result
7
7
  * object allocation per node.
8
8
  */
9
- import type { Combinator, ParseResult, ParseError } from '../types.ts';
9
+ import type { Combinator, ParseResult, ParseContext, ParseError } from '../types.ts';
10
10
  export type CompiledParser<T> = {
11
11
  parse(input: string, pos?: number): ParseResult<T>;
12
+ /** Like parse(), but with a caller-supplied ParseContext (e.g. `_triviaLog` for CST grammars). */
13
+ parseWithContext(input: string, ctx: ParseContext, pos?: number): ParseResult<T>;
12
14
  /**
13
15
  * Like parse(), but activates error recovery. recover() nodes collect their
14
16
  * ParseErrors into result.errors instead of (only) embedding them as values.
@@ -28,5 +30,5 @@ export type CompiledParser<T> = {
28
30
  */
29
31
  inlineExpression: string | null;
30
32
  };
31
- export declare function compile<T>(parser: Combinator<T>, mapFnSources?: string[]): CompiledParser<T>;
33
+ export declare function compile<T>(combinator: Combinator<T>, mapFnSources?: string[]): CompiledParser<T>;
32
34
  //# sourceMappingURL=codegen.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../../src/compiler/codegen.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,UAAU,EAAuB,WAAW,EAAgB,UAAU,EAAkB,MAAM,aAAa,CAAA;AA6lCzH,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI;IAC9B,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;IAClD;;;;OAIG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAA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M,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC,CAgGhG"}
@@ -0,0 +1,11 @@
1
+ import type { ParserDef } from '../types.ts';
2
+ /**
3
+ * When a node() build is a thin `mk(type, …)` wrapper, emit the object literal
4
+ * at the call site instead of `_build[n](…)`.
5
+ */
6
+ export declare function analyzeMkInlineBuild(def: Extract<ParserDef, {
7
+ tag: 'node';
8
+ }>): string | null;
9
+ /** Object literal matching `stub-build.ts` `mk()` without the function call. */
10
+ export declare function emitInlineMkNodeExpr(type: string, chV: string, rawV: string, pos: string, endVar: string, tlV: string): string;
11
+ //# sourceMappingURL=inline-build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline-build.d.ts","sourceRoot":"","sources":["../../src/compiler/inline-build.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAiB5C;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,CAAC,SAAS,EAAE;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,MAAM,GAAG,IAAI,CAS5F;AAED,gFAAgF;AAChF,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,GACV,MAAM,CAER"}
@@ -0,0 +1,12 @@
1
+ /** Source text for a transform callback — macro `fnSrc` or arrow `toString()`. */
2
+ export declare function transformFnSource(fn: Function, fnSrc?: string | null): string | null;
3
+ /** `s => expr` / `() => expr` when expr only uses the param (+ builtins). */
4
+ export declare function tryInlineUnaryTransform(src: string, valueVar: string): string | null;
5
+ /** Parse `[a, , c]` destructuring slots (null = ignore). */
6
+ export declare function parseArrayDestructure(pattern: string, arity: number): (string | null)[];
7
+ /**
8
+ * `([x, y]) => body` — substitute destructure names with sequence value vars.
9
+ * Caller must ensure body only references slotted params (+ builtins).
10
+ */
11
+ export declare function tryInlineDestructureTransform(src: string, valueVars: string[]): string | null;
12
+ //# sourceMappingURL=inline-callback.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline-callback.d.ts","sourceRoot":"","sources":["../../src/compiler/inline-callback.ts"],"names":[],"mappings":"AAUA,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"}
@@ -0,0 +1,24 @@
1
+ import type { Combinator } from '../types.ts';
2
+ import type { LabeledTriviaSpec } from '../cst/trivia-kinds.ts';
3
+ export type TriviaFastKind = 'wsComments' | 'wsOnly';
4
+ /**
5
+ * Detect trivia shapes safe to lower to a hand-rolled scan loop in compiled output.
6
+ * Matches CSS `rw` (`oneOrMore(choice(ws, blockComment))`) and ASCII ws-only grammars.
7
+ * Single alternation regexes are excluded — one regex exec matches only one arm per call.
8
+ */
9
+ export declare function analyzeTriviaFastPath(trivia: Combinator<unknown>): TriviaFastKind | null;
10
+ /** Emit a specialized `_tfN` that skips trivia without regex / combinator dispatch. */
11
+ export declare function buildFastTriviaFnDecl(fnName: string, kind: TriviaFastKind, kindIndices?: {
12
+ ws: number;
13
+ comment: number;
14
+ }): string;
15
+ /** Labeled trivia with regex arms — per-chunk kind capture in compiled output. */
16
+ export declare function buildLabeledRegexTriviaFnDecl(fnName: string, spec: LabeledTriviaSpec, reNames: string[]): string;
17
+ export declare function labeledTriviaKindIndices(trivia: Combinator<unknown>): {
18
+ ws: number;
19
+ comment: number;
20
+ } | null;
21
+ export declare function labeledTriviaRegexArms(trivia: Combinator<unknown>): LabeledTriviaSpec | null;
22
+ /** Labeled trivia via per-arm runtime parsers (non-regex or mixed arms). */
23
+ export declare function buildLabeledRuntimeTriviaFnDecl(fnName: string, spec: LabeledTriviaSpec, rpStartIndex: number): string;
24
+ //# sourceMappingURL=trivia-fast-path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trivia-fast-path.d.ts","sourceRoot":"","sources":["../../src/compiler/trivia-fast-path.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAG/D,MAAM,MAAM,cAAc,GAAG,YAAY,GAAG,QAAQ,CAAA;AAsCpD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,cAAc,GAAG,IAAI,CA6BxF;AAmED,uFAAuF;AACvF,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,cAAc,EACpB,WAAW,CAAC,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC5C,MAAM,CAeR;AAYD,kFAAkF;AAClF,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,iBAAiB,EACvB,OAAO,EAAE,MAAM,EAAE,GAChB,MAAM,CA+BR;AAED,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAO5G;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,iBAAiB,GAAG,IAAI,CAO5F;AAED,4EAA4E;AAC5E,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,iBAAiB,EACvB,YAAY,EAAE,MAAM,GACnB,MAAM,CA8BR"}
@@ -0,0 +1,46 @@
1
+ import type { ParseContext } from '../types.ts';
2
+ /** Lazy per-node capture state — arrays materialized on first push. */
3
+ export type CstCaptureBuf = {
4
+ single?: unknown | undefined;
5
+ ch?: unknown[] | undefined;
6
+ rawSingle?: unknown | undefined;
7
+ raw?: unknown[] | undefined;
8
+ tl?: number[] | undefined;
9
+ };
10
+ export declare function cstCaptureActive(ctx: ParseContext): boolean;
11
+ export type CstNodeCaptureSaved = {
12
+ ch: ParseContext['_cstChildren'];
13
+ lv: ParseContext['_cstLeaves'];
14
+ raw: ParseContext['_cstRawChildren'];
15
+ tl: ParseContext['_cstTriviaLog'];
16
+ cap: boolean | undefined;
17
+ buf: CstCaptureBuf | undefined;
18
+ };
19
+ export declare function beginCstNodeCapture(ctx: ParseContext): CstNodeCaptureSaved;
20
+ export declare function finishCstBuf(buf: CstCaptureBuf | undefined): {
21
+ children: unknown[];
22
+ rawChildren: unknown[];
23
+ triviaLog: number[];
24
+ };
25
+ export declare function endCstNodeCapture(ctx: ParseContext, saved: CstNodeCaptureSaved): {
26
+ children: unknown[];
27
+ rawChildren: unknown[];
28
+ triviaLog: number[];
29
+ };
30
+ export declare function pushCstLeaf(ctx: ParseContext, leaf: unknown): void;
31
+ /** Record a built sub-node into the active collector (children vs rawChildren may differ). */
32
+ export declare function pushCstChild(ctx: ParseContext, built: unknown, rawEntry: unknown): void;
33
+ export declare function cstRawLen(ctx: ParseContext): number;
34
+ export declare function cstLeavesLen(ctx: ParseContext): number;
35
+ export declare function cstTlLen(ctx: ParseContext): number;
36
+ export type CstRollbackMark = {
37
+ raw: number;
38
+ tlog: number;
39
+ leaves: number;
40
+ };
41
+ export declare function saveCstMark(ctx: ParseContext): CstRollbackMark;
42
+ export declare function rollbackCstCapture(ctx: ParseContext, mark: CstRollbackMark): void;
43
+ export declare function pushCstTriviaEntry(ctx: ParseContext, start: number, end: number, kindIndex?: number): void;
44
+ export declare function pushTriviaLogEntry(ctx: ParseContext, start: number, end: number, kindIndex?: number): void;
45
+ export declare function cstDeferredTriviaActive(ctx: ParseContext): boolean;
46
+ //# sourceMappingURL=capture-buffer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capture-buffer.d.ts","sourceRoot":"","sources":["../../src/cst/capture-buffer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,uEAAuE;AACvE,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IAC5B,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,SAAS,CAAA;IAC1B,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IAC/B,GAAG,CAAC,EAAE,OAAO,EAAE,GAAG,SAAS,CAAA;IAC3B,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;CAC1B,CAAA;AAKD,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAE3D;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE,YAAY,CAAC,cAAc,CAAC,CAAA;IAChC,EAAE,EAAE,YAAY,CAAC,YAAY,CAAC,CAAA;IAC9B,GAAG,EAAE,YAAY,CAAC,iBAAiB,CAAC,CAAA;IACpC,EAAE,EAAE,YAAY,CAAC,eAAe,CAAC,CAAA;IACjC,GAAG,EAAE,OAAO,GAAG,SAAS,CAAA;IACxB,GAAG,EAAE,aAAa,GAAG,SAAS,CAAA;CAC/B,CAAA;AAED,wBAAgB,mBAAmB,CA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,MAAM,GACjB,IAAI,CAkBN;AAED,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,SAAS,CAAC,EAAE,MAAM,GACjB,IAAI,CAON;AAED,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAElE"}
@@ -0,0 +1,20 @@
1
+ /** View over a flat trivia log (`_triviaLog` or per-node `triviaLog`). */
2
+ export type TriviaEntriesView = {
3
+ readonly length: number;
4
+ readonly labels: readonly string[] | undefined;
5
+ readonly stride: number;
6
+ start(i: number): number;
7
+ end(i: number): number;
8
+ kindIndex(i: number): number | undefined;
9
+ kind(i: number): string | undefined;
10
+ text(i: number, input: string): string;
11
+ };
12
+ /**
13
+ * Wrap a flat trivia log. Stride is inferred from `labels`:
14
+ * - root `_triviaLog`: 2 (start, end) or 3 (+ kindIndex)
15
+ * - node `triviaLog`: 3 (start, end, insertIdx) or 4 (+ kindIndex)
16
+ */
17
+ export declare function triviaEntries(log: readonly number[], labels?: readonly string[], opts?: {
18
+ nodeLog?: boolean;
19
+ }): TriviaEntriesView;
20
+ //# sourceMappingURL=trivia-entries.d.ts.map
@@ -0,0 +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,CA6BnB"}
@@ -5,13 +5,14 @@ export type TriviaToken = {
5
5
  readonly span: Span;
6
6
  };
7
7
  /**
8
- * Before/after offset index of captured trivia. Built from a tree's rawChildren
9
- * (trivia is only present there when the grammar enables `_captureTrivia`).
8
+ * Before/after offset index of captured trivia. Built from a tree whose nodes
9
+ * carry a `triviaLog` property (the flat `[start, end, insertIdx, ...]` array
10
+ * produced by parseman when `parser({ captureTrivia: true })` wraps a `node()` grammar).
10
11
  *
11
12
  * index.before.get(node.span.start) // trivia immediately before a node
12
13
  * index.after.get(node.span.end) // trivia immediately after a node
13
14
  *
14
- * A given trivia run is registered under BOTH the following item's start
15
+ * A given trivia entry is registered under BOTH the following item's start
15
16
  * (`before`) and the preceding item's end (`after`), so either lookup finds it.
16
17
  */
17
18
  export type TriviaIndex = {
@@ -22,12 +23,10 @@ export type TriviaIndex = {
22
23
  * Options for trailing/leading trivia at the document boundary. A repeating root
23
24
  * (e.g. `many()`) rolls back the trivia after its last item — it's "trailing" and
24
25
  * belongs to the enclosing context, which at the document root is the document
25
- * itself. Pass `{ input, trivia }` to re-scan and register that boundary trivia,
26
+ * itself. Pass `{ trivia }` to re-scan and register that boundary trivia,
26
27
  * so a round-trippable trivia map isn't missing the run before EOF.
27
28
  */
28
29
  export type TriviaIndexOptions = {
29
- /** The full source string. */
30
- input: string;
31
30
  /**
32
31
  * A regex matching ONE trivia token (a whitespace run or a comment). Applied
33
32
  * repeatedly to tokenize the boundary trivia. Each match becomes one token, so
@@ -37,14 +36,15 @@ export type TriviaIndexOptions = {
37
36
  trivia: RegExp;
38
37
  };
39
38
  /**
40
- * Walk a CST/AST node tree (anything exposing `children` whose items carry
41
- * `_tag`/`span`, with trivia items tagged `'trivia'`) and build a before/after
42
- * trivia index. Generic over the node type — formatters, LSPs, and codemods all
43
- * need this, and Parseman already owns trivia capture.
39
+ * Walk a tree whose nodes carry `triviaLog` (from `node()` + `captureTrivia`)
40
+ * and build a before/after trivia index. Each node must have
41
+ * `triviaLog: readonly number[]` (flat `[start, end, insertIdx, …]` —
42
+ * three numbers per entry) and `rawChildren` (structural items with `.span`).
43
+ * `input` is the source string used to materialize trivia values.
44
44
  *
45
45
  * With `opts`, also captures leading trivia (before the root's content) and
46
46
  * trailing trivia (after it, up to EOF) — the document boundaries a repeating
47
47
  * root rolls back.
48
48
  */
49
- export declare function buildTriviaIndex(root: unknown, opts?: TriviaIndexOptions): TriviaIndex;
49
+ export declare function buildTriviaIndex(root: unknown, input?: string, opts?: TriviaIndexOptions): TriviaIndex;
50
50
  //# sourceMappingURL=trivia-index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"trivia-index.d.ts","sourceRoot":"","sources":["../../src/cst/trivia-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAEvC,sFAAsF;AACtF,MAAM,MAAM,WAAW,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAAA;AAEzE;;;;;;;;;GASG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,CAAA;IAC3C,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,CAAA;CAC3C,CAAA;AAiBD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