}
- private final String formulaString;
- private final int formulaLength;
- private int pointer;
+ private final String _formulaString;
+ private final int _formulaLength;
+ private int _pointer;
private ParseNode _rootNode;
*/
private char look;
- private FormulaParsingWorkbook book;
+ private FormulaParsingWorkbook _book;
* 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 retrive the
+ * rpn order, then call the getRPNPtg() to retrieve the
* parse results.
* This class is recommended only for single threaded use.
*
* usermodel.HSSFFormulaEvaluator
*/
private FormulaParser(String formula, FormulaParsingWorkbook book){
- formulaString = formula;
- pointer=0;
- this.book = book;
- formulaLength = formulaString.length();
+ _formulaString = formula;
+ _pointer=0;
+ _book = book;
+ _formulaLength = _formulaString.length();
}
public static Ptg[] parse(String formula, FormulaParsingWorkbook book) {
/** Read New Character From Input Stream */
private void GetChar() {
// Check to see if we've walked off the end of the string.
- if (pointer > formulaLength) {
+ if (_pointer > _formulaLength) {
throw new RuntimeException("too far");
}
- if (pointer < formulaLength) {
- look=formulaString.charAt(pointer);
+ if (_pointer < _formulaLength) {
+ look=_formulaString.charAt(_pointer);
} else {
// Just return if so and reset 'look' to something to keep
// SkipWhitespace from spinning
look = (char)0;
}
- pointer++;
+ _pointer++;
//System.out.println("Got char: "+ look);
}
private RuntimeException expected(String s) {
String msg;
- if (look == '=' && formulaString.substring(0, pointer-1).trim().length() < 1) {
- msg = "The specified formula '" + formulaString
+ if (look == '=' && _formulaString.substring(0, _pointer-1).trim().length() < 1) {
+ msg = "The specified formula '" + _formulaString
+ "' starts with an equals sign which is not allowed.";
} else {
- msg = "Parse error near char " + (pointer-1) + " '" + look + "'"
- + " in specified formula '" + formulaString + "'. Expected "
+ msg = "Parse error near char " + (_pointer-1) + " '" + look + "'"
+ + " in specified formula '" + _formulaString + "'. Expected "
+ s;
}
return new FormulaParseException(msg);
new FormulaParseException("Name '" + name
+ "' does not look like a cell reference or named range");
}
- EvaluationName evalName = book.getName(name);
+ EvaluationName evalName = _book.getName(name);
if (evalName == null) {
throw new FormulaParseException("Specified named range '"
+ name + "' does not exist in the current workbook.");
int pos = name.lastIndexOf(']'); // safe because sheet names never have ']'
String wbName = name.substring(1, pos);
String sheetName = name.substring(pos+1);
- return book.getExternalSheetIndex(wbName, sheetName);
+ return _book.getExternalSheetIndex(wbName, sheetName);
}
- return book.getExternalSheetIndex(name);
+ return _book.getExternalSheetIndex(name);
}
/**
// user defined function
// in the token tree, the name is more or less the first argument
- EvaluationName hName = book.getName(name);
+ EvaluationName hName = _book.getName(name);
if (hName == null) {
- nameToken = book.getNameXPtg(name);
+ nameToken = _book.getNameXPtg(name);
if (nameToken == null) {
throw new FormulaParseException("Name '" + name
+ "' is completely unknown in the current workbook");
*
*/
private void parse() {
- pointer=0;
+ _pointer=0;
GetChar();
_rootNode = unionExpression();
- if(pointer <= formulaLength) {
- String msg = "Unused input [" + formulaString.substring(pointer-1)
- + "] after attempting to parse the formula [" + formulaString + "]";
+ if(_pointer <= _formulaLength) {
+ String msg = "Unused input [" + _formulaString.substring(_pointer-1)
+ + "] after attempting to parse the formula [" + _formulaString + "]";
throw new FormulaParseException(msg);
}
}
import org.apache.poi.hssf.record.formula.ConcatPtg;
import org.apache.poi.hssf.record.formula.DividePtg;
import org.apache.poi.hssf.record.formula.EqualPtg;
-import org.apache.poi.hssf.record.formula.ExpPtg;
import org.apache.poi.hssf.record.formula.FuncPtg;
import org.apache.poi.hssf.record.formula.FuncVarPtg;
import org.apache.poi.hssf.record.formula.GreaterEqualPtg;
}
OperationEval result;
- Class ptgClass = ptg.getClass();
+ Class<? extends OperationPtg> ptgClass = ptg.getClass();
result = _instancesByPtgClass.get(ptgClass);
if (result != null) {
if (ptgClass == ConcatPtg.class) {
return new ConcatEval((ConcatPtg)ptg);
}
- if(ptgClass == ExpPtg.class) {
- // ExpPtg is used for array formulas and shared formulas.
- // it is currently unsupported, and may not even get implemented here
- throw new RuntimeException("ExpPtg currently not supported");
- }
throw new RuntimeException("Unexpected operation ptg class (" + ptgClass.getName() + ")");
}
}
import org.apache.poi.hssf.record.formula.DeletedArea3DPtg;
import org.apache.poi.hssf.record.formula.DeletedRef3DPtg;
import org.apache.poi.hssf.record.formula.ErrPtg;
+import org.apache.poi.hssf.record.formula.ExpPtg;
import org.apache.poi.hssf.record.formula.FuncVarPtg;
import org.apache.poi.hssf.record.formula.IntPtg;
import org.apache.poi.hssf.record.formula.MemErrPtg;
// In any case, formulas are re-parsed before execution, so UnknownPtg should not get here
throw new RuntimeException("UnknownPtg not allowed");
}
+ if (ptg instanceof ExpPtg) {
+ // ExpPtg is used for array formulas and shared formulas.
+ // it is currently unsupported, and may not even get implemented here
+ throw new RuntimeException("ExpPtg currently not supported");
+ }
throw new RuntimeException("Unexpected ptg class (" + ptg.getClass().getName() + ")");
}