use of org.projectnessie.cel.parser.gen.CELParser in project cel-java by projectnessie.
the class Parser method parse.
ParseResult parse(Source source) {
StringCharStream charStream = new StringCharStream(source.content(), source.description());
CELLexer lexer = new CELLexer(charStream);
CELParser parser = new CELParser(new CommonTokenStream(lexer, 0));
RecursionListener parserListener = new RecursionListener(options.getMaxRecursionDepth());
parser.addParseListener(parserListener);
parser.setErrorHandler(new RecoveryLimitErrorStrategy(options.getErrorRecoveryLimit()));
Helper helper = new Helper(source);
Errors errors = new Errors(source);
InnerParser inner = new InnerParser(helper, errors);
lexer.addErrorListener(inner);
parser.addErrorListener(inner);
Expr expr = null;
try {
if (charStream.size() > options.getExpressionSizeCodePointLimit()) {
errors.reportError(Location.NoLocation, "expression code point size exceeds limit: size: %d, limit %d", charStream.size(), options.getExpressionSizeCodePointLimit());
} else {
expr = inner.exprVisit(parser.start());
}
} catch (RecoveryLimitError | RecursionError e) {
errors.reportError(Location.NoLocation, "%s", e.getMessage());
}
if (errors.hasErrors()) {
expr = null;
}
return new ParseResult(expr, errors, helper.getSourceInfo());
}
Aggregations