Search in sources :

Example 1 with ErrorListener

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();
}
Also used : ErrorListener(org.apache.metron.stellar.dsl.ErrorListener) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) TokenStream(org.antlr.v4.runtime.TokenStream) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) StellarLexer(org.apache.metron.stellar.common.generated.StellarLexer) StellarParser(org.apache.metron.stellar.common.generated.StellarParser) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream)

Example 2 with ErrorListener

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;
}
Also used : ErrorListener(org.apache.metron.stellar.dsl.ErrorListener) WindowParser(org.apache.metron.profiler.client.window.generated.WindowParser)

Example 3 with ErrorListener

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;
}
Also used : ErrorListener(org.apache.metron.stellar.dsl.ErrorListener) WindowLexer(org.apache.metron.profiler.client.window.generated.WindowLexer)

Aggregations

ErrorListener (org.apache.metron.stellar.dsl.ErrorListener)3 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 TokenStream (org.antlr.v4.runtime.TokenStream)1 WindowLexer (org.apache.metron.profiler.client.window.generated.WindowLexer)1 WindowParser (org.apache.metron.profiler.client.window.generated.WindowParser)1 StellarLexer (org.apache.metron.stellar.common.generated.StellarLexer)1 StellarParser (org.apache.metron.stellar.common.generated.StellarParser)1