private static string ParseXPathString(XPathLexer lexer, XmlNamespaceManager namespaceManager, bool throwOnFailure)
        {
            int firstTokenChar = lexer.FirstTokenChar;

            if (lexer.MoveNext())
            {
                XPathToken    token   = lexer.Token;
                StringBuilder builder = new StringBuilder(ParseXPathString(lexer, namespaceManager, throwOnFailure));
                if (XPathTokenID.NameTest == token.TokenID)
                {
                    string prefix = token.Prefix;
                    if (!string.IsNullOrEmpty(prefix))
                    {
                        string str3 = namespaceManager.LookupNamespace(prefix);
                        if (!string.IsNullOrEmpty(str3))
                        {
                            builder = builder.Replace(prefix, str3, firstTokenChar, prefix.Length);
                        }
                        else if (throwOnFailure)
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new IndexOutOfRangeException(System.ServiceModel.SR.GetString("ConfigXPathNamespacePrefixNotFound", new object[] { prefix })));
                        }
                    }
                }
                return(builder.ToString());
            }
            return(lexer.ConsumedSubstring());
        }
Beispiel #2
0
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            object lhs = RelationalExpr.parse(rootParser, lexer);

            Dictionary <string, string> equalityTypes = new Dictionary <string, string>();

            equalityTypes.Add("=", XPathAnalyzer.ExprType.EQUALITY);
            equalityTypes.Add("!=", XPathAnalyzer.ExprType.INEQUALITY);

            if (!string.IsNullOrEmpty(lexer.peak()) && equalityTypes.ContainsKey(lexer.peak()))
            {
                string op = lexer.next();

                object rhs = parse(rootParser, lexer);

                Dictionary <string, object> list = new Dictionary <string, object>();
                list.Add("type", equalityTypes[op]);
                list.Add("lhs", lhs);
                list.Add("rhs", rhs);
                return(list);
            }
            else
            {
                return(lhs);
            }
        }
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            object lhs = UnaryExpr.parse(rootParser, lexer);

            Dictionary<string, string> multiplicativeTypes = new Dictionary<string, string>();
            multiplicativeTypes.Add("*", XPathAnalyzer.ExprType.MULTIPLICATIVE);
            multiplicativeTypes.Add("div", XPathAnalyzer.ExprType.DIVISIONAL);
            multiplicativeTypes.Add("mod", XPathAnalyzer.ExprType.MODULUS);

            if (!string.IsNullOrEmpty(lexer.peak()) && multiplicativeTypes.ContainsKey(lexer.peak()))
            {
                string op = lexer.next();

                object rhs = parse(rootParser, lexer);

                Dictionary<string, object> list = new Dictionary<string, object>();
                list.Add("type", multiplicativeTypes[op]);
                list.Add("lhs", lhs);
                list.Add("rhs", rhs);
                return list;
            }
            else
            {
                return lhs;
            }
        }
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            object lhs = MultiplicativeExpr.parse(rootParser, lexer);

            Dictionary<string, string> additiveTypes = new Dictionary<string, string>();
            additiveTypes.Add("+", XPathAnalyzer.ExprType.ADDITIVE);
            additiveTypes.Add("-", XPathAnalyzer.ExprType.SUBTRACTIVE);

            if (!string.IsNullOrEmpty(lexer.peak()) && additiveTypes.ContainsKey(lexer.peak()))
            {
                string op = lexer.next();

                object rhs = parse(rootParser, lexer);

                Dictionary<string, object> list = new Dictionary<string, object>();
                list.Add("type", additiveTypes[op]);
                list.Add("lhs", lhs);
                list.Add("rhs", rhs);
                return list;
            }
            else
            {
                return lhs;
            }
        }
