Ejemplo n.º 1
0
        private static ExprChainedSpec GetLibFunctionChainSpec(ASTLibModelChainElement element, IDictionary <ITree, ExprNode> astExprNodeMap)
        {
            var methodName = ASTConstantHelper.RemoveTicks(element.FuncName);
            var parameters = ASTLibFunctionHelper.GetExprNodesLibFunc(element.Args, astExprNodeMap);

            return(new ExprChainedSpec(methodName, parameters, !element.HasLeftParen));
        }
Ejemplo n.º 2
0
        private static ASTLibModel GetModel(EsperEPL2GrammarParser.LibFunctionContext ctx, CommonTokenStream tokenStream)
        {
            var root = ctx.libFunctionWithClass();
            IList <EsperEPL2GrammarParser.LibFunctionNoClassContext> ctxElements = ctx.libFunctionNoClass();

            // there are no additional methods
            if (ctxElements == null || ctxElements.IsEmpty())
            {
                var classIdent = root.classIdentifier() == null ? null : ASTUtil.UnescapeClassIdent(root.classIdentifier());
                var ele        = FromRoot(root);
                return(new ASTLibModel(classIdent, Collections.SingletonList(ele)));
            }

            // add root and chain to just a list of elements
            IList <ASTLibModelChainElement> chainElements = new List <ASTLibModelChainElement>(ctxElements.Count + 1);
            var rootElement = FromRoot(root);

            chainElements.Add(rootElement);
            foreach (var chainedCtx in ctxElements)
            {
                var chainedElement = new ASTLibModelChainElement(chainedCtx.funcIdentChained().GetText(), chainedCtx.libFunctionArgs(), chainedCtx.l != null);
                chainElements.Add(chainedElement);
            }

            // determine/remove the list of chain elements, from the start and uninterrupted, that don't have parameters (no parenthesis 'l')
            IList <ASTLibModelChainElement> chainElementsNoArgs = new List <ASTLibModelChainElement>(chainElements.Count);

            for (int ii = 0; ii < chainElements.Count; ii++)
            {
                var element = chainElements[ii];
                if (!element.HasLeftParen)
                {
                    // has no parenthesis, therefore part of class identifier
                    chainElementsNoArgs.Add(element);
                    chainElements.RemoveAt(ii--);
                }
                else
                {
                    // else stop here
                    break;
                }
            }

            // write the class identifier including the no-arg chain elements
            var classIdentBuf = new StringBuilder();
            var delimiter     = "";

            if (root.classIdentifier() != null)
            {
                classIdentBuf.Append(ASTUtil.UnescapeClassIdent(root.classIdentifier()));
                delimiter = ".";
            }
            foreach (var noarg in chainElementsNoArgs)
            {
                classIdentBuf.Append(delimiter);
                classIdentBuf.Append(noarg.FuncName);
                delimiter = ".";
            }

            if (chainElements.IsEmpty())
            {
                // would this be an event property, but then that is handled greedily by parser
                throw ASTWalkException.From("Encountered unrecognized lib function call", tokenStream, ctx);
            }

            // class ident can be null if empty
            var classIdentifierString = classIdentBuf.ToString();
            var classIdentifier       = classIdentifierString.Length > 0 ? classIdentifierString : null;

            return(new ASTLibModel(classIdentifier, chainElements));
        }