SheetXL - v0.8.0-beta.9+sites.210.e2d420901
    Preparing search index...

    Interface FormulaToken

    Represents a portion of a formula for rendering typical in an editor.

    A token is plain data — no functions, no class instances — so a token array survives JSON.stringify and structuredClone, and can cross a worker or process boundary. What the parse knows about a token (its FormulaToken.context, the names in scope there, what an unfinished part may become) is carried on the token in that form, so every consumer reads the same answer.

    interface FormulaToken {
        context?: FormulaTokenContext;
        evalIndex?: number;
        referenceIndex?: number;
        refSide?: ReferenceSide;
        text?: string;
        type: string;
        value: any;
    }
    Index

    If the token is part of a a function this will be set. This will be the 'closest' function if nested.

    evalIndex?: number

    Allows for partial formula evaluation for tooltips or formula writing. Only available for tokens types that can be evaluated.

    To determine the 'token span' for the evaluation you can can tokens left and right until you reach a token that has a larger evalIndex or there are no more tokens.

    referenceIndex?: number

    The reference literal this token is part of, as an offset into ICalculation.IFormula.getReferences. Tokens sharing an index are one reference span — an editor colors them as one unit.

    • Carried by a cell (A1), the range operator joining two cells (: in A1:B2), a spill anchor (#), an error reference (#REF!), and every part of a structured reference (Sales[Col], brackets included).
    • Absent on a named reference (names stay uncolored, as in Excel), on a function that returns a reference (INDEX, OFFSET), and on an operator whose operands are not both cells (A1:INDEX(…), @A1).
    refSide?: ReferenceSide

    For a reference cell token, which part of the reference it is — 'self' for a standalone cell, or 'left'/'right' for the operands of a range : (see ReferenceSide). Lets an editor pick the range corner for IFormula.setReferenceModeAt (F4) without re-parsing. Absent on non-reference tokens.

    text?: string

    The raw source text this token occupied — exactly the characters that produced it (a whitespace token holds the literal spaces). Concatenating text across the whole array reproduces the original expression, so a consumer can derive each token's character offset as the running sum of text.length — no separate start/end is needed.

    Pairs with value: text is what was typed, value is the resolved/normalized form. The two diverge exactly where normalization is lossy — a number (3.0 → 3, 1**2 → 100) or a cell (raw b2 vs the resolved coords). undefined only for a token with no captured source image (e.g. a reference the engine rewrote programmatically rather than one the user typed).

    A reference literal is ONE span: a typed sheet qualifier and a trailing spill anchor ride inside the cell/named token's text (Sheet2!A1#), so the caret rules an editor applies per token treat the whole reference as one. The anchor keeps its own postfix token (carrying the same referenceIndex) imaging the empty string, so the concatenation above still holds.

    type: string

    The type of token.

    value: any

    The resolved/normalized form of the token; the shape depends on type.

    Reference tokens are structured — a cell token carries IRange.FixableCellCoords, a named or parameter token a NamedRef, a tableColumn or tableSpecifier token a TablePartRef, and an error REFERENCE token (#REF!, #NAME?) an ErrorRef, each holding its own sheet qualifier (coords.scope / ref.scope) so serializers can re-emit Sheet1!…. Most other tokens (operators, function names, separators) carry a string; literals carry their parsed value (number, boolean), an error literal its canonical label (#DIV/0!).