Beispiel #5
0
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            object primary = PrimaryExpr.parse(rootParser, lexer);


            if (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals("["))
            {
                Dictionary <string, object> filter = new Dictionary <string, object>();
                filter.Add("type", XPathAnalyzer.ExprType.FILTER);
                filter.Add("primary", primary);
                filter.Add("predicates", new List <object>());


                while (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals("["))
                {
                    ((List <object>)filter["predicates"]).Add(Predicate.parse(rootParser, lexer));
                }

                return(filter);
            }
            else
            {
                return(primary);
            }
        }
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            object lhs = UnaryExpr.parse(rootParser, lexer);

            Dictionary <string, string> multiplicativeTypes = new Dictionary <string, string>();

            multiplicativeTypes.Add("*", XPathAnalyzer.ExprType.MULTIPLICATIVE);
            multiplicativeTypes.Add("div", XPathAnalyzer.ExprType.DIVISIONAL);
            multiplicativeTypes.Add("mod", XPathAnalyzer.ExprType.MODULUS);

            if (!string.IsNullOrEmpty(lexer.peak()) && multiplicativeTypes.ContainsKey(lexer.peak()))
            {
                string op = lexer.next();

                object rhs = parse(rootParser, lexer);

                Dictionary <string, object> list = new Dictionary <string, object>();
                list.Add("type", multiplicativeTypes[op]);
                list.Add("lhs", lhs);
                list.Add("rhs", rhs);
                return(list);
            }
            else
            {
                return(lhs);
            }
        }
Beispiel #7
0
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            object lhs = AdditiveExpr.parse(rootParser, lexer);

            Dictionary <string, string> relationalTypes = new Dictionary <string, string>();

            relationalTypes.Add("<", XPathAnalyzer.ExprType.LESS_THAN);
            relationalTypes.Add(">", XPathAnalyzer.ExprType.GREATER_THAN);
            relationalTypes.Add("<=", XPathAnalyzer.ExprType.LESS_THAN_OR_EQUAL);
            relationalTypes.Add(">=", XPathAnalyzer.ExprType.GREATER_THAN_OR_EQUAL);


            if (!string.IsNullOrEmpty(lexer.peak()) && relationalTypes.ContainsKey(lexer.peak()))
            {
                string op = lexer.next();

                object rhs = parse(rootParser, lexer);

                Dictionary <string, object> list = new Dictionary <string, object>();
                list.Add("type", relationalTypes[op]);
                list.Add("lhs", lhs);
                list.Add("rhs", rhs);
                return(list);
            }
            else
            {
                return(lhs);
            }
        }
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            object lhs = MultiplicativeExpr.parse(rootParser, lexer);

            Dictionary <string, string> additiveTypes = new Dictionary <string, string>();

            additiveTypes.Add("+", XPathAnalyzer.ExprType.ADDITIVE);
            additiveTypes.Add("-", XPathAnalyzer.ExprType.SUBTRACTIVE);


            if (!string.IsNullOrEmpty(lexer.peak()) && additiveTypes.ContainsKey(lexer.peak()))
            {
                string op = lexer.next();

                object rhs = parse(rootParser, lexer);

                Dictionary <string, object> list = new Dictionary <string, object>();
                list.Add("type", additiveTypes[op]);
                list.Add("lhs", lhs);
                list.Add("rhs", rhs);
                return(list);
            }
            else
            {
                return(lhs);
            }
        }
