/** * The tree-walking evaluator: given a parsed {@link AstNode} and an * {@link EvalContext}, it produces a single {@link FormulaValue}. It is the * runtime heart of Phase 3 — operators, references, ranges and function calls * all resolve here. * * ### Design * - **Never throws.** Every user-facing error condition becomes a * {@link FormulaError} value that propagates like any other value, so a bad * cell renders `#DIV/0!` instead of crashing a recalculation pass. * - **Matrix-aware.** Range references evaluate to a {@link FormulaMatrix}; * function arguments receive that matrix intact (so `SUM(A1:A9)` works), while * scalar positions (operator operands, the cell's final result) collapse a * 1×1 matrix to its cell and reject larger matrices with `#VALUE!`. * - **Error short-circuiting.** Binary/unary operators return the first error * operand unchanged; functions decide their own strictness. * * The evaluator is stateless between calls; a single shared instance is reused * across the whole grid. * * @packageDocumentation */ import { AstNode } from '../parser/ast.types'; import type { EvalContext } from '../types/eval-context'; import type { FormulaValue } from '../types/formula.types'; export declare class Evaluator { /** * Evaluates `node` to a single scalar value, collapsing an incidental 1×1 * matrix and rejecting wider matrices used in scalar position. * * @param node - The AST to evaluate. * @param ctx - The evaluation context. * @returns The scalar result (possibly a {@link FormulaError}). */ evaluate(node: AstNode, ctx: EvalContext): FormulaValue; /** * Evaluates `node` to an argument value — a scalar, or a {@link FormulaMatrix} * when the node is a range reference. This is what function arguments receive. * * @param node - The AST to evaluate. * @param ctx - The evaluation context. */ private evalArg; /** Collapses a 1×1 matrix to its cell; wider matrices are `#VALUE!`. */ private toScalar; /** * Resolves a bare name. A named range/cell wins first (backward compatible); * otherwise the name is treated as a **row-relative** reference — a column by * data `field` or spreadsheet letter, read from the current row. Yields * `#NAME?` only when it is neither. */ private evalName; private evalUnary; private evalBinary; private arithmetic; private comparison; private evalFunction; private describeArity; } /** A process-wide shared evaluator (stateless, safe to reuse). */ export declare const sharedEvaluator: Evaluator; //# sourceMappingURL=evaluator.d.ts.map