public static IList <string> GetLambdaGoesParams(EsperEPL2GrammarParser.ExpressionLambdaDeclContext ctx) { IList <string> parameters; if (ctx.i != null) { parameters = new List <string>(1); parameters.Add(ctx.i.GetText()); } else { parameters = ASTUtil.GetIdentList(ctx.columnListKeywordAllowed()); } return(parameters); }
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); }
private static CreateSchemaDesc GetSchemaDesc( EsperEPL2GrammarParser.CreateSchemaDefContext ctx, AssignedType assignedType) { var schemaName = ctx.name.Text; var columnTypes = GetColTypeList(ctx.createColumnList()); // get model-after types (could be multiple for variants) ISet<string> typeNames = new LinkedHashSet<string>(); if (ctx.variantList() != null) { IList<EsperEPL2GrammarParser.VariantListElementContext> variantCtxs = ctx.variantList().variantListElement(); foreach (var variantCtx in variantCtxs) { typeNames.Add(variantCtx.GetText()); } } // get inherited and start timestamp and end timestamps string startTimestamp = null; string endTimestamp = null; ISet<string> inherited = new LinkedHashSet<string>(); ISet<string> copyFrom = new LinkedHashSet<string>(); if (ctx.createSchemaQual() != null) { IList<EsperEPL2GrammarParser.CreateSchemaQualContext> qualCtxs = ctx.createSchemaQual(); foreach (var qualCtx in qualCtxs) { var qualName = qualCtx.i.Text.ToLowerInvariant(); var cols = ASTUtil.GetIdentList(qualCtx.columnList()); if (string.Equals(qualName, "inherits", StringComparison.InvariantCultureIgnoreCase)) { inherited.AddAll(cols); continue; } if (string.Equals(qualName, "starttimestamp", StringComparison.InvariantCultureIgnoreCase)) { startTimestamp = cols[0]; continue; } if (string.Equals(qualName, "endtimestamp", StringComparison.InvariantCultureIgnoreCase)) { endTimestamp = cols[0]; continue; } if (string.Equals(qualName, "copyfrom", StringComparison.InvariantCultureIgnoreCase)) { copyFrom.AddAll(cols); continue; } throw new EPException( "Expected 'inherits', 'starttimestamp', 'endtimestamp' or 'copyfrom' keyword after create-schema clause but encountered '" + qualName + "'"); } } return new CreateSchemaDesc(schemaName, typeNames, columnTypes, inherited, assignedType, startTimestamp, endTimestamp, copyFrom); }