Beispiel #9
0
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            Dictionary <string, object> relativeLocation = new Dictionary <string, object>();

            relativeLocation.Add("type", XPathAnalyzer.ExprType.RELATIVE_LOCATION_PATH);
            relativeLocation.Add("steps", new List <Dictionary <string, object> >());

            ((List <Dictionary <string, object> >)relativeLocation["steps"]).Add(Step.parse(rootParser, lexer));


            while (!lexer.empty() && (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak()[0] == '/'))
            {
                if (lexer.next().Equals("/"))
                {
                    ((List <Dictionary <string, object> >)relativeLocation["steps"]).Add(Step.parse(rootParser, lexer));
                }
                else
                {
                    Dictionary <string, object> itm = new Dictionary <string, object>();
                    itm.Add("axis", XPathAnalyzer.AxisSpecifier.DESCENDANT_OR_SELF);

                    Dictionary <string, object> test = new Dictionary <string, object>();
                    test.Add("type", XPathAnalyzer.NodeType.NODE);

                    itm.Add("test", test);


                    ((List <Dictionary <string, object> >)relativeLocation["steps"]).Add(itm);

                    ((List <Dictionary <string, object> >)relativeLocation["steps"]).Add(Step.parse(rootParser, lexer));
                }
            }

            return(relativeLocation);
        }
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            Dictionary<string, object> absoluteLocation = new Dictionary<string, object>();
            absoluteLocation.Add("type", XPathAnalyzer.ExprType.ABSOLUTE_LOCATION_PATH);

            while (!lexer.empty() && (lexer.peak()[0] == '/'))
            {
                if(!absoluteLocation.ContainsKey("steps"))
                    absoluteLocation.Add("steps", new List<Dictionary<string, object>>());

                if (lexer.next().Equals("/"))
                {
                    var next = lexer.peak();

                    if (!lexer.empty() && (next.Equals(".") || next.Equals("..") || next.Equals("@") || next.Equals("*") || XPathLexer.RegexTest(next, @"(?![0 - 9])[\w]")))
                    {
                        ((List<Dictionary<string, object>>)absoluteLocation["steps"]).Add(Step.parse(rootParser, lexer));
                    }
                }else
                {
                    Dictionary<string, object> itm = new Dictionary<string, object>();
                    itm.Add("axis", XPathAnalyzer.AxisSpecifier.DESCENDANT_OR_SELF);

                    Dictionary<string, object> test = new Dictionary<string, object>();
                    test.Add("type", XPathAnalyzer.NodeType.NODE);

                    itm.Add("test", test);

                    ((List<Dictionary<string, object>>)absoluteLocation["steps"]).Add(itm);

                    ((List<Dictionary<string, object>>)absoluteLocation["steps"]).Add(Step.parse(rootParser, lexer));
                }
            }
            return absoluteLocation;
        }
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            object lhs = RelationalExpr.parse(rootParser, lexer);

            Dictionary<string, string> equalityTypes = new Dictionary<string, string>();
            equalityTypes.Add("=", XPathAnalyzer.ExprType.EQUALITY);
            equalityTypes.Add("!=", XPathAnalyzer.ExprType.INEQUALITY);

            if (!string.IsNullOrEmpty(lexer.peak()) && equalityTypes.ContainsKey(lexer.peak()))
            {
                string op = lexer.next();

                object rhs = parse(rootParser, lexer);

                Dictionary<string, object> list = new Dictionary<string, object>();
                list.Add("type", equalityTypes[op]);
                list.Add("lhs", lhs);
                list.Add("rhs", rhs);
                return list;
            }
            else
            {
                return lhs;
            }
        }
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            object lhs = AdditiveExpr.parse(rootParser, lexer);

            Dictionary<string, string> relationalTypes = new Dictionary<string, string>();
            relationalTypes.Add("<", XPathAnalyzer.ExprType.LESS_THAN);
            relationalTypes.Add(">", XPathAnalyzer.ExprType.GREATER_THAN);
            relationalTypes.Add("<=", XPathAnalyzer.ExprType.LESS_THAN_OR_EQUAL);
            relationalTypes.Add(">=", XPathAnalyzer.ExprType.GREATER_THAN_OR_EQUAL);

            if (!string.IsNullOrEmpty(lexer.peak()) && relationalTypes.ContainsKey(lexer.peak()))
            {
                string op = lexer.next();

                object rhs = parse(rootParser, lexer);

                Dictionary<string, object> list = new Dictionary<string, object>();
                list.Add("type", relationalTypes[op]);
                list.Add("lhs", lhs);
                list.Add("rhs", rhs);
                return list;
            }
            else
            {
                return lhs;
            }
        }
Beispiel #13
0
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            Dictionary <string, object> funCall = new Dictionary <string, object>();

            funCall.Add("type", XPathAnalyzer.ExprType.FUNCTION_CALL);
            funCall.Add("name", lexer.next());

            lexer.next();


            if (lexer.peak().Equals(")"))
            {
                lexer.next();
            }
            else
            {
                funCall.Add("args", new List <object>());

                while (!lexer.peak().Equals(")"))
                {
                    ((List <object>)funCall["args"]).Add(rootParser.parse(lexer));

                    if (lexer.peak().Equals(","))
                    {
                        lexer.next();
                    }
                }


                lexer.next();
            }

            return(funCall);
        }
