import type { Combinator, ParseContext } from '../types.ts'; export type TriviaChunk = { start: number; end: number; kindIndex: number; }; export type LabeledTriviaSpec = { readonly labels: readonly string[]; readonly arms: ReadonlyArray<{ label: string; kindIndex: number; parser: Combinator; }>; readonly minRepeats: number; }; /** Strip `label()` wrapper; returns inner parser for matching. */ export declare function peelLabel(p: Combinator): { label: string; parser: Combinator; } | null; /** * When every trivia arm is `label(name, parser)` inside `oneOrMore(choice(…))` * (or a single labeled arm), return the label table and matchers. */ export declare function analyzeLabeledTrivia(trivia: Combinator): LabeledTriviaSpec | null; /** Label table on a `trivia()` combinator, if all arms are labeled. */ export declare function triviaKindLabels(trivia: Combinator | undefined): readonly string[] | undefined; /** * Scan maximal labeled trivia chunks (PEG `oneOrMore(choice(…))` semantics). * Each successful arm match becomes one entry with that arm's kind index. */ export declare function scanLabeledTriviaChunks(input: string, cur: number, spec: LabeledTriviaSpec, state?: unknown): { end: number; chunks: TriviaChunk[]; }; /** * Scan labeled trivia when no caller will retain individual chunks. This is the * ordinary skip path for a classified grammar: labels remain available for an * explicit capture request, but merely having labels must not allocate one * `{ start, end, kindIndex }` object per whitespace/comment run. */ export declare function scanLabeledTriviaEnd(input: string, cur: number, spec: LabeledTriviaSpec, state?: unknown): number; /** * Visit classified trivia matches without constructing per-match objects. The * visitor is only invoked after one or more arms matched, which is the shape * used by `classifiedTrivia()`; callers with a stronger repeat minimum keep * the buffered scanner so an unsuccessful minimum cannot leak a partial run. */ export declare function visitLabeledTrivia(input: string, cur: number, spec: LabeledTriviaSpec, state: unknown | undefined, visit: (start: number, end: number, kindIndex: number) => void): number | undefined; export declare function recordTriviaChunks(ctx: ParseContext, chunks: readonly TriviaChunk[]): void; /** * Resolve a per-node trivia capture mask (`ctx._triviaCaptureMask`) from a trivia * label table and the kind names a host wants to keep. Returns `undefined` when * `labels` is absent (nothing to key on → capture everything). * * Names in `keep` that aren't in `labels` are **ignored by design**: `keep` is * often a dialect-independent list (e.g. `['blockComment', 'lineComment']`) applied * to a grammar whose trivia only defines some of them (CSS has no `lineComment`) — * so an unknown name is a normal cross-dialect no-op, not necessarily a typo, and * is not worth a warning that would cry wolf on legitimate superset lists. An empty * `keep` (or one where nothing matches) yields `0`, which means "capture NO trivia * into per-node logs" — an intentional, valid state (the global `_triviaLog` is * unaffected either way). If you expect comments and get an empty per-node log, * check the name against the grammar's `triviaKindLabels`. */ /** * Resolve an ADJACENCY kind filter against the ACTIVE trivia table — the strict * counterpart of `triviaKindMask` below. * * Deliberately NOT lenient. `triviaKindMask` is a capture preference, where an * unknown name is a legitimate cross-dialect no-op; this is a RECOGNITION * constraint, and a silently-dropped name turns `notAdjacent({kinds:['whitespace']})` * into a bare `notAdjacent()` — i.e. `calc()` quietly accepting a comment where * css-values-4 10.1 demands real whitespace, the exact defect the filter exists to * prevent. Both failure modes are hard errors. */ export declare function resolveAdjacencyKindMask(trivia: Combinator | undefined, kinds: readonly string[]): number; /** * Bitmask of the trivia CATEGORIES occurring in the run starting at `pos` * (`1 << kindIndex` per matched chunk); `0` when no trivia is there at all. * The single source of truth for the interpreter's adjacency kind test — the * compiled probe (`_akN`) mirrors this loop arm for arm. */ export declare function triviaKindMaskAt(input: string, pos: number, spec: LabeledTriviaSpec, state?: unknown): number; export declare function triviaKindMask(labels: readonly string[] | undefined, keep: readonly string[]): number | undefined; //# sourceMappingURL=trivia-kinds.d.ts.map