/** * The formula tokenizer: a single left-to-right scan turning a formula source * string into a flat {@link Token} array for the parser. * * Design goals (per Photon Grid's performance rules): * - **One pass, no per-token regex.** Scanning is done with `charCodeAt` and * manual classification, so tokenizing a formula never allocates throwaway * regex match objects or backtracks. * - **Configurable separators.** The argument separator (`,`) and decimal * separator (`.`) come from {@link ResolvedFormulaConfig}, so locales using * `;`/`,` are supported without code changes. * - **Error-tolerant.** An unrecognized character yields a single * {@link FormulaError} rather than throwing, letting the parser surface a * clean `#ERROR!`. * * The leading `=` (or `+`/`@` lead-in) of a formula is stripped by the caller * before tokenizing; this scanner sees only the expression body. * * @packageDocumentation */ import { Token } from './token.types'; import type { ResolvedFormulaConfig } from '../config/formula-config'; /** A tokenizer result: either the tokens, or the position of a scan error. */ export interface TokenizeResult { /** The scanned tokens (always terminated by an `EOF` token). */ readonly tokens: Token[]; /** Non-null when scanning hit an invalid character; carries its offset. */ readonly error: { message: string; position: number; } | null; } /** * Converts a formula body into tokens. * * The tokenizer is stateless between calls; a single shared instance is safe to * reuse across the whole grid. */ export declare class Tokenizer { /** * Scans `input` into tokens using the given configuration for separators. * * @param input - The formula body (without the leading `=`). * @param config - Resolved config supplying decimal/argument separators. * @returns The token list plus an optional scan error. */ tokenize(input: string, config: ResolvedFormulaConfig): TokenizeResult; /** Scans a `"..."` string with `""` → `"` escaping. Returns `null` if unterminated. */ private scanString; /** Scans a numeric literal (digits, one decimal separator, scientific `e` notation). */ private scanNumber; /** Scans an Excel error literal such as `#N/A`, `#REF!`, `#DIV/0!`. Returns end (== start if none). */ private scanErrorLiteral; /** Scans a word run: letters, digits, `$`, `_`, `.`, and a single `!` sheet separator. */ private scanWord; /** Scans a one- or two-character operator; returns end (== start if none). */ private scanOperator; private isDigit; private isLetter; private isRefStart; private isWordChar; /** * Heuristic: does `raw` (a scanned word) look like an `A1` cell reference? * Accepts optional sheet prefix (`Sheet1!`), optional `$` anchors, one or more * letters, then one or more digits. `TRUE`/`FALSE` are excluded (handled as * booleans by the parser), as are pure-letter (`SUM`) and word tokens. */ private looksLikeReference; } /** A process-wide shared tokenizer (stateless, safe to reuse). */ export declare const sharedTokenizer: Tokenizer; //# sourceMappingURL=tokenizer.d.ts.map