The offset of the first token within the text (formulaPrefixLen — a stripped =).
OptionalisFragment: (fragment: string) => boolean
Whether a run of text compiles as a standalone expression. Supplied by the host (it owns the calc engine); rule 2 is skipped entirely without it.
What a text selection in a formula resolves to — the eval tip's target, and F9's.
Three rules, in order, because no single one is right:
Exactly a subtree → evaluate it in place (
evalIndex). The common case: selectingSUM(A1:A5)inside=SUM(A1:A5)*2.A whole-token run that parses on its own → evaluate that TEXT as its own expression. The subtree rule alone is not enough, because an operator chain is left-nested:
=1+1+1+1is(((1+1)+1)+1), so the middle1+1is not any node — its two operands live in different subtrees. Rule 1 would widen to1+1+1and answer 3 for a selection that plainly reads as 2. Excel's F9 works this way throughout (it evaluates the selected text, not a node), and this is where that shows.Whole-token alignment is what keeps this honest:
1*2inside=A1*2parses, but it starts mid-token (A1), so it never reaches this rule and can't invent a value out of a coincidence.Otherwise → snap OUTWARD to the smallest evaluable segment containing the selection. A drag that lands mid-token (
UM(A1:A5in=SUM(A1:A5)*2) still answers — forSUM(A1:A5)— and the host's outline shows that it widened. Requiring a clean selection instead would leave the tip silent most of the time a human made the selection by hand.nullwhen the selection touches nothing evaluable (whitespace only, an unparsed tail, or a selection past the tokens).