Beispiel #14
0
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            string token = lexer.peak();
            char   ch    = token[0];

            if (ch == '(')
            {
                lexer.next();

                var expr = rootParser.parse(lexer);

                if (!lexer.next().Equals(")"))
                {
                    throw new Exception("Error: Unclosed parentheses");
                }

                return(expr);
            }

            if (ch == '"' || ch == '\'')
            {
                lexer.next();

                Dictionary <string, object> r = new Dictionary <string, object>();
                r.Add("type", XPathAnalyzer.ExprType.LITERAL);
                r.Add("string", token.Substring(1, (token.Length - 1) - 1));//token.slice(1, -1)

                return(r);
            }

            if (ch == '$')
            {
                throw new Exception("Error: Variable reference are not implemented");
            }

            if (XPathLexer.RegexTest(token, @"^\d+$") || XPathLexer.RegexTest(token, @"^(\d+)?\.\d+$"))
            {
                lexer.next();

                Dictionary <string, object> r = new Dictionary <string, object>();
                r.Add("type", XPathAnalyzer.ExprType.NUMBER);
                r.Add("number", float.Parse(token, CultureInfo.InvariantCulture));//token.slice(1, -1)

                return(r);
            }

            if (lexer.peak(1) == "(" && !NodeTypeValidator.isValid(lexer.peak()))
            {
                return(FunctionCall.parse(rootParser, lexer));
            }

            return(null);
            //throw new Exception("Error: Unhandle Expresion!");
        }
 public static object parse(Expr rootParser, XPathLexer lexer)
 {
     string token = lexer.peak();
     if(!string.IsNullOrEmpty(lexer.peak()) && token[0] == '/')
     {
         return AbsoluteLocationPath.parse(rootParser, lexer);
     }else
     {
         return RelativeLocationPath.parse(rootParser, lexer);
     }
 }
Beispiel #16
0
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            string token = lexer.peak();
            char ch = token[0];

            if (ch == '(')
            {
                lexer.next();

                var expr = rootParser.parse(lexer);

                if (!lexer.next().Equals(")"))
                {
                    throw new Exception("Error: Unclosed parentheses");
                }

                return expr;
            }

            if (ch == '"' || ch == '\'')
            {
                lexer.next();

                Dictionary<string, object> r = new Dictionary<string, object>();
                r.Add("type", XPathAnalyzer.ExprType.LITERAL);
                r.Add("string", token.Substring(1, (token.Length - 1) - 1));//token.slice(1, -1)

                return r;
            }

            if (ch == '$')
            {
                throw new Exception("Error: Variable reference are not implemented");
            }

            if (XPathLexer.RegexTest(token, @"^\d+$") || XPathLexer.RegexTest(token, @"^(\d+)?\.\d+$"))
            {
                lexer.next();

                Dictionary<string, object> r = new Dictionary<string, object>();
                r.Add("type", XPathAnalyzer.ExprType.NUMBER);
                r.Add("number", float.Parse(token, CultureInfo.InvariantCulture));//token.slice(1, -1)

                return r;
            }

            if (lexer.peak(1) == "(" && !NodeTypeValidator.isValid(lexer.peak()))
            {
                return FunctionCall.parse(rootParser, lexer);
            }

            return null;
            //throw new Exception("Error: Unhandle Expresion!");
        }
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            string token = lexer.peak();

            if (!string.IsNullOrEmpty(lexer.peak()) && token[0] == '/')
            {
                return(AbsoluteLocationPath.parse(rootParser, lexer));
            }
            else
            {
                return(RelativeLocationPath.parse(rootParser, lexer));
            }
        }
Beispiel #18
0
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            lexer.next();

            var predicate = rootParser.parse(lexer);

            if (!lexer.next().Equals("]"))
            {
                throw new Exception("Error: Unclosed brackets");
            }

            return predicate;
        }
