/** * Parser State * Core state management and token navigation utilities */ import type { SourceLocation, SourceSpan, Token } from '../types.js'; import { ParseError } from '../types.js'; export interface ParserState { readonly tokens: Token[]; pos: number; /** Recovery mode: collect errors instead of throwing */ readonly recoveryMode: boolean; /** Errors collected during recovery mode parsing */ readonly errors: ParseError[]; /** Original source text (for error recovery) */ readonly source: string; /** Tracks recursive-descent depth for functions guarded by withRecursionDepth */ recursionDepth: number; } interface ParserStateOptions { /** Enable recovery mode for IDE/tooling scenarios */ recoveryMode?: boolean; /** Original source text (required for recovery mode) */ source?: string; } export declare function createParserState(tokens: Token[], options?: ParserStateOptions): ParserState; /** * Increment a recursion-depth counter, call fn(), decrement in finally. * Guards against depth counter leaks when fn() throws. Shared by any * recursive-descent entry point that must halt with RILL-P015 instead * of a raw RangeError on adversarial input. * @internal */ export declare function withRecursionDepth(counter: { recursionDepth: number; }, getLocation: () => SourceLocation, fn: () => T): T; /** @internal */ export declare function current(state: ParserState): Token; /** @internal */ export declare function previous(state: ParserState): Token; /** @internal */ export declare function peek(state: ParserState, offset?: number): Token; /** @internal */ export declare function isAtEnd(state: ParserState): boolean; /** @internal */ export declare function check(state: ParserState, ...types: string[]): boolean; /** @internal */ export declare function advance(state: ParserState): Token; /** @internal */ export declare function expect(state: ParserState, type: string, message: string, errorId?: string): Token; /** @internal */ export declare function reportError(state: ParserState, errorId: string, message: string, loc: SourceLocation): void; /** @internal */ export declare function skipNewlines(state: ParserState): void; /** * Skip newlines if the next non-newline token is the target type. * Uses peek-then-skip pattern: only consumes newlines if target found. * @internal */ export declare function skipNewlinesIfFollowedBy(state: ParserState, tokenType: string): boolean; /** @internal */ export declare function makeSpan(start: SourceLocation, end: SourceLocation): SourceSpan; export {};