import type { Span } from '../types.ts'; /** One captured trivia token (a whitespace run or a comment) with its source span. */ export type TriviaToken = { readonly value: string; readonly span: Span; }; /** * Before/after offset index of captured trivia. Built from a tree whose nodes * carry a `triviaLog` property (the flat `[start, end, insertIdx, ...]` array * produced by parseman when `parser({ captureTrivia: true })` wraps a `node()` grammar). * * index.before.get(node.span.start) // trivia immediately before a node * index.after.get(node.span.end) // trivia immediately after a node * * A given trivia entry is registered under BOTH the following item's start * (`before`) and the preceding item's end (`after`), so either lookup finds it. */ export type TriviaIndex = { readonly before: Map; readonly after: Map; }; /** * Options for trailing/leading trivia at the document boundary. A repeating root * (e.g. `many()`) rolls back the trivia after its last item — it's "trailing" and * belongs to the enclosing context, which at the document root is the document * itself. Pass `{ trivia }` to re-scan and register that boundary trivia, * so a round-trippable trivia map isn't missing the run before EOF. */ export type TriviaIndexOptions = { /** * A regex matching ONE trivia token (a whitespace run or a comment). Applied * repeatedly to tokenize the boundary trivia. Each match becomes one token, so * write it to match a maximal run, e.g. * `/[ \t\n\r\f]+|\/\*(?:[^*]|\*(?!\/))*\*\//`. */ trivia: RegExp; }; /** * Walk a tree whose nodes carry `triviaLog` (from `node()` + `captureTrivia`) * and build a before/after trivia index. Each node must have * `triviaLog: readonly number[]` (flat `[start, end, insertIdx, …]` — * three numbers per entry) and `rawChildren` (structural items with `.span`). * `input` is the source string used to materialize trivia values. * * With `opts`, also captures leading trivia (before the root's content) and * trailing trivia (after it, up to EOF) — the document boundaries a repeating * root rolls back. */ export declare function buildTriviaIndex(root: unknown, input?: string, opts?: TriviaIndexOptions): TriviaIndex; //# sourceMappingURL=trivia-index.d.ts.map