Beispiel #19
0
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            lexer.next();

            var predicate = rootParser.parse(lexer);

            if (!lexer.next().Equals("]"))
            {
                throw new Exception("Error: Unclosed brackets");
            }

            return(predicate);
        }
Beispiel #20
0
        public static bool isValidOp(XPathLexer lexer)
        {
            if (string.IsNullOrEmpty(lexer.peak()))
                return false;

            char ch = lexer.peak()[0];

            return ch == '(' ||
             ch == '\\' ||
             ch == '\'' ||
             ch == '$' ||
            XPathLexer.RegexTest(ch + "", @"^\d+$") ||
              XPathLexer.RegexTest(ch + "", @"^d+$^(\d+)?\.\d+$") ||
             ((lexer.peak(1) != null) && (lexer.peak(1).Equals("(")) && !NodeTypeValidator.isValid(lexer.peak()));
        }
Beispiel #21
0
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            if (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals("-"))
            {
                lexer.next();

                Dictionary<string, object> list = new Dictionary<string, object>();
                list.Add("type", XPathAnalyzer.ExprType.NEGATION);
                list.Add("lhs", parse(rootParser, lexer));
                return list;
            }
            else
            {
                return UnionExpr.parse(rootParser, lexer);
            }
        }
Beispiel #22
0
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            if (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals("-"))
            {
                lexer.next();

                Dictionary <string, object> list = new Dictionary <string, object>();
                list.Add("type", XPathAnalyzer.ExprType.NEGATION);
                list.Add("lhs", parse(rootParser, lexer));
                return(list);
            }
            else
            {
                return(UnionExpr.parse(rootParser, lexer));
            }
        }
Beispiel #23
0
        public static bool isValidOp(XPathLexer lexer)
        {
            if (string.IsNullOrEmpty(lexer.peak()))
            {
                return(false);
            }

            char ch = lexer.peak()[0];

            return(ch == '(' ||
                   ch == '\\' ||
                   ch == '\'' ||
                   ch == '$' ||
                   XPathLexer.RegexTest(ch + "", @"^\d+$") ||
                   XPathLexer.RegexTest(ch + "", @"^d+$^(\d+)?\.\d+$") ||
                   ((lexer.peak(1) != null) && (lexer.peak(1).Equals("(")) && !NodeTypeValidator.isValid(lexer.peak())));
        }
Beispiel #24
0
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            if (FilterExpr.isValidOp(lexer))
            {
                object filter = FilterExpr.parse(rootParser, lexer);

                if (!lexer.empty() && (lexer.peak()[0] == '/'))
                {
                    Dictionary<string, object> path = new Dictionary<string, object>();
                    path.Add("type", XPathAnalyzer.ExprType.PATH);
                    path.Add("filter", filter);
                    path.Add("steps", new List<Dictionary<string, object>>());

                    while (!lexer.empty() && (lexer.peak()[0] == '/'))
                    {
                        if (lexer.next().Equals("//"))
                        {
                            Dictionary<string, object> itm = new Dictionary<string, object>();
                            itm.Add("axis", XPathAnalyzer.AxisSpecifier.DESCENDANT_OR_SELF);

                            Dictionary<string, string> test = new Dictionary<string, string>();
                            test.Add("type", XPathAnalyzer.NodeType.NODE);

                            itm.Add("test", test);

                            ((List<Dictionary<string, object>>)path["steps"]).Add(itm);
                        }

                        ((List<Dictionary<string, object>>)path["steps"]).Add(Step.parse(rootParser, lexer));
                    }

                    return path;
                }
                else
                {
                    return filter;
                }

            }
            else
            {
                return LocationPath.parse(rootParser, lexer);
            }
        }
