コード例 #1
0
        private static String MakeProperty(EsperEPL2GrammarParser.EventPropertyAtomicContext ctx, String defaultNamespacePrefix)
        {
            String prefix = "";

            if (defaultNamespacePrefix != null)
            {
                prefix = defaultNamespacePrefix + ":";
            }

            String unescapedIdent = ASTUtil.UnescapeDot(ctx.eventPropertyIdent().GetText());

            if (ctx.lb != null)
            {
                int index         = IntValue.ParseString(ctx.number().GetText());
                int xPathPosition = index + 1;
                return('/' + prefix + unescapedIdent + "[position() = " + xPathPosition + ']');
            }

            if (ctx.lp != null)
            {
                String key = StringValue.ParseString(ctx.s.Text);
                return('/' + prefix + unescapedIdent + "[@id='" + key + "']");
            }

            return('/' + prefix + unescapedIdent);
        }
コード例 #2
0
        /// <summary>
        ///     Parse the AST constant node and return Object value.
        /// </summary>
        /// <param name="node">parse node for which to parse the string value</param>
        /// <returns>value matching AST node type</returns>
        public static object Parse(IParseTree node)
        {
            if (node is ITerminalNode)
            {
                var terminal = (ITerminalNode) node;
                switch (terminal.Symbol.Type)
                {
                    case EsperEPL2GrammarParser.BOOLEAN_TRUE:
                        return BoolValue.ParseString(terminal.GetText());

                    case EsperEPL2GrammarParser.BOOLEAN_FALSE:
                        return BoolValue.ParseString(terminal.GetText());

                    case EsperEPL2GrammarParser.VALUE_NULL:
                        return null;

                    default:
                        throw ASTWalkException.From("Encountered unexpected constant type " + terminal.Symbol.Type, terminal.Symbol);
                }
            }

            var ruleNode = (IRuleNode) node;
            var ruleIndex = ruleNode.RuleContext.RuleIndex;
            if (ruleIndex == EsperEPL2GrammarParser.RULE_number)
            {
                return ParseNumber(ruleNode, 1);
            }

            if (ruleIndex == EsperEPL2GrammarParser.RULE_numberconstant)
            {
                var number = FindChildRuleByType(ruleNode, EsperEPL2GrammarParser.RULE_number);
                if (ruleNode.ChildCount > 1)
                {
                    if (ASTUtil.IsTerminatedOfType(ruleNode.GetChild(0), EsperEPL2GrammarLexer.MINUS))
                    {
                        return ParseNumber(number, -1);
                    }

                    return ParseNumber(number, 1);
                }

                return ParseNumber(number, 1);
            }

            if (ruleIndex == EsperEPL2GrammarParser.RULE_stringconstant)
            {
                return StringValue.ParseString(node.GetText());
            }

            if (ruleIndex == EsperEPL2GrammarParser.RULE_constant)
            {
                return Parse(ruleNode.GetChild(0));
            }

            throw ASTWalkException.From("Encountered unrecognized constant", node.GetText());
        }
コード例 #3
0
        private static Property MakeProperty(
            ChainableWithArgsContext ctx,
            bool optional,
            bool rootedDynamic)
        {
            var name = ctx.chainableIdent().GetText();

            if (ctx.lp == null)
            {
                return(optional | rootedDynamic ? (Property) new DynamicSimpleProperty(name) : new SimpleProperty(name));
            }

            var func = ctx.libFunctionArgs().libFunctionArgItem()[0];
            var key  = StringValue.ParseString(func.GetText());

            return(optional ? (Property) new DynamicMappedProperty(name, key) : new MappedProperty(name, key));
        }
コード例 #4
0
ファイル: PropertyParser.cs プロジェクト: valmac/nesper
        private static Property MakeProperty(EsperEPL2GrammarParser.EventPropertyAtomicContext atomic, bool isRootedInDynamic)
        {
            var prop = ASTUtil.UnescapeDot(atomic.eventPropertyIdent().GetText());

            if (prop.Length == 0)
            {
                throw new PropertyAccessException("Invalid zero-length string provided as an event property name");
            }
            if (atomic.lb != null)
            {
                var index = IntValue.ParseString(atomic.ni.GetText());
                if (!isRootedInDynamic && atomic.q == null)
                {
                    return(new IndexedProperty(prop, index));
                }
                else
                {
                    return(new DynamicIndexedProperty(prop, index));
                }
            }
            else if (atomic.lp != null)
            {
                var key = StringValue.ParseString(atomic.s.Text);
                if (!isRootedInDynamic && atomic.q == null)
                {
                    return(new MappedProperty(prop, key));
                }
                else
                {
                    return(new DynamicMappedProperty(prop, key));
                }
            }
            else
            {
                if (!isRootedInDynamic && atomic.q1 == null)
                {
                    return(new SimpleProperty(prop));
                }
                else
                {
                    return(new DynamicSimpleProperty(prop));
                }
            }
        }