import type { Combinator, ParseContext, ParseFail } from '../types.ts'; /** * Result of scanning trivia: the position after it, plus a `commit()` that * records the matched trivia tokens into the active rawChildren collector. * Recording is deferred so callers that may reject the following item (e.g. * many()/oneOrMore() retries) can advance speculatively without recording * trivia that doesn't actually sit between two accepted items. */ export type TriviaScan = { end: number; commit: () => void; }; export type CompactTriviaScan = number | TriviaScan; /** Saved lengths for rolling back speculative trivia commits. */ export type TriviaRollbackMark = { raw: number; tlog: number; leaves: number; fields: number; errors: number; log: number; rootLog: number; }; export declare function triviaScanEnd(scan: CompactTriviaScan): number; export declare function commitTriviaScan(scan: CompactTriviaScan): number; export type FastTriviaScanner = (input: string, cur: number) => number; /** True when trivia recording must be deferred until the following term commits. */ export declare function needsDeferredTriviaCommit(ctx: ParseContext): boolean; /** True when speculative parsing can write anything `rollbackTrivia` restores. */ export declare function needsTriviaRollback(ctx: ParseContext): boolean; export declare function saveTriviaMark(ctx: ParseContext): TriviaRollbackMark; /** * Trivia rollback from SCALAR marks — the allocation-free twin of * `rollbackTrivia`. See `rollbackCstCaptureAt`; `saveTriviaMark` allocates twice * (this wrapper plus the CST mark it delegates to) and the table driver took one * per sequence term and per repetition item. */ export declare function rollbackTriviaAt(ctx: ParseContext, raw: number, tlog: number, leaves: number, fields: number | undefined, errors: number | undefined, log: number, rootLog: number): void; export declare function rollbackTrivia(ctx: ParseContext, mark: TriviaRollbackMark): void; /** * Remove only the trivia rows appended by an ambient scan, preserving rows a * successful zero-width child appended after that scan. * * A sequence cannot use `rollbackTriviaAt` for this case: its pre-scan mark also * precedes the child, so truncating to it erases the child's nodes, fields, * recovery errors, and trivia. The scan's contribution is instead the half-open * range between the pre-scan and post-scan lengths. Compact that range in place; * this is the cold zero-width-success path and allocates no replacement arrays. */ export declare function rollbackScannedTriviaAt(ctx: ParseContext, tlogStart: number, tlogEnd: number, logStart: number, logEnd: number, rootLogStart: number, rootLogEnd: number): void; /** * A ZERO-WIDTH LOOKAHEAD's mark: everything `saveTriviaMark` covers, plus the * completions probe's current best failure. * * `_probe` is a sink like any other — `failAt` (probe.ts) replaces * `ctx._probe.best` whenever a failure lands at or before the cursor — but it is * deliberately NOT part of `rollbackTrivia`, because most rollbacks must leave it * alone. A failed `choice` arm or `sequence` term SHOULD keep its contribution: * merging the expectations of alternatives that failed at the cursor is exactly * how `completionsAt` builds its set. * * A lookahead is the exception. `peek`/`not` consume nothing on EITHER outcome * and promise to leave no observable trace, so expectations raised INSIDE the * probe are not reachable from the enclosing grammar at the cursor: * `peek(sequence(literal('a'), literal('zzz')))` over `"ab"` offered `"zzz"` as * the ONLY completion, though no input can ever reach it there. */ export type LookaheadMark = TriviaRollbackMark & { probeBest: ParseFail | null; }; export declare function saveLookaheadMark(ctx: ParseContext): LookaheadMark; export declare function rollbackLookahead(ctx: ParseContext, mark: LookaheadMark): void; /** * Skip trivia at `cur` and return the new position. No recording, no wrapper * object — use between sequence/repeat terms when CST trivia capture is off. */ export declare function advanceTrivia(input: string, cur: number, ctx: ParseContext): number; /** * Scan trivia at `cur` using `ctx.trivia`, WITHOUT recording it. Returns the * position directly when a classified scan retained no rows; otherwise returns * that position with a deferred `commit()` that records the retained rows. * Use `triviaScanEnd()` / `commitTriviaScan()` rather than inspecting the shape. */ export declare function scanTriviaCompact(input: string, cur: number, ctx: ParseContext): CompactTriviaScan; /** Legacy object-shaped contract used by previously emitted assembly factories. */ export declare function scanTrivia(input: string, cur: number, ctx: ParseContext): TriviaScan; /** * Skip trivia at `cur` through an INSTALLED scanner, recording it immediately. * * The table drivers install a scanner only for UNLABELLED trivia with * `trackLines` off, and that is exactly the case where the deferred path's whole * commit is the single row `(cur, end)` — so there is nothing to defer, and the * `{ end, commit }` pair plus its closure that `scanTrivia(…).commit()` allocated * on EVERY sequence term of EVERY capturing grammar buy nothing. This is that * branch with the allocations removed, kept here so recording has one home. */ export declare function skipTriviaScanned(s: FastTriviaScanner, input: string, cur: number, ctx: ParseContext): number; /** * Consume trivia at `cur`, recording it immediately. For callers that always * accept the trivia between two committed terms (e.g. sequence/sepBy). */ export declare function consumeTrivia(input: string, cur: number, ctx: ParseContext): number; /** * End of the trivia run at `cur`, WITHOUT recording any of it. * * The read-only twin of `consumeTrivia`, for a zero-width ASSERTION that wants the * adjacency fact and must leave no trace: the deferred path returns a scan whose * `commit()` is simply never called, so nothing lands in any buffer and there is * nothing to roll back. The following term re-scans the same gap and owns the * commit/rewind decision exactly as if the assertion were not there. */ export declare function probeTriviaEnd(input: string, cur: number, ctx: ParseContext): number; /** * The specialised scanner for a trivia combinator, or null when its shape has no * lowering. Memoized on the combinator. * * EXPORTED because G5's leaf swap needs it at TABLE-BUILD time: the table driver * resolves the scanner once, per trivia entry, and installs the closure at scope * entry — where the generic path called this (a WeakMap lookup) plus a chain of * option branches on EVERY sequence term. */ export declare function fastTriviaScanner(trivia: Combinator): FastTriviaScanner | null; //# sourceMappingURL=trivia-skip.d.ts.map