Beispiel #25
0
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            if (FilterExpr.isValidOp(lexer))
            {
                object filter = FilterExpr.parse(rootParser, lexer);

                if (!lexer.empty() && (lexer.peak()[0] == '/'))
                {
                    Dictionary <string, object> path = new Dictionary <string, object>();
                    path.Add("type", XPathAnalyzer.ExprType.PATH);
                    path.Add("filter", filter);
                    path.Add("steps", new List <Dictionary <string, object> >());

                    while (!lexer.empty() && (lexer.peak()[0] == '/'))
                    {
                        if (lexer.next().Equals("//"))
                        {
                            Dictionary <string, object> itm = new Dictionary <string, object>();
                            itm.Add("axis", XPathAnalyzer.AxisSpecifier.DESCENDANT_OR_SELF);

                            Dictionary <string, string> test = new Dictionary <string, string>();
                            test.Add("type", XPathAnalyzer.NodeType.NODE);

                            itm.Add("test", test);


                            ((List <Dictionary <string, object> >)path["steps"]).Add(itm);
                        }

                        ((List <Dictionary <string, object> >)path["steps"]).Add(Step.parse(rootParser, lexer));
                    }

                    return(path);
                }
                else
                {
                    return(filter);
                }
            }
            else
            {
                return(LocationPath.parse(rootParser, lexer));
            }
        }
Beispiel #26
0
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            Dictionary<string, object> ret = new Dictionary<string, object>();

            if (!string.IsNullOrEmpty(lexer.peak()) &&  lexer.peak().Equals("*"))
            {
                lexer.next();

                ret.Add("name", "*");
                return ret;
            }

            if (!string.IsNullOrEmpty(lexer.peak(1)) && lexer.peak(1).Equals("("))
            {
                if (NodeTypeValidator.isValid(lexer.peak()))
                {
                    ret.Add("type", lexer.next());
                    lexer.next();

                    if (lexer.peak().Equals(")"))
                    {
                        lexer.next();
                    }
                    else
                    {
                        ret.Add("name", lexer.next());
                        lexer.next();
                    }

                    return ret;
                }
                else
                {
                    throw new Exception("Error: Unexpected token " + lexer.peak());

                }
            }

            ret = new Dictionary<string, object>();
            ret.Add("name", lexer.next());
            return ret;
        }
Beispiel #27
0
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            Dictionary <string, object> ret = new Dictionary <string, object>();

            if (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals("*"))
            {
                lexer.next();

                ret.Add("name", "*");
                return(ret);
            }

            if (!string.IsNullOrEmpty(lexer.peak(1)) && lexer.peak(1).Equals("("))
            {
                if (NodeTypeValidator.isValid(lexer.peak()))
                {
                    ret.Add("type", lexer.next());
                    lexer.next();

                    if (lexer.peak().Equals(")"))
                    {
                        lexer.next();
                    }
                    else
                    {
                        ret.Add("name", lexer.next());
                        lexer.next();
                    }

                    return(ret);
                }
                else
                {
                    throw new Exception("Error: Unexpected token " + lexer.peak());
                }
            }


            ret = new Dictionary <string, object>();
            ret.Add("name", lexer.next());
            return(ret);
        }
Beispiel #28
0
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            object lhs = AndExpr.parse(rootParser, lexer);

            if (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals("or"))
            {
                lexer.next();

                object rhs = parse(rootParser, lexer);

                Dictionary<string, object> list = new Dictionary<string, object>();
                list.Add("type", XPathAnalyzer.ExprType.OR);
                list.Add("lhs", lhs);
                list.Add("rhs", rhs);
                return list;
            }else
            {
                return lhs;
            }
        }
Beispiel #29
0
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            object lhs = AndExpr.parse(rootParser, lexer);

            if (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals("or"))
            {
                lexer.next();

                object rhs = parse(rootParser, lexer);

                Dictionary <string, object> list = new Dictionary <string, object>();
                list.Add("type", XPathAnalyzer.ExprType.OR);
                list.Add("lhs", lhs);
                list.Add("rhs", rhs);
                return(list);
            }
            else
            {
                return(lhs);
            }
        }
