Search in sources :

Example 1 with Parser

use of io.atlasmap.expression.parser.Parser in project atlasmap by atlasmap.

the class Expression method parse.

/**
 * Parses the expression text.
 * @param expessionText expression text
 * @param functionResolver function resolver
 * @return result
 * @throws ExpressionException unexpected error
 */
static Expression parse(String expessionText, FunctionResolver functionResolver) throws ExpressionException {
    if (functionResolver == null) {
        functionResolver = (name, args) -> {
            throw new ParseException("Function not found: " + name);
        };
    }
    Object result = CACHE.get(expessionText);
    if (result instanceof ExpressionException) {
        throw (ExpressionException) result;
    } else if (result instanceof Expression) {
        return (Expression) result;
    } else {
        String actual = expessionText;
        try {
            Parser parser = new Parser(new StringReader(actual));
            parser.functionResolver = functionResolver;
            Expression e = parser.parse();
            CACHE.put(expessionText, e);
            return e;
        } catch (Throwable e) {
            ExpressionException fe = new ExpressionException(actual, e);
            CACHE.put(expessionText, fe);
            throw fe;
        }
    }
}
Also used : StringReader(java.io.StringReader) ParseException(io.atlasmap.expression.parser.ParseException) Parser(io.atlasmap.expression.parser.Parser)

Aggregations

ParseException (io.atlasmap.expression.parser.ParseException)1 Parser (io.atlasmap.expression.parser.Parser)1 StringReader (java.io.StringReader)1