UNPKG

xlsxp

Version:

An Excel formula parser in javascript/typescript

181 lines (180 loc) 5.41 kB
type InfixOperator = "^" | "*" | "/" | "+" | "-" | "&" | "=" | "<>" | "<" | "<=" | ">" | ">=" | ":" | "," | " "; type PostfixOperator = "%" | "#"; type PrefixOperator = "+" | "-" | "@"; declare enum Kind { INFIX = 0, PREFIX = 1, POSTFIX = 2, VALUE = 3, LIST = 4, NAME = 5, FCALL = 6, MISSING = 7, SINGLE_SHEET = 8, SHEET_RANGE = 9, COLUMN_RANGE = 10, ROW_RANGE = 11, CELL = 12, AREA = 13, EXTERNAL_CELL_REFERENCE = 14, TABLE_IDENTIFIER = 15, TABLE_COLUMN = 16, TABLE_COLUMN_RANGE = 17, TABLE_SPECIFIER = 18, STRUCTURED_REFERENCE = 19, FUNCTION_NAME = 20 } declare class Node { kind: Kind; constructor(kind: Kind); } declare class InfixNode extends Node { op: InfixOperator; lhs: Node; rhs: Node; constructor(lhs: Node, op: InfixOperator, rhs: Node); } declare class PrefixNode extends Node { op: PrefixOperator; expr: Node; constructor(op: PrefixOperator, expr: Node); } declare class PostfixNode extends Node { op: PostfixOperator; expr: Node; constructor(expr: Node, op: PostfixOperator); } declare enum ValueType { ERROR = 0, LOGICAL = 1, NUMBER = 2, STRING = 3, ARRAY = 4 } declare class ValueNode extends Node { type: ValueType; constructor(type: ValueType); } declare enum ErrorValue { REF = 0, DIV0 = 1, NA = 2, NAME = 3, NULL = 4, NUM = 5, VALUE = 6, GETTING_DATA = 7, SPILL = 8 } declare class ErrorValueNode extends ValueNode { value: ErrorValue; constructor(value: ErrorValue); } declare class LogicalValueNode extends ValueNode { value: boolean; constructor(value: boolean); } declare class NumberValueNode extends ValueNode { value: number; constructor(value: number); } declare class StringValueNode extends ValueNode { value: string; constructor(value: string); } declare class ListNode extends Node { list: Node[]; constructor(node?: Node); push(node: Node): void; } declare class ArrayValueNode extends ValueNode { value: ValueNode[][]; constructor(row: ValueNode[]); push(row: ValueNode[]): void; } declare class NameNode extends Node { name: string; constructor(name: string); } declare class FunctionNameNode extends Node { name: string; constructor(name: string); } // single-sheet = [workbook-index] sheet-name / apostrophe [workbook-index] sheet-name-special apostrophe declare class SingleSheetNode extends Node { sheet: string; workbook?: string; constructor(sheet: string, workbook?: string); } // sheet-range = [workbook-index] sheet-name ":" sheet-name / apostrophe [workbook-index] sheet-name-special ":" sheet-name-special apostrophe declare class SheetRangeNode extends Node { start: string; end: string; workbook?: string; constructor(start: string, end: string, workbook?: string); } declare class ColumnRangeNode extends Node { start: number; end: number; flags: number; // 0x01 -> startAbs, 0x02 -> endAbs constructor(start: number, end: number, flags?: number); } declare class RowRangeNode extends Node { start: number; end: number; flags: number; // 0x01 -> startAbs, 0x02 -> endAbs constructor(start: number, end: number, flags?: number); } declare class CellNode extends Node { row: number; column: number; flags: number; // 0x01 -> row, 0x02 -> column 0x04 -> spill constructor(row: number, column: number, flags?: number); } declare class AreaNode extends Node { start: CellNode; end: CellNode; constructor(start: CellNode, end: CellNode); } declare class ExternalCellReference extends Node { sheet: SingleSheetNode | SheetRangeNode; cell: CellNode | AreaNode; constructor(sheet: SingleSheetNode | SheetRangeNode, cell: CellNode | AreaNode); } declare class TableIdentifierNode extends Node { workbook?: string; name: string; constructor(name: string, workbook?: string); } declare class TableColumnNode extends Node { name: string; constructor(name: string); } declare class TableColumnRangeNode extends Node { first: TableColumnNode; last?: TableColumnNode | null; constructor(first: TableColumnNode, last?: TableColumnNode); } declare class TableSpecifierNode extends Node { value: number; constructor(value: number); } declare class StructuredReferenceNode extends Node { table?: TableIdentifierNode; column?: TableColumnRangeNode; specifier: number; constructor(specifier?: number, column?: TableColumnRangeNode); } declare class FunctionCallNode extends Node { name: NameNode; args: ListNode; constructor(name: Node, args: ListNode); } declare class MissingNode extends Node { constructor(); } declare class Formula { node?: Node; } declare function parse(formula: string): Node | undefined; export { parse, Formula, Node, InfixOperator, PostfixOperator, PrefixOperator, Kind, InfixNode, PrefixNode, PostfixNode, ValueType, ValueNode, ErrorValue, ErrorValueNode, LogicalValueNode, NumberValueNode, StringValueNode, ListNode, ArrayValueNode, NameNode, FunctionNameNode, SingleSheetNode, SheetRangeNode, ColumnRangeNode, RowRangeNode, CellNode, AreaNode, ExternalCellReference, TableIdentifierNode, TableColumnNode, TableColumnRangeNode, TableSpecifierNode, StructuredReferenceNode, FunctionCallNode, MissingNode };