Beispiel #30
0
        static string ParseXPathString(XPathLexer lexer, XmlNamespaceManager namespaceManager, bool throwOnFailure)
        {
            string retVal = String.Empty;

            int currentTokenStart = lexer.FirstTokenChar;

            if (lexer.MoveNext())
            {
                XPathToken    token       = lexer.Token;
                StringBuilder xPathString = new StringBuilder(XPathMessageFilterElementComparer.ParseXPathString(lexer, namespaceManager, throwOnFailure));

                if (XPathTokenID.NameTest == token.TokenID)
                {
                    string nsPrefix = token.Prefix;
                    if (!String.IsNullOrEmpty(nsPrefix))
                    {
                        string ns = namespaceManager.LookupNamespace(nsPrefix);
                        if (!String.IsNullOrEmpty(ns))
                        {
                            xPathString = xPathString.Replace(nsPrefix, ns, currentTokenStart, nsPrefix.Length);
                        }
                        else
                        {
                            if (throwOnFailure)
                            {
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new IndexOutOfRangeException(SR.GetString(SR.ConfigXPathNamespacePrefixNotFound, nsPrefix)));
                            }
                        }
                    }
                }

                retVal = xPathString.ToString();
            }
            else
            {
                retVal = lexer.ConsumedSubstring();
            }

            return(retVal);
        }
Beispiel #31
0
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            Dictionary <string, object> absoluteLocation = new Dictionary <string, object>();

            absoluteLocation.Add("type", XPathAnalyzer.ExprType.ABSOLUTE_LOCATION_PATH);

            while (!lexer.empty() && (lexer.peak()[0] == '/'))
            {
                if (!absoluteLocation.ContainsKey("steps"))
                {
                    absoluteLocation.Add("steps", new List <Dictionary <string, object> >());
                }

                if (lexer.next().Equals("/"))
                {
                    var next = lexer.peak();

                    if (!lexer.empty() && (next.Equals(".") || next.Equals("..") || next.Equals("@") || next.Equals("*") || XPathLexer.RegexTest(next, @"(?![0 - 9])[\w]")))
                    {
                        ((List <Dictionary <string, object> >)absoluteLocation["steps"]).Add(Step.parse(rootParser, lexer));
                    }
                }
                else
                {
                    Dictionary <string, object> itm = new Dictionary <string, object>();
                    itm.Add("axis", XPathAnalyzer.AxisSpecifier.DESCENDANT_OR_SELF);

                    Dictionary <string, object> test = new Dictionary <string, object>();
                    test.Add("type", XPathAnalyzer.NodeType.NODE);

                    itm.Add("test", test);

                    ((List <Dictionary <string, object> >)absoluteLocation["steps"]).Add(itm);

                    ((List <Dictionary <string, object> >)absoluteLocation["steps"]).Add(Step.parse(rootParser, lexer));
                }
            }
            return(absoluteLocation);
        }
Beispiel #32
0
        public static object parse(Expr rootParser, XPathLexer lexer)
        {
            object primary = PrimaryExpr.parse(rootParser, lexer);

            if(!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals("["))
            {
                Dictionary<string, object> filter = new Dictionary<string, object>();
                filter.Add("type", XPathAnalyzer.ExprType.FILTER);
                filter.Add("primary", primary);
                filter.Add("predicates", new List<object>());

                while (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals("["))
                {
                    ((List<object>)filter["predicates"]).Add(Predicate.parse(rootParser, lexer));
                }

                return filter;
            }
            else
            {
                return primary;
            }
        }
Beispiel #33
0
 public object parse(XPathLexer lexer)
 {
     return(OrExpr.parse(this, lexer));
 }
Beispiel #34
0
 //PrimaryExpr primExp = new PrimaryExpr();
 public static bool isValidOp(XPathLexer lexer)
 {
     return(PrimaryExpr.isValidOp(lexer));
 }
