Bug 45025 - improved FormulaParser parse error messages (r659452 had wrong bug number)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@659455 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
dc3f6b36b8
commit
a4aab681a7
@ -37,7 +37,7 @@
|
||||
|
||||
<!-- Don't forget to update status.xml too! -->
|
||||
<release version="3.1-final" date="2008-06-??">
|
||||
<action dev="POI-DEVELOPERS" type="add">45041 - improved FormulaParser parse error messages</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">45025 - improved FormulaParser parse error messages</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">45046 - allowed EXTERNALBOOK(0x01AE) to be optional in the LinkTable</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">45066 - fixed sheet encoding size mismatch problems</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">45003 - Support embeded HDGF visio documents</action>
|
||||
|
@ -34,7 +34,7 @@
|
||||
<!-- Don't forget to update changes.xml too! -->
|
||||
<changes>
|
||||
<release version="3.1-final" date="2008-06-??">
|
||||
<action dev="POI-DEVELOPERS" type="add">45041 - improved FormulaParser parse error messages</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">45025 - improved FormulaParser parse error messages</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">45046 - allowed EXTERNALBOOK(0x01AE) to be optional in the LinkTable</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">45066 - fixed sheet encoding size mismatch problems</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">45003 - Support embeded HDGF visio documents</action>
|
||||
|
@ -140,29 +140,21 @@ public final class FormulaParser {
|
||||
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);
|
||||
@ -218,7 +210,6 @@ public final class FormulaParser {
|
||||
return Token.toString();
|
||||
}
|
||||
|
||||
|
||||
/** Get a Number */
|
||||
private String GetNum() {
|
||||
StringBuffer value = new StringBuffer();
|
||||
@ -564,9 +555,6 @@ public final class FormulaParser {
|
||||
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();
|
||||
@ -710,8 +698,7 @@ public final class FormulaParser {
|
||||
}
|
||||
|
||||
|
||||
private StringPtg parseStringLiteral()
|
||||
{
|
||||
private StringPtg parseStringLiteral() {
|
||||
Match('"');
|
||||
|
||||
StringBuffer token = new StringBuffer();
|
||||
@ -841,8 +828,9 @@ end;
|
||||
**/
|
||||
|
||||
|
||||
/** 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;
|
||||
@ -871,6 +859,7 @@ end;
|
||||
|
||||
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]);
|
||||
@ -951,7 +940,7 @@ end;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
@ -966,7 +955,7 @@ end;
|
||||
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
|
||||
|
@ -56,8 +56,6 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public final class TestFormulaParser extends TestCase {
|
||||
|
||||
@ -76,6 +74,7 @@ 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);
|
||||
|
Loading…
Reference in New Issue
Block a user