/** * Formula engine: tokenizer -> Pratt parser -> AST -> evaluator. * Deliberately no `eval` / `new Function` — see ARCHITECTURE.md §3.3 and §6. * Supports: numbers, cell refs (A1), ranges (A1:B3), + - * / ^, parens, * comparisons (= <> < <= > >=), and a small function table (SUM, AVG, MIN, * MAX, COUNT, IF, ROUND, CONCAT). */ import { Sheet } from './model.js'; export type FormulaValue = number | string | boolean | FormulaError; export declare class FormulaError { code: '#REF!' | '#DIV/0!' | '#CIRC!' | '#NAME?' | '#VALUE!' | '#ERROR!'; constructor(code: '#REF!' | '#DIV/0!' | '#CIRC!' | '#NAME?' | '#VALUE!' | '#ERROR!'); toString(): "#REF!" | "#DIV/0!" | "#CIRC!" | "#NAME?" | "#VALUE!" | "#ERROR!"; } export type Node = { kind: 'num'; value: number; } | { kind: 'str'; value: string; } | { kind: 'ref'; value: string; } | { kind: 'range'; from: string; to: string; } | { kind: 'call'; name: string; args: Node[]; } | { kind: 'binop'; op: string; left: Node; right: Node; } | { kind: 'unary'; op: string; arg: Node; }; export declare function parseFormula(formula: string): Node; export declare function parseCellRef(ref: string): { row: number; col: number; }; export declare function cellRefName(row: number, col: number): string; /** Cells a formula depends on — used to build the recalculation dependency graph. */ export declare function extractDependencies(node: Node): string[]; export interface CellResolver { resolve(ref: string): FormulaValue; } export declare function evaluate(node: Node, resolver: CellResolver): FormulaValue; /** Build a resolver bound to a specific sheet, with a visiting-set for cycle detection. */ export declare function makeSheetResolver(sheet: Sheet, visiting?: Set): CellResolver;