/** * Grammar rules and operator precedence for formula parsing */ import type { BinaryOpNode } from "./ast"; /** * Operator precedence levels (higher number = higher precedence) */ export declare const OPERATOR_PRECEDENCE: Record; /** * Operator associativity */ type Associativity = "left" | "right"; export declare const OPERATOR_ASSOCIATIVITY: Record; /** * Check if a string is a valid binary operator */ export declare function isBinaryOperator(op: string): op is BinaryOpNode["operator"]; /** * Get operator precedence */ export declare function getOperatorPrecedence(op: string): number; /** * Get operator associativity */ export declare function getOperatorAssociativity(op: string): Associativity; /** * Compare operator precedence * Returns: * - positive if op1 has higher precedence than op2 * - negative if op1 has lower precedence than op2 * - 0 if they have the same precedence */ export declare function compareOperatorPrecedence(op1: string, op2: string): number; /** * Built-in function names that don't require parentheses in some contexts */ export declare const SPECIAL_FUNCTIONS: Set; /** * Special constants */ export declare const SPECIAL_CONSTANTS: Set; /** * Functions that accept variable number of arguments */ export declare const VARIADIC_FUNCTIONS: Set; /** * Functions that require at least one argument */ export declare const REQUIRED_ARG_FUNCTIONS: Set; /** * Reserved keywords that cannot be used as names */ export declare const RESERVED_KEYWORDS: Set; /** * Check if a name is a reserved keyword */ export declare function isReservedKeyword(name: string): boolean; /** * Grammar production rules (in BNF-like notation): * * Formula ::= Expression * * Expression ::= ComparisonExpr * * ComparisonExpr ::= ConcatExpr (ComparisonOp ConcatExpr)* * ComparisonOp ::= '=' | '<>' | '<' | '>' | '<=' | '>=' * * ConcatExpr ::= AddExpr ('&' AddExpr)* * * AddExpr ::= MultExpr (AddOp MultExpr)* * AddOp ::= '+' | '-' * * MultExpr ::= PowerExpr (MultOp PowerExpr)* * MultOp ::= '*' | '/' * * PowerExpr ::= UnaryExpr ('^' PowerExpr)? // Right associative * * UnaryExpr ::= UnaryOp UnaryExpr | PostfixExpr * UnaryOp ::= '+' | '-' * * PostfixExpr ::= PrimaryExpr ('%')? * * PrimaryExpr ::= Number * | String * | Boolean * | Error * | CellReference * | RangeReference * | NamedExpression * | FunctionCall * | ArrayLiteral * | '(' Expression ')' * * CellReference ::= (SheetName '!')? AbsoluteIndicator? Column AbsoluteIndicator? Row * RangeReference ::= CellReference ':' CellReference * * SheetName ::= Identifier | '\'' AnyCharsExceptQuote '\'' * AbsoluteIndicator ::= '$' * * NamedExpression ::= Identifier // Not followed by '(' or ':' * * FunctionCall ::= FunctionName '(' ArgumentList? ')' * ArgumentList ::= Expression (',' Expression)* * * ArrayLiteral ::= '{' ArrayRows '}' * ArrayRows ::= ArrayRow (';' ArrayRow)* * ArrayRow ::= Expression (',' Expression)* * * Number ::= [+-]? [0-9]+ ('.' [0-9]+)? ([eE] [+-]? [0-9]+)? * String ::= '"' (AnyCharExceptQuote | '""')* '"' * Boolean ::= 'TRUE' | 'FALSE' * Error ::= '#DIV/0!' | '#N/A' | '#NAME?' | '#NUM!' | '#REF!' | '#VALUE!' | '#CYCLE!' | '#ERROR!' * Identifier ::= [A-Za-z_][A-Za-z0-9_]* * FunctionName ::= Identifier */ /** * Cell reference patterns */ export declare const CELL_REFERENCE_PATTERNS: { COLUMN: RegExp; COLUMN_WITH_ABSOLUTE: RegExp; ROW: RegExp; ROW_WITH_ABSOLUTE: RegExp; CELL: RegExp; SHEET_QUALIFIED: RegExp; SHEET_RANGE_QUALIFIED: RegExp; INFINITE_COLUMN: RegExp; INFINITE_ROW: RegExp; OPEN_ENDED_INFINITY: RegExp; OPEN_ENDED_COLUMN: RegExp; OPEN_ENDED_ROW: RegExp; TABLE_REFERENCE: RegExp; CURRENT_ROW_REFERENCE: RegExp; TABLE_SELECTOR: RegExp; }; /** * Validate a column reference */ export declare function isValidColumn(col: string): boolean; /** * Validate a row reference */ export declare function isValidRow(row: string): boolean; /** * Parse a cell reference into components */ interface ParsedCellReference { sheet?: string; colAbsolute: boolean; col: string; rowAbsolute: boolean; row: string; } interface ParsedInfiniteRange { sheet?: string; type: "column" | "row"; startAbsolute: boolean; start: string; endAbsolute: boolean; end: string; } export declare function parseCellReference(ref: string): ParsedCellReference | null; export declare function parseInfiniteRange(ref: string): ParsedInfiniteRange | null; /** * Parse open-ended range patterns (A5:INFINITY, A5:D, A5:15) */ interface ParsedOpenEndedRange { sheet?: string; type: "infinity" | "column-bounded" | "row-bounded"; startCol: string; startRow: string; startColAbsolute: boolean; startRowAbsolute: boolean; endCol?: string; endRow?: string; endColAbsolute?: boolean; endRowAbsolute?: boolean; } export declare function parseOpenEndedRange(ref: string): ParsedOpenEndedRange | null; /** * Parse a 3D range reference (e.g., Sheet1:Sheet3!A1) */ interface Parsed3DReference { startSheet: string; endSheet: string; reference: string; } export declare function parse3DReference(ref: string): Parsed3DReference | null; /** * Parse a structured reference (e.g., Table1[Column1]) */ interface ParsedStructuredReference { tableName: string; columnSpec: string; isCurrentRow?: boolean; selector?: string; cols?: { startCol: string; endCol: string; }; } export declare function parseStructuredReference(ref: string): ParsedStructuredReference | null; export {};