/** * The formula parser: turns the tokenizer's flat {@link Token} stream into an * immutable {@link AstNode} tree with correct operator precedence. * * ### Precedence (lowest → highest), Excel-compatible * 1. comparison `=` `<>` `<` `<=` `>` `>=` * 2. concatenation `&` * 3. addition/subtraction `+` `-` * 4. multiplication/division `*` `/` * 5. unary prefix `+` `-` ← binds tighter than `^` (Excel quirk: `-2^2 = 4`) * 6. exponentiation `^` (right-associative) * 7. postfix percent `%` * 8. range `:` and grouping `( )` / references / literals (atoms) * * Implemented with precedence climbing for binary operators plus explicit * unary/postfix handling — no recursion-per-precedence-level table walking, so * the hot path stays shallow. Parsing never throws: a malformed formula yields a * `{ ast: null, error }` result the engine surfaces as `#ERROR!`. * * @packageDocumentation */ import { Token } from '../tokenizer/token.types'; import { AstNode } from './ast.types'; import type { ResolvedFormulaConfig } from '../config/formula-config'; /** Outcome of a parse: the root node, or a positioned error. */ export interface ParseResult { /** The parsed AST, or `null` when parsing failed. */ readonly ast: AstNode | null; /** Non-null on failure; carries a message and source offset. */ readonly error: { message: string; position: number; } | null; } export declare class Parser { private tokens; private pos; private config; /** * Parses a token stream into an AST. * * @param tokens - Tokens produced by the tokenizer (must end with `EOF`). * @param config - Resolved config (decimal separator for number literals). * @returns The AST or a positioned error. */ parse(tokens: Token[], config: ResolvedFormulaConfig): ParseResult; /** Precedence-climbing binary-operator parse. */ private parseExpression; /** Unary prefix `+`/`-`, then postfix `%`. */ private parseUnary; /** Applies any postfix `%` operators to an already-parsed node. */ private parsePostfix; /** Parses an atom, optionally combined with a `:` partner into a range. */ private parseRangeable; /** Parses a single atomic operand into an {@link Endpoint}. */ private parseEndpoint; /** Parses `NAME( arg, arg, ... )`. Assumes the identifier is current. */ private parseFunctionCall; private endpointToNode; /** Combines two endpoints around a `:` into a {@link RangeRef} node. */ private buildRange; private parseNumber; private errorFromLiteral; private peek; private peekAhead; private advance; private expect; private fail; } /** A process-wide shared parser (reset per call, safe to reuse single-threaded). */ export declare const sharedParser: Parser; //# sourceMappingURL=parser.d.ts.map