use of org.apache.metron.stellar.dsl.ErrorListener 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();
}
use of org.apache.metron.stellar.dsl.ErrorListener in project metron by apache.
the class WindowProcessor method createParser.
private static WindowParser createParser(TokenStream tokens, Optional<WindowProcessor> windowProcessor) {
WindowParser parser = new WindowParser(tokens);
if (windowProcessor.isPresent()) {
parser.addParseListener(windowProcessor.get());
}
parser.removeErrorListeners();
parser.addErrorListener(new ErrorListener());
return parser;
}
use of org.apache.metron.stellar.dsl.ErrorListener in project metron by apache.
the class WindowProcessor method createTokenStream.
private static TokenStream createTokenStream(String statement) {
if (statement == null || isEmpty(statement.trim())) {
return null;
}
statement = statement.trim();
ANTLRInputStream input = new ANTLRInputStream(statement);
WindowLexer lexer = new WindowLexer(input);
lexer.removeErrorListeners();
lexer.addErrorListener(new ErrorListener());
TokenStream tokens = new CommonTokenStream(lexer);
return tokens;
}
Aggregations