use of org.apache.metron.stellar.common.generated.StellarParser in project metron by apache.
the class BaseStellarProcessor method compile.
/**
* Parses and evaluates the given Stellar expression, {@code rule}.
* @param rule The Stellar expression to parse and evaluate.
* @return The Expression, which can be reevaluated without reparsing in different Contexts and Resolvers.
*/
public static StellarCompiler.Expression compile(final String rule) {
if (rule == null || isEmpty(rule.trim())) {
return null;
}
ANTLRInputStream input = new ANTLRInputStream(rule);
StellarLexer lexer = new StellarLexer(input);
lexer.removeErrorListeners();
lexer.addErrorListener(new ErrorListener());
TokenStream tokens = new CommonTokenStream(lexer);
StellarParser parser = new StellarParser(tokens);
StellarCompiler treeBuilder = new StellarCompiler(ArithmeticEvaluator.INSTANCE, NumberLiteralEvaluator.INSTANCE, ComparisonExpressionWithOperatorEvaluator.INSTANCE);
parser.addParseListener(treeBuilder);
parser.removeErrorListeners();
parser.addErrorListener(new ErrorListener());
parser.transformation();
return treeBuilder.getExpression();
}
Aggregations