import type { Combinator, ParseContext, ParseResult } from '../types.ts'; export type ParseOptions = { trackLines?: boolean; /** * Enable the error-collection channel. When true, recovery points (expect(), and * tolerant list recovery) collect their ParseErrors into a side-channel array * rather than only embedding them in the value tree. The returned ParseOk will * have an `errors` field listing all recovered errors. Top-level parse failures * (where nothing recovered) still return ParseFail as usual. */ recover?: boolean; }; export type ParserOptions = ParseOptions & { /** * Trivia parser for this scope. Three states: * - a Combinator → skip this trivia between sequence/repeat terms * - `undefined` → inherit the enclosing scope's trivia (no change) * - `null` → CLEAR trivia: no trivia skipped, so terms must be contiguous. * Re-enable inside a nested region with another parser({ trivia }). */ trivia?: Combinator | null; /** * Declare that this local trivia scope intentionally does not preserve * selected root categories. Required only by * `rootTrivia: { select }` when the scope does not use * `classifiedTrivia()`. */ rootCapture?: 'opaque'; /** Record consumed trivia as CSTTrivia tokens in rawChildren. Default: skip. */ captureTrivia?: boolean; /** * Restrict PER-NODE CST trivia capture to these trivia kinds (label names from * the trivia's `label()` arms). Whitespace and any other unlisted kind is still * skipped over but NOT recorded into a node's `triviaLog` — so a host that only * consumes (say) comments pays nothing to log every whitespace run. The global * trivia log is unaffected. Requires labeled trivia; ignored otherwise. */ captureTriviaKinds?: readonly string[]; }; export interface ParsemanParser extends Combinator { parse(input: string): ParseResult; parse(input: string, pos: number, ctx: ParseContext): ParseResult; } /** * A trivia scope. * * ── NO RULE MAY CONSULT AN OPTION WHILE IT PARSES ─────────────────────────── * * `opts` is fixed when `parser(opts, root)` is called. That is LINK TIME — the * same moment `assemble.ts` resolves `RunCfg` into a choice of piece, and the * same rule (`RunCfg`'s header, `scripts/check-invariants.mjs` INV-6/INV-7). * Everything below used to be read INSIDE `parse`, which a nested scope enters * on every visit, so a grammar with a `parser({ trivia })` region paid nine * option reads per entry for answers that could not change. * * They are now resolved once, here, and the parse path reads only the resolved * values. Where the answer genuinely depends on the CALLER's context — an * inherited `trackLines`, inherited trivia labels — a pre-written variant is * SELECTED at link time rather than branched on per entry. Selecting costs one * closure per scope in the grammar; branching cost one test per entry per parse. * * `_ctx.trivia`, `_ctx.captureTrivia` and the CST sinks stay where they are: * those are per-scope RUNTIME state that `node()` opens and closes mid-parse, * not configuration. Resolving them early would be wrong, not fast. */ export declare function parser(opts: ParserOptions, root: Combinator): ParsemanParser; /** * Run `root` with the active trivia cleared — no trivia is skipped between its * sequence/repeat terms, so they must be contiguous in the input. (Trivia is * whatever parser({ trivia }) installed — often whitespace/comments, but it is * grammar-defined.) The inverse of parser({ trivia }); re-enable trivia in a * nested region with another parser({ trivia }). * * Wrap the WHOLE contiguous run: an enclosing sequence skips trivia *before* a * term runs, so wrapping just the inner part would let leading trivia through. * * For a static glued token just use one literal/regex; reach for noTrivia when a * glued part is a structured sub-rule — e.g. a head glued to a `[subscript]` * whose interior still allows trivia. Turn trivia back on for a region by nesting * another parser({ trivia }) (innermost wins, reverts on exit); put the WHOLE * spaced region — including its leading `[` — inside it, since sequence skips * trivia only between terms, not before its first: * * // `arr[i + 1]` — `arr` touches `[`, but the subscript is a spaced expr: * noTrivia(sequence(name, * parser({ trivia: ws }, sequence(literal('['), expr, literal(']'))))) */ export declare function noTrivia(root: Combinator): ParsemanParser; export declare function parse(combinator: Combinator, input: string, opts?: ParseOptions): ParseResult; //# sourceMappingURL=grammar.d.ts.map