Ast:
    | { type: "num"; value: number }
    | { ref: CellRef; type: "cell" }
    | { from: CellRef; to: CellRef; type: "range" }
    | { left: Ast; op: BinOp; right: Ast; type: "binop" }
    | { op: "-"; operand: Ast; type: "unary" }
    | { args: Ast[]; name: string; type: "call" }

Discriminated AST union produced by the formula parser.

Variants:

  • num — numeric literal carrying its parsed value.
  • cell — single A1 reference resolved to a CellRef.
  • range — inclusive rectangular range from from to to.
  • binop — binary arithmetic with operator BinOp and left/right operands.
  • unary — unary minus applied to operand.
  • call — function invocation by name with positional args.

The tag field type is the discriminator. Every variant is a plain JSON object so the whole tree round-trips through JSON.stringify / JSON.parse without loss — the property test in test/ir-roundtrip.test.ts pins that contract.