JFLib

diagram_core/src/formula/eval.rs#

Source: lib/diagram_core/src/formula/eval.rs

eval -- evaluating a parsed formula for one cell of one sheet (FX-02, FX-03)

Ev holds what a formula needs while it runs: the document, the engine's run (results so far,
themes, text metrics, the effects an action collects), the sheet and cell it is evaluated
for, and the sheet whose cell holds the formula text.  The last two differ for inherited
formulas: a master shape's formula runs in the instance's context (Width is the instance's
Width), and its Sheet.N references name shapes of the master, which the instance has under
other IDs -- they are mapped to the instance's subshape with MasterShape = N.

Arithmetic works on internal units (the parser converted "10 mm"), so units need no work
here.  Errors propagate through operators and functions; IF, AND, OR and the like evaluate
only what they need.
  • enum Keep why a formula's value cannot be computed here (the stored value stays and the cell is marked)
    • Parse(super::parse::ParseError) -- the formula does not parse
    • Unknown(String) -- it calls a function the engine does not know (the first such name)
    • NotComputed(&'static str) -- it calls a function the engine knows but does not compute here (glue helpers, add-ons, macros, values that depend on the machine: fonts, random numbers)
    • Reference -- it names a section the engine does not know
    • Deep -- its inputs nest deeper than the engine follows at once

Source: docs/API.md in the JFLib repository.