Expand description
Sheet-qualified reference rewriting — how =Sheet2!A1 evaluates without
the evaluator knowing sheets exist.
formula-lang’s grammar has no ! (a qualified reference is not even
tokenizable), and its formula_lang::CellResolver resolves bare
(col, row) pairs in one namespace. Re-implementing the evaluator to
add a sheet dimension would abandon every Excel-compatible function, so
the engine instead rewrites each qualified reference into a stub:
=Sheet2!A1 + B2 becomes =A1048577 + B2 (stub shown illustratively)
└ recorded: stub → (Sheet2, A1)A stub is a plain in-grid cell reference guaranteed to collide with no
real reference of the same formula: stub linear coordinates start one
past the highest linear coordinate the formula’s local references
(B2 above) reach. The mapping is kept per formula in Prepared;
the engine’s resolver translates stub reads back to their real
(sheet, row, col) targets during evaluation. The original text is
never altered in the sheet — rewriting happens only in the evaluation
path, so XLSX round-trips carry the formula exactly as written.
The scanner is deliberately lenient in the same spirit as
sheet_core::refs: string literals, error literals (#REF! contains a
!), and function names (LOG10() are skipped; anything unrecognized
is copied through verbatim, which lets formula_lang::parse produce
its typed error for genuinely malformed input. The scanner itself
cannot fail.