Search in sources :

Example 1 with LamtypeContext

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

the class Walker method visitLambda.

@Override
public ANode visitLambda(LambdaContext ctx) {
    reserved.push(new FunctionReserved());
    List<String> paramTypes = new ArrayList<>();
    List<String> paramNames = new ArrayList<>();
    List<AStatement> statements = new ArrayList<>();
    for (LamtypeContext lamtype : ctx.lamtype()) {
        if (lamtype.decltype() == null) {
            paramTypes.add("def");
        } else {
            paramTypes.add(lamtype.decltype().getText());
        }
        paramNames.add(lamtype.ID().getText());
    }
    if (ctx.expression() != null) {
        // single expression
        AExpression expression = (AExpression) visit(ctx.expression());
        statements.add(new SReturn(location(ctx), expression));
    } else {
        for (StatementContext statement : ctx.block().statement()) {
            statements.add((AStatement) visit(statement));
        }
    }
    String name = nextLambda();
    return new ELambda(name, (FunctionReserved) reserved.pop(), location(ctx), paramTypes, paramNames, statements);
}
Also used : AStatement(org.elasticsearch.painless.node.AStatement) LamtypeContext(org.elasticsearch.painless.antlr.PainlessParser.LamtypeContext) ELambda(org.elasticsearch.painless.node.ELambda) FunctionReserved(org.elasticsearch.painless.node.SFunction.FunctionReserved) AExpression(org.elasticsearch.painless.node.AExpression) ArrayList(java.util.ArrayList) EString(org.elasticsearch.painless.node.EString) SReturn(org.elasticsearch.painless.node.SReturn) StatementContext(org.elasticsearch.painless.antlr.PainlessParser.StatementContext)

Aggregations

ArrayList (java.util.ArrayList)1 LamtypeContext (org.elasticsearch.painless.antlr.PainlessParser.LamtypeContext)1 StatementContext (org.elasticsearch.painless.antlr.PainlessParser.StatementContext)1 AExpression (org.elasticsearch.painless.node.AExpression)1 AStatement (org.elasticsearch.painless.node.AStatement)1 ELambda (org.elasticsearch.painless.node.ELambda)1 EString (org.elasticsearch.painless.node.EString)1 FunctionReserved (org.elasticsearch.painless.node.SFunction.FunctionReserved)1 SReturn (org.elasticsearch.painless.node.SReturn)1