feat(formula): one AST for both spreadsheet formula syntaxes - #884
Open
andiwand wants to merge 1 commit into
Open
feat(formula): one AST for both spreadsheet formula syntaxes#884andiwand wants to merge 1 commit into
andiwand wants to merge 1 commit into
Conversation
`internal/formula` parses what a `table:formula` and an `<f>` state into one tree. The two syntaxes share their expression grammar, so one recursive descent takes a `Syntax` and branches where they part: the reference (`[Sheet1.A1:.B2]` against `Sheet1!A1:B2`), the argument separator and the row separator of an array. References, ranges, sheet-qualified references and named expressions are read; nothing resolves a name or evaluates anything. A formula that does not parse answers nothing, so a caller reads no reference out of one it cannot read. A spelling past the grid is a name rather than a position, which is also what `A0` and `ABCDEFGHI1` are. Step 3.1 of `docs/design/spreadsheet-editing.md`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VVmjmddv2Ui17Nptc1ggue
This was referenced Sep 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 Generated with Claude Code
Step 3.1 of
docs/design/spreadsheet-editing.md— the read side of formulas. First of four; the dependency graph, the view and the.odscached value follow on top of this.What it does
src/odr/internal/formulaparses what atable:formulaand an<f>state into one AST. The two syntaxes share their expression grammar — the same operators at the same precedence — and differ over three things, so one recursive descent takes aSyntaxand branches where they part:[$'My Sheet'.$A$1:.B2]'My Sheet'!$A$1:B2;,|;Read: cell references, ranges, whole columns (
A:A), the$of each axis, sheet-qualified and external references, named expressions, functions, arrays, errors, and the operators. A named expression and a reference over several sheets (Sheet1:Sheet3!A1) stay the spelling the file states — nothing resolves one.Nothing evaluates anything: that is step 4.
Two decisions worth a look
A0(rows are 1-based) andABCDEFGHI1(past what an index holds) are names, not refused parses — which is what a sheet calls them too, and a name carries no dependency.Test
41 cases in
test/src/internal/formula/formula_parser_test.cpp, inline strings only. They pin the precedence a sheet has (-2^2is 4,-3%is -0.03), theLOG10(ambiguity against the referenceLOG10, and each dialect's own spellings.