Beispiel #35
0
        public static Dictionary <string, object> parse(Expr rootParser, XPathLexer lexer)
        {
            Dictionary <string, object> step = new Dictionary <string, object>();

            step.Add("axis", "");
            step.Add("test", new object());

            if (!string.IsNullOrEmpty(lexer.peak(1)) && lexer.peak(1).Equals("::"))
            {
                var axisSpecifier = lexer.next();

                lexer.next();

                if (AxisSpecifierValidator.isValid(axisSpecifier))
                {
                    step["axis"] = axisSpecifier;
                }
                else
                {
                    throw new Exception("Error: Unexpected token " + axisSpecifier);
                }
            }
            else if (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals("@"))
            {
                lexer.next();

                step["axis"] = XPathAnalyzer.AxisSpecifier.ATTRIBUTE;
            }
            else if (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals(".."))
            {
                lexer.next();

                Dictionary <string, object> test = new Dictionary <string, object>();
                test.Add("type", XPathAnalyzer.NodeType.NODE);

                step["axis"] = XPathAnalyzer.AxisSpecifier.PARENT;
                step["test"] = test;
                return(step);
            }
            else if (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals("."))
            {
                lexer.next();

                Dictionary <string, object> test = new Dictionary <string, object>();
                test.Add("type", XPathAnalyzer.NodeType.NODE);

                step["axis"] = XPathAnalyzer.AxisSpecifier.SELF;
                step["test"] = test;

                return(step);
            }
            else
            {
                step["axis"] = XPathAnalyzer.AxisSpecifier.CHILD;
            }

            step["test"] = NodeTest.parse(rootParser, lexer);

            while (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals("["))
            {
                if (!step.ContainsKey("predicates"))
                {
                    step.Add("predicates", new List <object>());
                }
                ((List <object>)step["predicates"]).Add(Predicate.parse(rootParser, lexer));
            }

            return(step);
        }
Beispiel #36
0
 public object parse(XPathLexer lexer)
 {
     return OrExpr.parse(this, lexer);
 }
Beispiel #37
0
 //PrimaryExpr primExp = new PrimaryExpr();
 public static bool isValidOp(XPathLexer lexer)
 {
     return PrimaryExpr.isValidOp(lexer);
 }
Beispiel #38
0
        internal static string ParseXPathString(XPathMessageFilter filter, bool throwOnFailure)
        {
            XPathLexer lexer = new XPathLexer(filter.XPath);

            return(XPathMessageFilterElementComparer.ParseXPathString(lexer, filter.Namespaces, throwOnFailure));
        }
Beispiel #39
0
        public static Dictionary<string, object> parse(Expr rootParser, XPathLexer lexer)
        {
            Dictionary<string, object> step = new Dictionary<string, object>();
            step.Add("axis", "");
            step.Add("test", new object());

            if (!string.IsNullOrEmpty(lexer.peak(1)) && lexer.peak(1).Equals("::"))
            {
                var axisSpecifier = lexer.next();

                lexer.next();

                if (AxisSpecifierValidator.isValid(axisSpecifier))
                {
                    step["axis"] = axisSpecifier;
                }
                else
                {
                    throw new Exception("Error: Unexpected token " + axisSpecifier);
                }
            }
            else if (!string.IsNullOrEmpty(lexer.peak()) && lexer.peak().Equals("@"))
            {
                lexer.next();

                step["axis"] = XPathAnalyzer.AxisSpecifier.ATTRIBUTE;
            }else if (!string.IsNullOrEmpty(lexer.peak()) &&  lexer.peak().Equals("..")) {
                lexer.next();

                Dictionary<string, object> test = new Dictionary<string, object>();
                test.Add("type", XPathAnalyzer.NodeType.NODE);

                step["axis"] = XPathAnalyzer.AxisSpecifier.PARENT;
                step["test"] = test;
                return step;
            }
            else if (!string.IsNullOrEmpty(lexer.peak()) &&  lexer.peak().Equals("."))
            {
                lexer.next();

                Dictionary<string, object> test = new Dictionary<string, object>();
                test.Add("type", XPathAnalyzer.NodeType.NODE);

                step["axis"] = XPathAnalyzer.AxisSpecifier.SELF;
                step["test"] = test;

                return step;
            }
            else
            {
                step["axis"] = XPathAnalyzer.AxisSpecifier.CHILD;
            }

            step["test"] = NodeTest.parse(rootParser, lexer);

            while (!string.IsNullOrEmpty(lexer.peak()) &&  lexer.peak().Equals("["))
            {
                if(!step.ContainsKey("predicates"))
                {
                    step.Add("predicates", new List<object>());
                }
                ((List<object>)step["predicates"]).Add(Predicate.parse(rootParser, lexer));
            }

            return step;
        }