Search in sources :

Example 1 with DynamicContext

use of org.elasticsearch.painless.antlr.PainlessParser.DynamicContext in project elasticsearch by elastic.

the class Walker method visitOperator.

@Override
public ANode visitOperator(OperatorContext ctx) {
    AExpression expression = (AExpression) visit(ctx.unary());
    final Operation operation;
    if (ctx.BOOLNOT() != null) {
        operation = Operation.NOT;
    } else if (ctx.BWNOT() != null) {
        operation = Operation.BWNOT;
    } else if (ctx.ADD() != null) {
        operation = Operation.ADD;
    } else if (ctx.SUB() != null) {
        if (ctx.unary() instanceof ReadContext && ((ReadContext) ctx.unary()).chain() instanceof DynamicContext && ((DynamicContext) ((ReadContext) ctx.unary()).chain()).primary() instanceof NumericContext && ((DynamicContext) ((ReadContext) ctx.unary()).chain()).postfix().isEmpty()) {
            return expression;
        }
        operation = Operation.SUB;
    } else {
        throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
    }
    return new EUnary(location(ctx), operation, expression);
}
Also used : EUnary(org.elasticsearch.painless.node.EUnary) AExpression(org.elasticsearch.painless.node.AExpression) ReadContext(org.elasticsearch.painless.antlr.PainlessParser.ReadContext) Operation(org.elasticsearch.painless.Operation) DynamicContext(org.elasticsearch.painless.antlr.PainlessParser.DynamicContext) NumericContext(org.elasticsearch.painless.antlr.PainlessParser.NumericContext)

Aggregations

Operation (org.elasticsearch.painless.Operation)1 DynamicContext (org.elasticsearch.painless.antlr.PainlessParser.DynamicContext)1 NumericContext (org.elasticsearch.painless.antlr.PainlessParser.NumericContext)1 ReadContext (org.elasticsearch.painless.antlr.PainlessParser.ReadContext)1 AExpression (org.elasticsearch.painless.node.AExpression)1 EUnary (org.elasticsearch.painless.node.EUnary)1