return new FormulaParseException(msg);
}
-
-
/** Recognize an Alpha Character */
private boolean IsAlpha(char c) {
return Character.isLetter(c) || c == '$' || c=='_';
}
-
-
/** Recognize a Decimal Digit */
private boolean IsDigit(char c) {
- //System.out.println("Checking digit for"+c);
return Character.isDigit(c);
}
-
-
/** Recognize an Alphanumeric */
private boolean IsAlNum(char c) {
return (IsAlpha(c) || IsDigit(c));
}
-
/** Recognize White Space */
private boolean IsWhite( char c) {
return (c ==' ' || c== TAB);
return Token.toString();
}
-
/** Get a Number */
private String GetNum() {
StringBuffer value = new StringBuffer();
return new ParenthesisPtg();
case '"':
return parseStringLiteral();
- case ',':
- case ')':
- return new MissingArgPtg(); // TODO - not quite the right place to recognise a missing arg
}
if (IsAlpha(look) || look == '\''){
return parseIdent();
}
- private StringPtg parseStringLiteral()
- {
+ private StringPtg parseStringLiteral() {
Match('"');
StringBuffer token = new StringBuffer();
**/
- /** API call to execute the parsing of the formula
- *
+ /**
+ * API call to execute the parsing of the formula
+ * @deprecated use Ptg[] FormulaParser.parse(String, HSSFWorkbook) directly
*/
public void parse() {
pointer=0;
* a result of the parsing
*/
public Ptg[] getRPNPtg() {
- return getRPNPtg(FORMULA_TYPE_CELL);
+ return getRPNPtg(FORMULA_TYPE_CELL);
}
public Ptg[] getRPNPtg(int formulaType) {
Node node = createTree();
+ // RVA is for 'operand class': 'reference', 'value', 'array'
setRootLevelRVA(node, formulaType);
setParameterRVA(node,formulaType);
return (Ptg[]) tokens.toArray(new Ptg[0]);
}
}
/**
- * Convience method which takes in a list then passes it to the
+ * Convenience method which takes in a list then passes it to the
* other toFormulaString signature.
* @param book workbook for 3D and named references
* @param lptgs list of Ptg, can be null or empty
return retval;
}
/**
- * Convience method which takes in a list then passes it to the
+ * Convenience method which takes in a list then passes it to the
* other toFormulaString signature. Works on the current
* workbook for 3D and named references
* @param lptgs list of Ptg, can be null or empty
/**
* Test the low level formula parser functionality. High level tests are to
- * be done via usermodel/HSSFCell.setFormulaValue() .
- * Some tests are also done in scratchpad, if they need
- * HSSFFormulaEvaluator, which is there
+ * be done via usermodel/HSSFCell.setFormulaValue().
*/
public final class TestFormulaParser extends TestCase {
Ptg[] ptgs = parseFormula("2+2");
assertEquals(3, ptgs.length);
}
+
public void testFormulaWithSpace1() {
Ptg[] ptgs = parseFormula(" 2 + 2 ");
assertEquals(3, ptgs.length);