• Parse a formula string into an Ast.

    The leading = is optional, so both parseFormula('=A1+1') and parseFormula('A1+1') succeed and produce equivalent ASTs.

    Parameters

    • text: string

      Raw formula source.

    Returns Ast

    The parsed AST.

    FormulaParseError on any syntactic failure.

    The implementation is a recursive-descent parser with the precedence spelled out in grammar.ts. No regular expression scans the entire input — each parse function consumes at most one structural element so the positional information attached to errors stays accurate.

    const ast = parseFormula('=SUM(A1:A3) + 2')
    // { type: 'binop', op: '+', left: { type: 'call', ... }, right: { type: 'num', value: 2 } }