<expression> ::= <term> [<addop> <term>]*
<term> ::= <factor> [ <mulop> <factor> ]*
<factor> ::= <number> | (<expression>) | <cellRef> | <function>
<function> ::= <functionName> ([expression [, expression]*])
For POI internal use only
| Modifier and Type | Class and Description |
|---|---|
| private static class | FormulaParser.
A1, $A1, A$1, $A$1, A, 1 |
| Modifier and Type | Field and Description |
|---|---|
| private final FormulaParsingWorkbook | |
| private final int | |
| private final String | |
| private boolean | _inIntersection
Tracks whether the run of whitespace preceding "look" could be an intersection operator. |
| private int | |
| private ParseNode | |
| private final int | |
| private final int | |
| private final SpreadsheetVersion | |
| private static final Pattern | CELL_REF_PATTERN
Matches a zero or one letter-runs followed by zero or one digit-runs. |
| private static final char | |
| private static final char | |
| private static final Logger | |
| private int | look
Lookahead unicode codepoint gets value '\0' when the input string is exhausted |
| private static final String | |
| private static final String | |
| private static final String | |
| private static final String | |
| private static final String | |
| private static final char |
| Access | Constructor and Description |
|---|---|
| private | FormulaParser(String formula, FormulaParsingWorkbook book, int sheetIndex, int rowIndex)
Create the formula parser, with the string that is to be parsed against the supplied workbook. |
| Modifier and Type | Method and Description |
|---|---|
| private ParseNode | |
| private void | |
| private ParseNode[] | |
| private static ParseNode | |
| private void | |
| private static void | checkValidRangeOperand(String sideName, int
used to format a potential error message currentParsePosition, ParseNode pn)
|
| private ParseNode | |
| private ParseNode | |
| private static Double | |
| private AreaReference | |
| private ParseNode | createAreaRefParseNode(SheetIdentifier
may be sheetIden, FormulaParser.nullmay be part2null
|
| private RuntimeException | |
| private ParseNode | |
| private String | |
| private Ptg | |
| private ParseNode | |
| private static Ptg | getNumberPtgFromString(String number1, String number2, String exponent)
Get a PTG for an integer from its string representation. |
| private Ptg[] | |
| private ParseNode | |
| private static boolean | |
| private static boolean | |
| private static boolean | |
| private static boolean | isUnquotedSheetNameChar(int
unicode codepoint ch)very similar to |
| private boolean | |
| private static boolean | Returns: true if the specified character may be used in a defined nameunicode codepoint ch)
|
| private static boolean | Returns: false if sub-expression represented the specified ParseNode definitely
cannot appear on either side of the range (':') operator
|
| private static boolean | |
| private void | match(int x)
Consumes the next input character if it is equal to the one specified otherwise throws an unchecked exception. |
| private static boolean | needsMemFunc(ParseNode root)
From OOO doc: "Whenever one operand of the reference subexpression is a function, a defined name, a 3D reference, or an external reference (and no error occurs), a tMemFunc token is used" |
| private void | |
| private String | |
| public static Ptg[] | Returns: array of parsed tokensthe formula to parse formula, FormulaParsingWorkbook the parent workbook workbook, FormulaType the type of the formula formulaType, int the 0-based index of the sheet this formula belongs to.
The sheet index is required to resolve sheet-level names. sheetIndex, int -1 means that
the scope of the name will be ignored and the parser will match names only by name- the related cell's row index in 0-based form (-1 if the formula is not cell related)
used to handle structured references that have the "#This Row" quantifier.
Use rowIndex=-1 or rowIndex)parseStructuredReference(String, FormulaParsingWorkbook, int) if formula
does not contain structured references.Parse a formula into an array of tokens
Side effect: creates name ( |
| public static Ptg[] | Returns: array of parsed tokensthe formula to parse formula, FormulaParsingWorkbook the parent workbook workbook, FormulaType the type of the formula formulaType, int the 0-based index of the sheet this formula belongs to.
The sheet index is required to resolve sheet-level names. sheetIndex)-1 means that
the scope of the name will be ignored and the parser will match names only by nameParse a formula into an array of tokens
Side effect: creates name ( |
| private void | |
| private ParseNode | |
| private Object | |
| private Object[] | |
| private String | parseAsColumnQuantifier()
Tries to parse the next as column - can contain whitespace Caller should save pointer. |
| private String | |
| private String | |
| private Boolean | |
| private int | |
| private ParseNode | parseNonRange(int savePointer)
Parses simple factors that are not primitive ranges or range components i.e. '!', ':'(and equiv '...') do not appear Examples my.named...range. |
| private Ptg | |
| private ParseNode | parseRangeable()
Parses area refs (things which could be the operand of ':') and simple factors Examples A$1 $A$1 : $B1 A1 ....... |
| private ParseNode | |
| private SheetIdentifier | Returns: The sheet name as an identifiernull if '!' is not found in the right placeNote - caller should reset |
| private SheetIdentifier | parseSheetRange(String bookname, NameIdentifier sheet1Name, boolean isSndPartOfQuotedRange)
If we have something that looks like [book]Sheet1: or Sheet1, see if it's actually a range eg Sheet1:Sheet2! |
| private ParseNode | |
| private FormulaParser. | parseSimpleRangePart()
Parses out a potential LHS or RHS of a ':' intended to produce a plain AreaRef. |
| private String | |
| public static Area3DPxg | Returns: the area that being represented by the structured reference.- The structured reference text tableText, FormulaParsingWorkbook - the parent workbook workbook, int - the 0-based cell's row index ( used to handle "#This Row" quantifiers ) rowIndex)Parse a structured reference. |
| private ParseNode | Returns: Area Reference for the given tableParses a structured reference, returns it as area reference. |
| private ParseNode | |
| private String | |
| private ParseNode | |
| private ParseNode | |
| private void | |
| private void | |
| private ParseNode | |
| private ParseNode | |
| private void |
| _book | back to summary |
|---|---|
| private final FormulaParsingWorkbook _book | |
| _formulaLength | back to summary |
|---|---|
| private final int _formulaLength | |
| _formulaString | back to summary |
|---|---|
| private final String _formulaString | |
| _inIntersection | back to summary |
|---|---|
| private boolean _inIntersection Tracks whether the run of whitespace preceding "look" could be an intersection operator. See GetChar. | |
| _pointer | back to summary |
|---|---|
| private int _pointer points at the next character to be read (after the | |
| _rootNode | back to summary |
|---|---|
| private ParseNode _rootNode | |
| _rowIndex | back to summary |
|---|---|
| private final int _rowIndex | |
| _sheetIndex | back to summary |
|---|---|
| private final int _sheetIndex | |
| _ssVersion | back to summary |
|---|---|
| private final SpreadsheetVersion _ssVersion | |
| CELL_REF_PATTERN | back to summary |
|---|---|
| private static final Pattern CELL_REF_PATTERN Matches a zero or one letter-runs followed by zero or one digit-runs. Either or both runs man optionally be prefixed with a single '$'. (copied+modified from CellReference.CELL_REF_PATTERN) | |
| CR | back to summary |
|---|---|
| private static final char CR | |
| LF | back to summary |
|---|---|
| private static final char LF | |
| LOGGER | back to summary |
|---|---|
| private static final Logger LOGGER | |
| look | back to summary |
|---|---|
| private int look Lookahead unicode codepoint gets value '\0' when the input string is exhausted | |
| specAll | back to summary |
|---|---|
| private static final String specAll | |
| specData | back to summary |
|---|---|
| private static final String specData | |
| specHeaders | back to summary |
|---|---|
| private static final String specHeaders | |
| specThisRow | back to summary |
|---|---|
| private static final String specThisRow | |
| specTotals | back to summary |
|---|---|
| private static final String specTotals | |
| TAB | back to summary |
|---|---|
| private static final char TAB | |
| FormulaParser | back to summary |
|---|---|
| private FormulaParser(String formula, FormulaParsingWorkbook book, int sheetIndex, int rowIndex) Create the formula parser, with the string that is to be
parsed against the supplied workbook.
A later call the parse() method to return ptg list in
rpn order, then call the getRPNPtg() to retrieve the
parse results.
This class is recommended only for single threaded use.
If you have a | |
| additiveExpression | back to summary |
|---|---|
| private ParseNode additiveExpression() Parse and Translate an Expression | |
| addName | back to summary |
|---|---|
| private void addName(String functionName) Adds a name (named range or user defined function) to underlying workbook's names table | |
| Arguments | back to summary |
|---|---|
| private ParseNode[] Arguments() get arguments to a function | |
| augmentWithMemPtg | back to summary |
|---|---|
| private static ParseNode augmentWithMemPtg(ParseNode root) | |
| checkRowLengths | back to summary |
|---|---|
| private void checkRowLengths(Object[][] values2d, int nColumns) | |
| checkValidRangeOperand | back to summary |
|---|---|
private static void checkValidRangeOperand(String sideName, int currentParsePosition, ParseNode pn)
| |
| comparisonExpression | back to summary |
|---|---|
| private ParseNode comparisonExpression() | |
| concatExpression | back to summary |
|---|---|
| private ParseNode concatExpression() | |
| convertArrayNumber | back to summary |
|---|---|
| private static Double convertArrayNumber(Ptg ptg, boolean isPositive) | |
| createAreaRef | back to summary |
|---|---|
| private AreaReference createAreaRef(FormulaParser. | |
| createAreaRefParseNode | back to summary |
|---|---|
private ParseNode createAreaRefParseNode(SheetIdentifier sheetIden, FormulaParser.
| |
| expected | back to summary |
|---|---|
| private RuntimeException expected(String s) Report What Was Expected | |
| function | back to summary |
|---|---|
| private ParseNode function(String name) Note - Excel function names are 'case aware but not case sensitive'. This method may end up creating a defined name record in the workbook if the specified name is not an internal Excel function, and has not been encountered before. Side effect: creates workbook name if name is not recognized (name is probably a UDF)
| |
| getBookName | back to summary |
|---|---|
| private String getBookName() | |
| getComparisonToken | back to summary |
|---|---|
| private Ptg getComparisonToken() | |
| getFunction | back to summary |
|---|---|
| private ParseNode getFunction(String name, Ptg namePtg, ParseNode[] args) Generates the variable function ptg for the formula. For IF Formulas, additional PTGs are added to the tokens | |
| getNumberPtgFromString | back to summary |
|---|---|
| private static Ptg getNumberPtgFromString(String number1, String number2, String exponent) Get a PTG for an integer from its string representation. return Int or Number Ptg based on size of input | |
| getRPNPtg | back to summary |
|---|---|
| private Ptg[] getRPNPtg(FormulaType formulaType) | |
| intersectionExpression | back to summary |
|---|---|
| private ParseNode intersectionExpression() | |
| isAlpha | back to summary |
|---|---|
| private static boolean isAlpha(int c) Recognize an Alpha Character | |
| isArgumentDelimiter | back to summary |
|---|---|
private static boolean isArgumentDelimiter(int ch)
| |
| isDigit | back to summary |
|---|---|
| private static boolean isDigit(int c) Recognize a Decimal Digit | |
| isUnquotedSheetNameChar | back to summary |
|---|---|
| private static boolean isUnquotedSheetNameChar(int ch) very similar to
| |
| isValidCellReference | back to summary |
|---|---|
private boolean isValidCellReference(String str)
| |
| isValidDefinedNameChar | back to summary |
|---|---|
private static boolean isValidDefinedNameChar(int ch)
| |
| isValidRangeOperand | back to summary |
|---|---|
private static boolean isValidRangeOperand(ParseNode a)
| |
| isWhite | back to summary |
|---|---|
| private static boolean isWhite(int c) Recognize White Space | |
| match | back to summary |
|---|---|
| private void match(int x) Consumes the next input character if it is equal to the one specified otherwise throws an unchecked exception. This method does not consume whitespace (before or after the matched character). | |
| needsMemFunc | back to summary |
|---|---|
| private static boolean needsMemFunc(ParseNode root) From OOO doc: "Whenever one operand of the reference subexpression is a function, a defined name, a 3D reference, or an external reference (and no error occurs), a tMemFunc token is used" | |
| nextChar | back to summary |
|---|---|
| private void nextChar() Read New Character From Input Stream | |
| nextNum | back to summary |
|---|---|
| private String nextNum() Get a Number | |
| parse | back to summary |
|---|---|
| public static Ptg[] parse(String formula, FormulaParsingWorkbook workbook, FormulaType formulaType, int sheetIndex, int rowIndex) Parse a formula into an array of tokens
Side effect: creates name (
| |
| parse | back to summary |
|---|---|
| public static Ptg[] parse(String formula, FormulaParsingWorkbook workbook, FormulaType formulaType, int sheetIndex) Parse a formula into an array of tokens
Side effect: creates name (
| |
| parse | back to summary |
|---|---|
| private void parse() API call to execute the parsing of the formula | |
| parseArray | back to summary |
|---|---|
| private ParseNode parseArray() | |
| parseArrayItem | back to summary |
|---|---|
| private Object parseArrayItem() | |
| parseArrayRow | back to summary |
|---|---|
| private Object[] parseArrayRow() | |
| parseAsColumnQuantifier | back to summary |
|---|---|
| private String parseAsColumnQuantifier() Tries to parse the next as column - can contain whitespace Caller should save pointer. | |
| parseAsName | back to summary |
|---|---|
| private String parseAsName() | |
| parseAsSpecialQuantifier | back to summary |
|---|---|
| private String parseAsSpecialQuantifier() Tries to parse the next as special quantifier Caller should save pointer. | |
| parseBooleanLiteral | back to summary |
|---|---|
| private Boolean parseBooleanLiteral() | |
| parseErrorLiteral | back to summary |
|---|---|
| private int parseErrorLiteral() | |
| parseNonRange | back to summary |
|---|---|
| private ParseNode parseNonRange(int savePointer) Parses simple factors that are not primitive ranges or range components i.e. '!', ':'(and equiv '...') do not appear Examples my.named...range. foo.bar(123.456, "abc") 123.456 "abc" true | |
| parseNumber | back to summary |
|---|---|
| private Ptg parseNumber() | |
| parseRangeable | back to summary |
|---|---|
| private ParseNode parseRangeable() Parses area refs (things which could be the operand of ':') and simple factors Examples A$1 $A$1 : $B1 A1 ....... C2 Sheet1 !$A1 a..b!A1 'my sheet'!A1 .my.sheet!A1 'my sheet':'my alt sheet'!A1 .my.sheet1:.my.sheet2!$B$2 my.named..range. 'my sheet'!my.named.range .my.sheet!my.named.range foo.bar(123.456, "abc") 123.456 "abc" true [Foo.xls]!$A$1 [Foo.xls]'my sheet'!$A$1 [Foo.xls]!my.named.range | |
| parseRangeExpression | back to summary |
|---|---|
| private ParseNode parseRangeExpression() | |
| parseSheetName | back to summary |
|---|---|
| private SheetIdentifier parseSheetName(boolean isSndPartOfQuotedRange) Note - caller should reset
| |
| parseSheetRange | back to summary |
|---|---|
| private SheetIdentifier parseSheetRange(String bookname, NameIdentifier sheet1Name, boolean isSndPartOfQuotedRange) If we have something that looks like [book]Sheet1: or Sheet1, see if it's actually a range eg Sheet1:Sheet2! | |
| parseSimpleFactor | back to summary |
|---|---|
| private ParseNode parseSimpleFactor() factors (without ^ or % ) | |
| parseSimpleRangePart | back to summary |
|---|---|
| private FormulaParser. Parses out a potential LHS or RHS of a ':' intended to produce a plain AreaRef. Normally these are proper cell references but they could also be row or column refs like "$AC" or "10"
| |
| parseStringLiteral | back to summary |
|---|---|
| private String parseStringLiteral() | |
| parseStructuredReference | back to summary |
|---|---|
| public static Area3DPxg parseStructuredReference(String tableText, FormulaParsingWorkbook workbook, int rowIndex) Parse a structured reference. Converts the structured reference to the area that represent it.
| |
| parseStructuredReference | back to summary |
|---|---|
| private ParseNode parseStructuredReference(String tableName) Parses a structured reference, returns it as area reference. Examples: Table1[] Table1[col] Table1[[#Totals],[col]] Table1[#Totals] Table1[#All] Table1[#Data] Table1[#Headers] Table1[#Totals] Table1[#This Row] Table1[[#All],[col]] Table1[[#Headers],[col]] Table1[[#Totals],[col]] Table1[[#All],[col1]:[col2]] Table1[[#Data],[col1]:[col2]] Table1[[#Headers],[col1]:[col2]] Table1[[#Totals],[col1]:[col2]] Table1[[#Headers],[#Data],[col2]] Table1[[#This Row], [col1]] Table1[ [col1]:[col2] ]
| |
| parseUnary | back to summary |
|---|---|
| private ParseNode parseUnary(boolean isPlus) | |
| parseUnquotedIdentifier | back to summary |
|---|---|
| private String parseUnquotedIdentifier() | |
| percentFactor | back to summary |
|---|---|
| private ParseNode percentFactor() | |
| powerFactor | back to summary |
|---|---|
| private ParseNode powerFactor() Parse and Translate a Math Factor | |
| resetPointer | back to summary |
|---|---|
| private void resetPointer(int ptr) | |
| skipWhite | back to summary |
|---|---|
| private void skipWhite() Skip Over Leading White Space | |
| Term | back to summary |
|---|---|
| private ParseNode Term() Parse and Translate a Math Term | |
| unionExpression | back to summary |
|---|---|
| private ParseNode unionExpression() | |
| validateNumArgs | back to summary |
|---|---|
| private void validateNumArgs(int numArgs, FunctionMetadata fm) | |
| Modifier and Type | Class and Description |
|---|---|
| private static enum |
| Modifier and Type | Field and Description |
|---|---|
| private final String | |
| private final FormulaParser. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public CellReference | |
| public String | |
| public boolean | |
| public boolean | |
| public boolean | Returns: true if the two range parts can be combined in an
AreaPtg ( Note - the explicit range operator (:) may still be valid
when this method returns false )
|
| public boolean | |
| public boolean | |
| public String |
| _rep | back to summary |
|---|---|
| private final String _rep | |
| _type | back to summary |
|---|---|
| private final FormulaParser. | |
| SimpleRangePart | back to summary |
|---|---|
| public SimpleRangePart(String rep, boolean hasLetters, boolean hasNumbers) | |
| getCellReference | back to summary |
|---|---|
| public CellReference getCellReference() | |
| getRep | back to summary |
|---|---|
| public String getRep() | |
| isCell | back to summary |
|---|---|
| public boolean isCell() | |
| isColumn | back to summary |
|---|---|
| public boolean isColumn() | |
| isCompatibleForArea | back to summary |
|---|---|
public boolean isCompatibleForArea(FormulaParser.
| |
| isRow | back to summary |
|---|---|
| public boolean isRow() | |
| isRowOrColumn | back to summary |
|---|---|
| public boolean isRowOrColumn() | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| Modifier and Type | Field and Description |
|---|---|
| public static final FormulaParser. | |
| public static final FormulaParser. | |
| public static final FormulaParser. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static FormulaParser. | |
| public static FormulaParser. | |
| public static FormulaParser. |
| CELL | back to summary |
|---|---|
| public static final FormulaParser. | |
| COLUMN | back to summary |
|---|---|
| public static final FormulaParser. | |
| ROW | back to summary |
|---|---|
| public static final FormulaParser. | |
| Type | back to summary |
|---|---|
| private Type() | |
| get | back to summary |
|---|---|
| public static FormulaParser. | |
| valueOf | back to summary |
|---|---|
| public static FormulaParser. | |
| values | back to summary |
|---|---|
| public static FormulaParser. | |