parseman 0.13.0 → 0.14.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.
Files changed (39) hide show
  1. package/dist/combinators/expect.d.ts.map +1 -1
  2. package/dist/combinators/node.d.ts +1 -1
  3. package/dist/combinators/node.d.ts.map +1 -1
  4. package/dist/combinators/parser.d.ts.map +1 -1
  5. package/dist/combinators/regex-analyze.d.ts +6 -0
  6. package/dist/combinators/regex-analyze.d.ts.map +1 -0
  7. package/dist/combinators/regex.d.ts +16 -1
  8. package/dist/combinators/regex.d.ts.map +1 -1
  9. package/dist/compiler/build-arity.d.ts.map +1 -1
  10. package/dist/compiler/codegen.d.ts +45 -0
  11. package/dist/compiler/codegen.d.ts.map +1 -1
  12. package/dist/compiler/inline-build.d.ts.map +1 -1
  13. package/dist/compiler/linker.d.ts +44 -0
  14. package/dist/compiler/linker.d.ts.map +1 -0
  15. package/dist/compiler/scannable-run.d.ts.map +1 -1
  16. package/dist/cst/offset-model.d.ts +119 -0
  17. package/dist/cst/offset-model.d.ts.map +1 -0
  18. package/dist/cst/relative-spans.d.ts +56 -0
  19. package/dist/cst/relative-spans.d.ts.map +1 -0
  20. package/dist/functional/doc.d.ts +20 -0
  21. package/dist/functional/doc.d.ts.map +1 -1
  22. package/dist/functional/run.d.ts +63 -0
  23. package/dist/functional/run.d.ts.map +1 -0
  24. package/dist/index.cjs +907 -112
  25. package/dist/index.cjs.map +4 -4
  26. package/dist/index.d.ts +9 -1
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +907 -112
  29. package/dist/index.js.map +4 -4
  30. package/dist/plugin/evaluator.d.ts +2 -28
  31. package/dist/plugin/evaluator.d.ts.map +1 -1
  32. package/dist/plugin/index.cjs +710 -250
  33. package/dist/plugin/index.cjs.map +4 -4
  34. package/dist/plugin/index.d.ts.map +1 -1
  35. package/dist/plugin/index.js +710 -250
  36. package/dist/plugin/index.js.map +4 -4
  37. package/dist/types.d.ts +12 -3
  38. package/dist/types.d.ts.map +1 -1
  39. package/package.json +3 -1
