vimsheet.formula.evaluator

Formula evaluator — walks the AST and resolves values.

exception vimsheet.formula.evaluator.EvalError(sentinel)[source]

Bases: Exception

Internal error raised during evaluation; converted to a sentinel string.

Parameters:

sentinel (str)

Return type:

None

__init__(sentinel)[source]
Parameters:

sentinel (str)

Return type:

None

class vimsheet.formula.evaluator.Evaluator(sheet, workbook=None)[source]

Bases: object

Evaluate a formula AST in the context of a Sheet.

Usage:

ev = Evaluator(sheet)
result = ev.eval_formula("=SUM(A1:A5)")
Parameters:
  • sheet (Sheet)

  • workbook (Any | None)

__init__(sheet, workbook=None)[source]
Parameters:
  • sheet (Sheet)

  • workbook (Any | None)

Return type:

None

eval_formula(formula, row=0, col=0)[source]

Parse and evaluate formula (must start with ‘=’).

Returns the computed value, or an error sentinel string on failure.

Parameters:
Return type:

Any

collect_deps(formula)[source]

Return the set of (row, col) cells referenced by formula.

Parameters:

formula (str)

Return type:

set[tuple[int, int]]

vimsheet.formula.evaluator.recalculate(sheet, graph)[source]

Recalculate all formula cells in sheet using graph for ordering.

Updates each cell’s value and display in topological order. Cells in a cycle receive #CIRC.

Parameters:
Return type:

None