Search in sources :

Example 1 with ParseException

use of pcgen.base.formula.parse.ParseException in project pcgen by PCGen.

the class UserFunction method setFunction.

/**
	 * Sets the Function for this UserFunction to the function defined by the
	 * given UserExpression.
	 * 
	 * @param expression
	 *            The expression to be parsed into a Function.
	 */
public void setFunction(String expression) {
    if (expression == null) {
        throw new IllegalArgumentException("Cannot make formula from null String");
    }
    origExpression = expression;
    try {
        SimpleNode root = new FormulaParser(new StringReader(expression)).query();
        function = new GenericFunction(getKeyName(), root);
    } catch (ParseException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : StringReader(java.io.StringReader) GenericFunction(pcgen.base.formula.library.GenericFunction) ParseException(pcgen.base.formula.parse.ParseException) FormulaParser(pcgen.base.formula.parse.FormulaParser) SimpleNode(pcgen.base.formula.parse.SimpleNode)

Aggregations

StringReader (java.io.StringReader)1 GenericFunction (pcgen.base.formula.library.GenericFunction)1 FormulaParser (pcgen.base.formula.parse.FormulaParser)1 ParseException (pcgen.base.formula.parse.ParseException)1 SimpleNode (pcgen.base.formula.parse.SimpleNode)1