Package com.espertech.esper.epl.parse

Source Code of com.espertech.esper.epl.parse.ASTExpressionDeclHelper

/**************************************************************************************
* Copyright (C) 2008 EsperTech, Inc. All rights reserved.                            *
* http://esper.codehaus.org                                                          *
* http://www.espertech.com                                                           *
* ---------------------------------------------------------------------------------- *
* The software in this package is published under the terms of the GPL license       *
* a copy of which has been included with this distribution in the license.txt file.  *
**************************************************************************************/
package com.espertech.esper.epl.parse;

import com.espertech.esper.collection.Pair;
import com.espertech.esper.epl.expression.ExprNode;
import com.espertech.esper.epl.generated.EsperEPL2GrammarParser;
import com.espertech.esper.epl.spec.ExpressionDeclItem;
import com.espertech.esper.epl.spec.ExpressionScriptProvided;
import org.antlr.v4.runtime.tree.Tree;

import java.util.Collections;
import java.util.List;
import java.util.Map;

public class ASTExpressionDeclHelper
{
    public static Pair<ExpressionDeclItem, ExpressionScriptProvided> walkExpressionDecl(EsperEPL2GrammarParser.ExpressionDeclContext ctx, List<String> scriptBodies, Map<Tree, ExprNode> astExprNodeMap) {

        String name = ctx.name.getText();

        if (ctx.expressionDef().stringconstant() != null) {
            String expressionText = scriptBodies.remove(0);
            List<String> parameters = ASTUtil.getIdentList(ctx.columnList());
            String optionalReturnType = ctx.classIdentifier() == null ? null : ASTUtil.unescapeClassIdent(ctx.classIdentifier());
            boolean optionalReturnTypeArray = ctx.array != null;
            String optionalDialect = ctx.expressionDialect() == null ? null : ctx.expressionDialect().d.getText();
            ExpressionScriptProvided script = new ExpressionScriptProvided(name, expressionText, parameters,
                    optionalReturnType, optionalReturnTypeArray, optionalDialect);
            return new Pair<ExpressionDeclItem, ExpressionScriptProvided>(null, script);
        }

        EsperEPL2GrammarParser.ExpressionDefContext ctxexpr = ctx.expressionDef();
        ExprNode inner = ASTExprHelper.exprCollectSubNodes(ctxexpr.expression(), 0, astExprNodeMap).get(0);

        List<String> parametersNames = Collections.emptyList();
        EsperEPL2GrammarParser.ExpressionLambdaDeclContext lambdactx = ctxexpr.expressionLambdaDecl();
        if (ctxexpr.expressionLambdaDecl() != null) {
            parametersNames = ASTLibFunctionHelper.getLambdaGoesParams(lambdactx);
        }

        ExpressionDeclItem expr = new ExpressionDeclItem(name, parametersNames, inner);
        return new Pair<ExpressionDeclItem, ExpressionScriptProvided>(expr, null);
    }
}
TOP

Related Classes of com.espertech.esper.epl.parse.ASTExpressionDeclHelper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.