Esempio n. 1
0
 public static FilterSpecRaw WalkFilterSpec(
     EsperEPL2GrammarParser.EventFilterExpressionContext ctx,
     PropertyEvalSpec propertyEvalSpec,
     IDictionary<ITree, ExprNode> astExprNodeMap)
 {
     var eventName = ASTUtil.UnescapeClassIdent(ctx.classIdentifier());
     var exprNodes = ctx.expressionList() != null
         ? ASTExprHelper.ExprCollectSubNodes(ctx.expressionList(), 0, astExprNodeMap)
         : new List<ExprNode>(1);
     return new FilterSpecRaw(eventName, exprNodes, propertyEvalSpec);
 }
Esempio n. 2
0
        private static string[] ParseParamsStreamNames(EsperEPL2GrammarParser.GopParamsItemContext item)
        {
            IList<string> paramNames = new List<string>(1);
            if (item.gopParamsItemMany() != null)
            {
                foreach (EsperEPL2GrammarParser.ClassIdentifierContext ctx in item.gopParamsItemMany().classIdentifier())
                {
                    paramNames.Add(ctx.GetText());
                }
            }
            else
            {
                paramNames.Add(ASTUtil.UnescapeClassIdent(item.classIdentifier()));
            }

            return paramNames.ToArray();
        }
Esempio n. 3
0
        /// <summary>
        ///     Walk an annotation root name or child node (nested annotations).
        /// </summary>
        /// <param name="ctx">annotation walk node</param>
        /// <param name="importService">for imports</param>
        /// <returns>annotation descriptor</returns>
        /// <throws>ASTWalkException if the walk failed</throws>
        public static AnnotationDesc Walk(
            EsperEPL2GrammarParser.AnnotationEnumContext ctx,
            ImportServiceCompileTime importService)
        {
            var name = ASTUtil.UnescapeClassIdent(ctx.classIdentifier());
            IList<Pair<string, object>> values = new List<Pair<string, object>>();
            if (ctx.elementValueEnum() != null)
            {
                var value = WalkValue(ctx.elementValueEnum(), importService);
                values.Add(new Pair<string, object>("Value", value));
            }
            else if (ctx.elementValuePairsEnum() != null)
            {
                WalkValuePairs(ctx.elementValuePairsEnum(), values, importService);
            }

            return new AnnotationDesc(name, values);
        }
Esempio n. 4
0
        public static IList<ColumnDesc> GetColTypeList(EsperEPL2GrammarParser.CreateColumnListContext ctx)
        {
            if (ctx == null)
            {
                return new EmptyList<ColumnDesc>();
            }

            IList<ColumnDesc> result = new List<ColumnDesc>(ctx.createColumnListElement().Length);
            foreach (var colctx in ctx.createColumnListElement())
            {
                var colname = colctx.classIdentifier();
                var name = ASTUtil.UnescapeClassIdent(colname);
                var classIdent = ASTClassIdentifierHelper.Walk(colctx.classIdentifierWithDimensions());
                result.Add(new ColumnDesc(name, classIdent?.ToEPL()));
            }

            return result;
        }
Esempio n. 5
0
        private static GraphOperatorOutputItemType ParseType(EsperEPL2GrammarParser.GopOutTypeParamContext ctx)
        {
            if (ctx.q != null)
            {
                return new GraphOperatorOutputItemType(true, null, null);
            }

            var className = ASTUtil.UnescapeClassIdent(ctx.gopOutTypeItem().classIdentifier());
            IList<GraphOperatorOutputItemType> typeParams = new List<GraphOperatorOutputItemType>();
            if (ctx.gopOutTypeItem().gopOutTypeList() != null)
            {
                IList<EsperEPL2GrammarParser.GopOutTypeParamContext> pctxs = ctx.gopOutTypeItem().gopOutTypeList().gopOutTypeParam();
                foreach (var pctx in pctxs)
                {
                    var type = ParseType(pctx);
                    typeParams.Add(type);
                }
            }

            return new GraphOperatorOutputItemType(false, className, typeParams);
        }
Esempio n. 6
0
        public static ClassIdentifierWArray Walk(EsperEPL2GrammarParser.ClassIdentifierWithDimensionsContext ctx)
        {
            if (ctx == null)
            {
                return null;
            }

            var name = ASTUtil.UnescapeClassIdent(ctx.classIdentifier());
            IList<EsperEPL2GrammarParser.DimensionsContext> dimensions = ctx.dimensions();

            if (dimensions.IsEmpty())
            {
                return new ClassIdentifierWArray(name);
            }

            var first = dimensions[0].IDENT();
            var keyword = first?.ToString().Trim().ToLowerInvariant();
            if (keyword != null && !keyword.Equals(ClassIdentifierWArray.PRIMITIVE_KEYWORD))
            {
                throw ASTWalkException.From("Invalid array keyword '" + keyword + "', expected '" + ClassIdentifierWArray.PRIMITIVE_KEYWORD + "'");
            }

            return new ClassIdentifierWArray(name, dimensions.Count, keyword != null);
        }
Esempio n. 7
0
        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);
        }