@@ -1 +1 @@
1
- {"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../src/combinators/expect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,UAAU,EAAE,MAAM,aAAa,CAAA;AAEhG,YAAY,EAAE,UAAU,EAAE,CAAA;AAE1B;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,MAAM,EAAE,CAoB/D;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC,GAAG,UAAU,CAAC,CAmB/F"}
1
+ {"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../src/combinators/expect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,UAAU,EAAE,MAAM,aAAa,CAAA;AAEhG,YAAY,EAAE,UAAU,EAAE,CAAA;AAE1B;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,MAAM,EAAE,CA2B/D;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC,GAAG,UAAU,CAAC,CAmB/F"}
@@ -33,5 +33,5 @@ export type BuildNode<N> = (children: ReadonlyArray<unknown>, rawChildren: Reado
33
33
  export type NodeOptions = {
34
34
  collapse?: boolean;
35
35
  };
36
- export declare function node<N>(type: string, combinator: Combinator<unknown>, build: BuildNode<N>, opts?: NodeOptions): Combinator<N>;
36
+ export declare function node<N>(type: string, combinator: Combinator<unknown>, build?: BuildNode<N>, opts?: NodeOptions): Combinator<N>;
37
37
  //# 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,EAAoD,MAAM,aAAa,CAAA;AAI/F;;;;;;;;;;;;;;;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;;;;;;;;;;GAUG;AACH,MAAM,MAAM,WAAW,GAAG;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAA;AAShD,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,CA8C7H"}
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/combinators/node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAoD,MAAM,aAAa,CAAA;AAI/F;;;;;;;;;;;;;;;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;;;;;;;;;;GAUG;AACH,MAAM,MAAM,WAAW,GAAG;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAA;AAShD,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,CAmD9H"}
@@ -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;AAG7C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,EACjE,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,GACxB,CAAC,CAmCH"}
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/combinators/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAG7C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,EACjE,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,GACxB,CAAC,CAwCH"}
@@ -0,0 +1,6 @@
1
+ import type { FirstSet } from '../types.ts';
2
+ export declare function firstSetFromRegex(pattern: string): {
3
+ firstSet: FirstSet;
4
+ canMatchNewline: boolean;
5
+ };
6
+ //# sourceMappingURL=regex-analyze.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regex-analyze.d.ts","sourceRoot":"","sources":["../../src/combinators/regex-analyze.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAG3C,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,eAAe,EAAE,OAAO,CAAA;CAAE,CAOnG"}
@@ -1,3 +1,18 @@
1
- import type { Combinator } from '../types.ts';
1
+ import type { Combinator, FirstSet } from '../types.ts';
2
+ /**
3
+ * Computes a regex terminal's first-set (for choice-dispatch fast paths). The
4
+ * only implementation — `firstSetFromRegex` in `./regex-analyze.ts` — is backed
5
+ * by `regexp-tree` (~264 KB) and is registered by the interpreter/library entry
6
+ * (`index.ts`) via `registerRegexAnalyzer`. It is injected rather than imported
7
+ * so that consumers who ship only compiled grammars (or import `regex` directly
8
+ * from this subpath) never pull `regexp-tree` into their bundle. When no
9
+ * analyzer is registered, `regex()` uses the permissive `PERMISSIVE_FIRST_SET`
10
+ * below — this only disables the dispatch fast paths, never changing matches.
11
+ */
12
+ export type RegexFirstSetAnalyzer = (pattern: string) => {
13
+ firstSet: FirstSet;
14
+ canMatchNewline: boolean;
15
+ };
16
+ export declare function registerRegexAnalyzer(analyzer: RegexFirstSetAnalyzer): void;
2
17
  export declare function regex(pattern: string | RegExp, flags?: string): Combinator<string>;
3
18
  //# sourceMappingURL=regex.d.ts.map
@@ -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;AA6H9F,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,SAAK,GAAG,UAAU,CAAC,MAAM,CAAC,CA0B9E"}
1
+ {"version":3,"file":"regex.d.ts","sourceRoot":"","sources":["../../src/combinators/regex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,QAAQ,EAAE,MAAM,aAAa,CAAA;AAK9F;;;;;;;;;GASG;AACH,MAAM,MAAM,qBAAqB,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,eAAe,EAAE,OAAO,CAAA;CAAE,CAAA;AAIzG,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,qBAAqB,GAAG,IAAI,CAE3E;AAQD,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,SAAK,GAAG,UAAU,CAAC,MAAM,CAAC,CAyB9E"}
@@ -1 +1 @@
1
- {"version":3,"file":"build-arity.d.ts","sourceRoot":"","sources":["../../src/compiler/build-arity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE5C;;;;;;;;;;GAUG;AAEH,KAAK,OAAO,GAAG,OAAO,CAAC,SAAS,EAAE;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAkBlD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAuB9D;AAED,sFAAsF;AACtF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAKtD;AAED,sFAAsF;AACtF,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAKrD"}
1
+ {"version":3,"file":"build-arity.d.ts","sourceRoot":"","sources":["../../src/compiler/build-arity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE5C;;;;;;;;;;GAUG;AAEH,KAAK,OAAO,GAAG,OAAO,CAAC,SAAS,EAAE;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAkBlD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAuB9D;AAED,sFAAsF;AACtF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAMtD;AAED,sFAAsF;AACtF,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAMrD"}
@@ -31,6 +31,15 @@ export type CompiledParser<T> = {
31
31
  */
32
32
  inlineExpression: string | null;
33
33
  };
34
+ /**
35
+ * Dependency manifest for the linkable form: for each rule in the map, the set
36
+ * of OTHER rule names its body references (by name). A referenced rule is a
37
+ * boundary — we record the edge and do NOT descend into it (its own deps are its
38
+ * own entry). Used by the linker for à la carte dep-closure selection and the
39
+ * compose-time name-closure check (every referenced name must resolve in the
40
+ * final set). Self-references are included (a recursive rule depends on itself).
41
+ */
42
+ export declare function ruleDependencies(ruleMap: ReadonlyArray<readonly [string, Combinator<unknown>]>): Map<string, string[]>;
34
43
  /**
35
44
  * Compile a combinator tree into an optimized parse function at runtime.
36
45
  *
@@ -74,4 +83,40 @@ export declare function compileRuleMap(ruleMap: ReadonlyArray<readonly [string,
74
83
  keys: string[];
75
84
  replacement: string;
76
85
  } | null;
86
+ /**
87
+ * The linkable form of a rule map (RULE_ABI_PLAN §3): the same compiled rule
88
+ * bodies as `compileRuleMap`, but returned as **splice-able pieces** under a
89
+ * namespace `ns` so multiple independently-compiled maps fuse into one scope
90
+ * (see `fuseRules`). `ns` MUST be non-empty and unique per artifact (the caller
91
+ * derives it — module identity in the macro, a counter in `compile()`).
92
+ *
93
+ * prelude — namespaced hoisted decls (regexes, expected, `_mf`/`_build`, and
94
+ * private `_pf` helper fns). Sentinels / `_EMPTY_TL` / `_collator`
95
+ * are NOT here — they are SHARED, emitted once by the linker.
96
+ * ruleFns — name → `function _r_<Name>(…) { … }` source (the composition
97
+ * surface; siblings call these by name).
98
+ * wrappers — name → public `(input,pos,ctx) => ParseResult` wrapper source.
99
+ * deps — name → referenced rule names (from `ruleDependencies`).
100
+ *
101
+ * Returns null on the same "can't inline" conditions as `compileRuleMap`.
102
+ */
103
+ export type LinkablePieces = {
104
+ ns: string;
105
+ keys: string[];
106
+ prelude: string[];
107
+ ruleFns: Map<string, string>;
108
+ wrappers: Map<string, string>;
109
+ deps: Map<string, string[]>;
110
+ needsEmptyTl: boolean;
111
+ needsCollator: boolean;
112
+ /**
113
+ * Transform (`_mf`) / build (`_build`) callback FUNCTIONS, injected into the
114
+ * fused scope via `_env` when their SOURCE isn't available (runtime `compile()`
115
+ * mode). Empty when the callbacks were inlined from source (macro mode). Keyed
116
+ * for `_env` as `<ns>mf` / `<ns>build`.
117
+ */
118
+ mfFns: ReadonlyArray<(...args: unknown[]) => unknown>;
119
+ buildFns: ReadonlyArray<(...args: unknown[]) => unknown>;
120
+ };
121
+ export declare function compileLinkable(ruleMapArg: ReadonlyArray<readonly [string, Combinator<unknown>]>, ns: string): LinkablePieces | null;
77
122
  //# 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,EAAE,YAAY,EAAE,UAAU,EAAkB,MAAM,aAAa,CAAA;AAqbzH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,OAAO,GAAG,IAAI,CAA0B;AAohDjF,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI;IAC9B,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;IAClD,kGAAkG;IAClG,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;IAChF;;;;OAIG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,EAA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,OAAO,CAAA;IACrB,aAAa,EAAE,OAAO,CAAA;IACtB;;;;;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,CAwJvB"}
@@ -1 +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"}
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,CAU5F;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,44 @@
1
+ import type { LinkablePieces } from './codegen.ts';
2
+ import type { Combinator } from '../types.ts';
3
+ export declare function linkable(rulesMap: Record<string, Combinator<unknown>>, ns?: string): LinkablePieces;
4
+ /**
5
+ * A generic positioned-CST build host (RULE_ABI_PLAN §7). Pass as `ctx.build`
6
+ * (or `parseDoc(..., { build: cstBuildHost })`) to make ANY linkable/fused
7
+ * grammar produce a uniform CST — `{ _tag:'node', type, span, state, children }`
8
+ * — instead of its own eval-AST builders. This is the host the linter and IDE
9
+ * drivers use; the eval driver leaves `ctx.build` unset (grammar's own builders).
10
+ */
11
+ export declare function cstBuildHost(type: string, children: ReadonlyArray<unknown>, _rawChildren: ReadonlyArray<unknown>, span: {
12
+ start: number;
13
+ end: number;
14
+ }, _triviaLog?: readonly number[], state?: unknown): unknown;
15
+ export type FusedRule = (input: string, pos: number, ctx: Record<string, unknown>) => {
16
+ ok: boolean;
17
+ value?: unknown;
18
+ span: {
19
+ start: number;
20
+ end: number;
21
+ };
22
+ };
23
+ /**
24
+ * Restrict a grammar/artifact to `names` plus their transitive rule-dependency
25
+ * closure (à la carte selection) — e.g. Jess taking parts of Less and parts of
26
+ * Sass: `compose([pick(less, ['MixinCall']), pick(sass, ['EachFor']), css])`. A
27
+ * picked rule pulls in every rule name it references, so the result is always
28
+ * self-consistent within the artifact. Accepts a grammar (`rules()` result) or a
29
+ * compiled artifact; returns an artifact for `compose()`.
30
+ */
31
+ export declare function pick(grammar: LinkablePieces | Record<string, Combinator<unknown>>, names: string[]): LinkablePieces;
32
+ /** Fuse at RUNTIME (via `new Function`) — used by `compose()` when not compiled
33
+ * by the macro (like `compile()`). The macro path uses `emitFusedSource` instead. */
34
+ export declare function fuseRules(pieces: LinkablePieces[]): Record<string, FusedRule>;
35
+ /**
36
+ * Fuse at BUILD time — emit the fused closure as a self-contained SOURCE
37
+ * expression (`(() => { … })()`), with **no `new Function`**. This is what the
38
+ * macro splices in for a `compose([...])` call, so macro output stays eval-free.
39
+ * Requires every callback to be inlined from source (macro mode); throws if any
40
+ * artifact carries runtime-only callback functions.
41
+ */
42
+ export declare function emitFusedSource(pieces: LinkablePieces[]): string;
43
+ export declare function compose(items: Array<LinkablePieces | Record<string, unknown>>): Record<string, FusedRule>;
44
+ //# sourceMappingURL=linker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linker.d.ts","sourceRoot":"","sources":["../../src/compiler/linker.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAa7C,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,EAC7C,EAAE,CAAC,EAAE,MAAM,GACV,cAAc,CAIhB;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,aAAa,CAAC,OAAO,CAAC,EAChC,YAAY,EAAE,aAAa,CAAC,OAAO,CAAC,EACpC,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EACpC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,EAC9B,KAAK,CAAC,EAAE,OAAO,GACd,OAAO,CAIT;AAED,MAAM,MAAM,SAAS,GAAG,CACtB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KACzB;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,IA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,cAAc,CAC5B,KAAK,EAAE,OAAO,CAAC,SAAS,EAAE;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC,GAC5C,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAIzB;AAED,sEAAsE;AACtE,MAAM,MAAM,IAAI,GAAG,CAAC,MAAM,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;AAE9C;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,UAAU,GAAG;IAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAA;AAKrE,wBAAgB,cAAc,CAC5B,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,IAAI,EACV,GAAG,EAAE,MAAM,EACX,SAAS,CAAC,EAAE,MAAM,GACjB,UAAU,CA6PZ;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,GAAG,MAAM,CAG/D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,MAAM,CAazF"}
@@ -0,0 +1,119 @@
1
+ import type { Span } from '../types.ts';
2
+ /**
3
+ * Trivia-offset-inference model.
4
+ *
5
+ * The premise (see docs): most trivia carries nothing that isn't already implied
6
+ * by the source offsets of the tokens around it. A gap between a slot ending at
7
+ * 100 and the next starting at 103 IS three characters of trivia — known without
8
+ * storing anything. So we store only the slot boundaries (which the tree already
9
+ * has) and reconstruct trivia from them:
10
+ *
11
+ * - exact printing: slice the source between two slots (`gapText`);
12
+ * - inference: widths / indents / alignment / blank-lines are subtraction;
13
+ * - positional queries: binary search over the sorted slot array (O(log n)),
14
+ * collapsing the old double-indexed before/after maps into one index.
15
+ *
16
+ * A "slot" is a leaf token's source span. Trivia lives in the GAPS between
17
+ * consecutive slots (plus the leading gap before the first slot and the trailing
18
+ * gap after the last). Gaps are fully determined by the sorted slot list, so
19
+ * there is no separate trivia store for whitespace at all.
20
+ */
21
+ /** A leaf token's source span — the anchor points; trivia is between them. */
22
+ export type Slot = {
23
+ readonly start: number;
24
+ readonly end: number;
25
+ };
26
+ /** A trivia region between two slots (or a document boundary). Half-open `[start, end)`. */
27
+ export type Gap = {
28
+ readonly start: number;
29
+ readonly end: number;
30
+ };
31
+ /**
32
+ * A positional index over an ordered set of slots (leaf spans) within a source
33
+ * of length `docEnd`. Answers "what trivia is before/after/around this offset"
34
+ * by binary search, and reconstructs the exact trivia text by slicing `source`.
35
+ *
36
+ * Slots must be non-overlapping. They are sorted by `start` on construction;
37
+ * out-of-order or overlapping input throws (the caller's spans are wrong).
38
+ */
39
+ export declare class OffsetIndex {
40
+ /** Slot starts, sorted ascending. Parallel to `_ends`. */
41
+ private readonly _starts;
42
+ private readonly _ends;
43
+ readonly count: number;
44
+ readonly docStart: number;
45
+ readonly docEnd: number;
46
+ constructor(slots: readonly Slot[], docStart?: number, docEnd?: number);
47
+ /** The slot at index `i` (0-based, source order), or undefined. */
48
+ slot(i: number): Slot | undefined;
49
+ /**
50
+ * Index of the gap that CONTAINS `offset`, in `[0, count]`. Gap `i` spans
51
+ * `[endOf(i-1), startOf(i))` where `endOf(-1)=docStart` and `startOf(count)=docEnd`.
52
+ * An offset that lands inside a slot returns that slot's TRAILING gap index
53
+ * (i.e. the gap after it) — callers querying at slot boundaries get the
54
+ * intuitive answer via `gapBefore`/`gapAfter`.
55
+ */
56
+ gapIndexAt(offset: number): number;
57
+ /** The gap at index `i` in `[0, count]`. */
58
+ gap(i: number): Gap | undefined;
59
+ /**
60
+ * The trivia gap immediately BEFORE `offset` (`[prevSlotEnd, offset)`), where
61
+ * `prevSlotEnd` is the end of the last slot ending at or before `offset` (or
62
+ * `docStart`). For a real slot start this is the gap preceding that slot; for an
63
+ * adjacent slot the gap is empty and agrees with `gapAfter` on the same seam.
64
+ */
65
+ gapBefore(offset: number): Gap | undefined;
66
+ /**
67
+ * The trivia gap immediately AFTER `offset` (`[offset, nextSlotStart)`), where
68
+ * `nextSlotStart` is the least slot start at or after `offset` (or `docEnd`).
69
+ */
70
+ gapAfter(offset: number): Gap | undefined;
71
+ /** Least slot start `>= offset`, else `docEnd`. */
72
+ private _ceilStart;
73
+ /** Is this gap empty (adjacent slots, no trivia)? */
74
+ isEmpty(gap: Gap): boolean;
75
+ }
76
+ /** Exact trivia text of a gap: `source.slice(gap.start, gap.end)`. */
77
+ export declare function gapText(source: string, gap: Gap): string;
78
+ /** Count of line breaks (`\n`, with `\r\n` counted once) within a gap. */
79
+ export declare function lineBreaksIn(source: string, gap: Gap): number;
80
+ /** Blank lines in a gap = breaks - 1 (a single break is just a line end, not a blank line). */
81
+ export declare function blankLinesIn(source: string, gap: Gap): number;
82
+ /**
83
+ * Offset just after the last line break in the gap (the start of the final
84
+ * line's indent), or `gap.start` if the gap has no break. This is the ONE
85
+ * non-inferable position; every indent quantity derives from it by subtraction.
86
+ */
87
+ export declare function lineStartWithin(source: string, gap: Gap): number;
88
+ /**
89
+ * Indent width of the line the NEXT slot sits on: `nextStart - lineStart`.
90
+ * `nextStart` is `gap.end` (the following slot's start). Zero if the gap has no
91
+ * line break (the next slot is on the same line).
92
+ */
93
+ export declare function indentWidth(source: string, gap: Gap): number;
94
+ /** True if the final line's indent mixes tabs and spaces (the one case width can't capture). */
95
+ export declare function indentMixed(source: string, gap: Gap): boolean;
96
+ /** Comment spans within a gap (absolute offsets), tokenized by `comment`. */
97
+ export declare function commentsIn(source: string, gap: Gap, comment: RegExp): Span[];
98
+ /**
99
+ * Does the gap carry anything a normalizing printer must preserve? True if it
100
+ * contains a comment or a line break; a pure inline-whitespace gap returns false
101
+ * and needs no record at all (the printer re-derives canonical spacing).
102
+ */
103
+ export declare function gapIsSignificant(source: string, gap: Gap, comment?: RegExp): boolean;
104
+ /**
105
+ * Collect the leaf-token spans of a CST in source order. Nodes/errors (which
106
+ * carry `children`) are descended into; only childless spanned items (terminals)
107
+ * become slots. Node spans are skipped — they overlap their children and would
108
+ * double-cover the gaps.
109
+ */
110
+ export declare function collectLeafSlots(root: unknown): Slot[];
111
+ /**
112
+ * Build an `OffsetIndex` directly from a parseman CST root and its source. This
113
+ * is the drop-in replacement for the double-indexed `buildTriviaIndex`: the same
114
+ * before/after trivia is recovered by `gapBefore`/`gapAfter` + `gapText`, and it
115
+ * additionally supports arbitrary positional queries and inference — with nothing
116
+ * stored per whitespace gap.
117
+ */
118
+ export declare function buildOffsetIndex(root: unknown, input?: string): OffsetIndex;
119
+ //# sourceMappingURL=offset-model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"offset-model.d.ts","sourceRoot":"","sources":["../../src/cst/offset-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAEvC;;;;;;;;;;;;;;;;;;GAkBG;AAEH,8EAA8E;AAC9E,MAAM,MAAM,IAAI,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAA;AAEnE,4FAA4F;AAC5F,MAAM,MAAM,GAAG,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAA;AAqBlE;;;;;;;GAOG;AACH,qBAAa,WAAW;IACtB,0DAA0D;IAC1D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAU;IAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IAEvB,YAAY,KAAK,EAAE,SAAS,IAAI,EAAE,EAAE,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AE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,EAAE,CAW5E;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAKpF;AAcD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,EAAE,CAYtD;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,SAAK,GAAG,WAAW,CAEvE"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Relative span model for incremental edits.
3
+ *
4
+ * Absolute source offsets are simple but fragile: an insertion at offset `at`
5
+ * shifts EVERY downstream offset, so a whole-tree renumber is O(nodes-after-edit).
6
+ * Storing each node's span RELATIVE to its parent's start makes edits local: an
7
+ * insertion inside child k of a node only changes
8
+ * (a) child k's relative end,
9
+ * (b) the relative start of siblings after k,
10
+ * and leaves the *children* of those shifted siblings untouched — they move with
11
+ * their parent for free. So the mutation count is O(depth + trailing siblings),
12
+ * not O(all following nodes), and every unaffected subtree is shared by identity.
13
+ *
14
+ * An absolute view is recovered on query by accumulating the parent base as you
15
+ * descend (the `absolutize` / `absoluteSpanAt` cursor) — one source of truth,
16
+ * two manifestations.
17
+ */
18
+ /** A node with an ABSOLUTE source span and ordered children. */
19
+ export type AbsNode = {
20
+ readonly start: number;
21
+ readonly end: number;
22
+ readonly children: readonly AbsNode[];
23
+ };
24
+ /** A node whose `start`/`end` are RELATIVE to its parent's start (root base = 0). */
25
+ export type RelNode = {
26
+ readonly start: number;
27
+ readonly end: number;
28
+ readonly children: readonly RelNode[];
29
+ };
30
+ /** Convert an absolute tree to parent-relative spans. */
31
+ export declare function relativize(node: AbsNode, parentBase?: number): RelNode;
32
+ /** Reconstruct absolute spans from a relative tree. Inverse of `relativize`. */
33
+ export declare function absolutize(node: RelNode, parentBase?: number): AbsNode;
34
+ /**
35
+ * Absolute span of the node at `path` (child indices from the root), accumulating
36
+ * the base as it descends — O(path length), no full absolutize. The relative-form
37
+ * cursor: query any node's absolute position without materializing the whole tree.
38
+ */
39
+ export declare function absoluteSpanAt(root: RelNode, path: readonly number[]): {
40
+ start: number;
41
+ end: number;
42
+ };
43
+ /** Naive absolute reshift (baseline): shift every offset >= `at` by `delta`. */
44
+ export declare function shiftAbsolute(node: AbsNode, at: number, delta: number): AbsNode;
45
+ /**
46
+ * Apply an edit of `delta` characters at absolute offset `at` to a RELATIVE tree.
47
+ * Returns a new relative tree; every subtree that ends at/before `at` (in absolute
48
+ * terms) is returned by IDENTITY (unchanged), so the result structurally shares
49
+ * all unaffected subtrees with the input.
50
+ *
51
+ * `stats.allocated` counts nodes that had to be re-created — the incremental cost.
52
+ */
53
+ export declare function applyEdit(root: RelNode, at: number, delta: number, stats?: {
54
+ allocated: number;
55
+ }): RelNode;
56
+ //# sourceMappingURL=relative-spans.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relative-spans.d.ts","sourceRoot":"","sources":["../../src/cst/relative-spans.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,gEAAgE;AAChE,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAA;CACtC,CAAA;AAED,qFAAqF;AACrF,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAA;CACtC,CAAA;AAED,yDAAyD;AACzD,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,SAAI,GAAG,OAAO,CAMjE;AAED,gFAAgF;AAChF,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,SAAI,GAAG,OAAO,CAOjE;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAUrG;AAED,gFAAgF;AAChF,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAQ/E;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,OAAO,EACb,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,EACb,KAAK,CAAC,EAAE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GAC5B,OAAO,CAGT"}
@@ -16,6 +16,13 @@ export type ParseDocOptions<N extends NodeLike> = {
16
16
  * works for plain-object nodes; class-instance ASTs should supply their own.
17
17
  */
18
18
  rebuild?: (node: N, children: ReadonlyArray<N | CSTLeaf | CSTError>) => N;
19
+ /**
20
+ * Mode host for a linkable/fused grammar (RULE_ABI_PLAN §7): threaded into
21
+ * `ctx.build` on every (re)parse so `node()` rules build a positioned CST /
22
+ * language-service tree instead of their own eval-AST. Unset → the grammar's
23
+ * own builders (eval mode).
24
+ */
25
+ build?: ParseContext['build'];
19
26
  };
20
27
  export interface ParseDoc<N extends NodeLike> {
21
28
  readonly tree: N | null;
@@ -24,9 +31,22 @@ export interface ParseDoc<N extends NodeLike> {
24
31
  /**
25
32
  * Incrementally re-parse after a text change. `from`/`to` are byte offsets in
26
33
  * the OLD input; `replacement` fills that range (editor change-event shape).
34
+ * Sound: the result tree is always structurally identical to a fresh
35
+ * `parseDoc` of the edited text (the Stage-2 guard falls back to a full
36
+ * reparse whenever reuse can't be proven safe). Reuse/strategy is intentionally
37
+ * NOT reported here — an observer derives it by diffing this tree against the
38
+ * previous one (see the incremental tests); the runtime's job is to be fast,
39
+ * not to measure itself.
27
40
  */
28
41
  edit(from: number, to: number, replacement: string): ParseDoc<N>;
29
42
  }
43
+ /**
44
+ * Deep structural equality on parse trees: `_tag`, `span`, node `type`, leaf
45
+ * `value`, and children pairwise. This is the oracle relation `.edit()` must
46
+ * preserve against a full reparse; it's also what the Stage-2 guard compares
47
+ * probe results with.
48
+ */
49
+ export declare function structurallyEqual(a: unknown, b: unknown): boolean;
30
50
  /**
31
51
  * Parse `input` from `rootRule` and wrap the result in a ParseDoc that can
32
52
  * be incrementally re-parsed via `.edit()`.
@@ -1 +1 @@
1
- {"version":3,"file":"doc.d.ts","sourceRoot":"","sources":["../../src/functional/doc.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACvE,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAElE,qFAAqF;AACrF,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,KAAK,WAAW,CAAC,CAAC,CAAC,CAAA;AAEzF,gFAAgF;AAChF,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;AAEnD,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,QAAQ,IAAI;IAChD,wEAAwE;IACxE,KAAK,CAAC,EAAE,OAAO,CAAA;IACf;;;;OAIG;IACH,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC,GAAG,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;CAC1E,CAAA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,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC,GAAG,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IACzE;;;;;OAKG;IACH,KAAK,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,CAAA;CAC9B,CAAA;AAED,MAAM,WAAW,QAAQ,CAAC,CAAC,SAAS,QAAQ;IAC1C,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,CAAA;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB;;;;;;;;;OASG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;CACjE;AA6GD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAsBjE;AAyID;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,QAAQ,EACzC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,eAAe,CAAC,CAAC,CAAM,GAC5B,QAAQ,CAAC,CAAC,CAAC,CASb"}
@@ -0,0 +1,63 @@
1
+ import type { Combinator, ParseContext, ParseError, ParseResult } from '../types.ts';
2
+ /**
3
+ * Run a compiled/interpreted grammar entry against an input and collect the raw
4
+ * outcome a tool needs to shape a parse result — WITHOUT the consumer having to
5
+ * hand-build a `ctx`, branch on function-vs-combinator, or scan for leftover
6
+ * input itself.
7
+ *
8
+ * A `compile()`/macro grammar hands you a map of bare parse FUNCTIONS; the
9
+ * interpreter hands you COMBINATORS. `run()` invokes either, threads the standard
10
+ * framework ctx (trivia log, recover/expect error sink, the `ctx.build` host,
11
+ * grammar state), and — given the grammar's trivia parser — reports where
12
+ * non-trivia input was left unconsumed. The consumer keeps only its own policy:
13
+ * how to shape the tree and how to turn diagnostics into its error type.
14
+ */
15
+ /** A compiled rule (macro/`compile()` output) OR an interpreter combinator. */
16
+ export type Runnable = ((input: string, pos: number, ctx: ParseContext) => ParseResult<unknown>) | Combinator<unknown>;
17
+ export type RunOptions = {
18
+ /** `ctx.build` host — makes structural `node()` rules build a CST / AST via the
19
+ * host instead of their own eval builders. Omit for a grammar's own builders. */
20
+ build?: ParseContext['build'];
21
+ /** Initial grammar state threaded into `ctx.state`. */
22
+ state?: unknown;
23
+ /**
24
+ * The grammar's trivia rule. A root rule consumes trivia BETWEEN terms but not
25
+ * after the last one, so trailing whitespace/comments would otherwise look like
26
+ * unparsed input. Given the trivia rule, `run` skips that tail before computing
27
+ * `unconsumedFrom` — so only real leftover is reported. Also encodes dialect
28
+ * differences for free: pass the CSS trivia and a trailing `//` counts as
29
+ * leftover; pass the Less trivia (which treats `//` as a line comment) and it
30
+ * doesn't. An UNTERMINATED comment (which the trivia rule won't match) surfaces
31
+ * at its start. Omit to require the parse to reach the exact end itself.
32
+ */
33
+ trivia?: Runnable;
34
+ };
35
+ export type RunResult = {
36
+ ok: boolean;
37
+ /** The entry's value on success; undefined on failure. */
38
+ value: unknown;
39
+ span: {
40
+ start: number;
41
+ end: number;
42
+ };
43
+ /** Expected-token set when the TOP-LEVEL parse failed (empty on success). */
44
+ expected: string[];
45
+ /** `recover()` / `expect()` diagnostics collected during the parse (in order). */
46
+ errors: ParseError[];
47
+ /**
48
+ * Flat trivia log for building a trivia map. Entry width depends on whether the
49
+ * grammar uses labeled trivia: 2 numbers per entry (`start, end`) for plain
50
+ * trivia, 3 numbers per entry (`start, end, kindIndex`) for labeled trivia
51
+ * (grammars with `label()` arms in their trivia choice). Use `buildTriviaIndex`
52
+ * / `triviaEntries` to consume it format-agnostically rather than iterating raw.
53
+ */
54
+ triviaLog: number[];
55
+ /** Offset where unparsed input begins — the first non-trivia character the parse
56
+ * left unconsumed (trailing trivia skipped when `trivia` is given), or null if
57
+ * the whole input was consumed. This is how you detect "the grammar stopped short,
58
+ * there's junk here". Only meaningful on success — a failed parse reports its own
59
+ * `span`/`expected`. */
60
+ unconsumedFrom: number | null;
61
+ };
62
+ export declare function run(entry: Runnable, input: string, options?: RunOptions): RunResult;
63
+ //# sourceMappingURL=run.d.ts.map
@@ -0,0 +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,EAAE,GAAG,EAAE,YAAY,KAAK,WAAW,CAAC,OAAO,CAAC,CAAC,GACzE,UAAU,CAAC,OAAO,CAAC,CAAA;AAEvB,MAAM,MAAM,UAAU,GAAG;IACvB;qFACiF;IACjF,KAAK,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,CAAA;IAC7B,uDAAuD;IACvD,KAAK,CAAC,EAAE,OAAO,CAAA;IACf;;;;;;;;;OASG;IACH,MAAM,CAAC,EAAE,QAAQ,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,EAAE,EAAE,OAAO,CAAA;IACX,0DAA0D;IAC1D,KAAK,EAAE,OAAO,CAAA;IACd,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;IACpC,6EAA6E;IAC7E,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,kFAAkF;IAClF,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,CAqCvF"}