private static Chainable GetChainable( EsperEPL2GrammarParser.ChainableWithArgsContext ctx, bool optional, IDictionary <ITree, ExprNode> astExprNodeMap) { var distinct = ctx.libFunctionArgs() != null && ctx.libFunctionArgs().DISTINCT() != null; var nameUnescaped = ctx.chainableIdent().GetText(); var name = StringValue.RemoveTicks(nameUnescaped); if (ctx.lp == null) { return(new ChainableName(distinct, optional, name, nameUnescaped)); } IList <ExprNode> @params = ASTLambdaHelper.GetExprNodesLibFunc(ctx.libFunctionArgs(), astExprNodeMap); return(new ChainableCall(distinct, optional, name, nameUnescaped, @params)); }
public static MyPair WalkExpressionDecl( EsperEPL2GrammarParser.ExpressionDeclContext ctx, IList<string> scriptBodies, IDictionary<ITree, ExprNode> astExprNodeMap, CommonTokenStream tokenStream) { var name = ctx.name.Text; if (ctx.alias != null) { if (!ctx.alias.Text.ToLowerInvariant().Trim().Equals("alias")) { throw ASTWalkException.From( "For expression alias '" + name + "' expecting 'alias' keyword but received '" + ctx.alias.Text + "'"); } if (ctx.columnList() != null) { throw ASTWalkException.From( "For expression alias '" + name + "' expecting no parameters but received '" + tokenStream.GetText(ctx.columnList()) + "'"); } if (ctx.expressionDef() != null && ctx.expressionDef().expressionLambdaDecl() != null) { throw ASTWalkException.From( "For expression alias '" + name + "' expecting an expression without parameters but received '" + tokenStream.GetText(ctx.expressionDef().expressionLambdaDecl()) + "'"); } if (ctx.expressionDef().stringconstant() != null) { throw ASTWalkException.From("For expression alias '" + name + "' expecting an expression but received a script"); } var node = ASTExprHelper.ExprCollectSubNodes(ctx, 0, astExprNodeMap)[0]; var alias = ctx.name.Text; var expressionUnmap = StatementSpecMapper.Unmap(node); var decl = new ExpressionDeclItem(alias, new string[0], true); decl.OptionalSoda = expressionUnmap; return new MyPair(decl, null); } if (ctx.expressionDef().stringconstant() != null) { var expressionText = scriptBodies.DeleteAt(0); var parameters = ASTUtil.GetIdentList(ctx.columnList()); var optionalReturnType = ctx.classIdentifier() == null ? null : ASTUtil.UnescapeClassIdent(ctx.classIdentifier()); var optionalReturnTypeArray = ctx.array != null; var optionalDialect = ctx.expressionDialect() == null ? null : ctx.expressionDialect().d.Text; var optionalEventTypeName = ASTTypeExpressionAnnoHelper.ExpectMayTypeAnno(ctx.typeExpressionAnnotation(), tokenStream); var script = new ExpressionScriptProvided( name, expressionText, parameters.ToArray(), optionalReturnType, optionalReturnTypeArray, optionalEventTypeName, optionalDialect); return new MyPair(null, script); } var ctxexpr = ctx.expressionDef(); var inner = ASTExprHelper.ExprCollectSubNodes(ctxexpr.expression(), 0, astExprNodeMap)[0]; IList<string> parametersNames = new EmptyList<string>(); var lambdactx = ctxexpr.expressionLambdaDecl(); if (ctxexpr.expressionLambdaDecl() != null) { parametersNames = ASTLambdaHelper.GetLambdaGoesParams(lambdactx); } var expression = StatementSpecMapper.Unmap(inner); var expr = new ExpressionDeclItem(name, parametersNames.ToArray(), false); expr.OptionalSoda = expression; return new MyPair(expr, null); }