private bool ParseRelativePath(XPathExprList path)
        {
            XPathStepExpr expr = this.ParseStep();

            if (expr == null)
            {
                return(false);
            }
            path.Add(expr);
            while (true)
            {
                if (this.NextToken(XPathTokenID.Slash) != null)
                {
                    expr = this.ParseStep();
                }
                else
                {
                    if (this.NextToken(XPathTokenID.DblSlash) == null)
                    {
                        return(true);
                    }
                    expr = new XPathStepExpr(new NodeSelectCriteria(QueryAxisType.DescendantOrSelf, NodeQName.Empty, QueryNodeType.All));
                    path.Add(expr);
                    expr = this.ParseStep();
                }
                if (expr == null)
                {
                    this.ThrowError(QueryCompileError.InvalidLocationPath);
                }
                path.Add(expr);
            }
        }
Esempio n. 2
0
        XPathExprList ParseAbsolutePath()
        {
            XPathExprList path  = null;
            XPathToken    token = this.NextToken();

            if (null != token)
            {
                switch (token.TokenID)
                {
                default:
                    this.PushToken(token);
                    break;

                case XPathTokenID.Slash:
                    path = new XPathExprList();
                    path.Add(new XPathStepExpr(new NodeSelectCriteria(QueryAxisType.Child, NodeQName.Empty, QueryNodeType.Root)));
                    break;

                case XPathTokenID.DblSlash:
                    // '//' is special. If found at the start of an absolute path, it implies that the descendant-or-self axis
                    // is applied to the ROOT
                    path = new XPathExprList();
                    path.Add(new XPathStepExpr(new NodeSelectCriteria(QueryAxisType.Child, NodeQName.Empty, QueryNodeType.Root)));
                    path.Add(new XPathStepExpr(new NodeSelectCriteria(QueryAxisType.DescendantOrSelf, NodeQName.Empty, QueryNodeType.All)));
                    break;
                }
            }

            if (null != path)
            {
                this.ParseRelativePath(path);
            }

            return(path);
        }
        private XPathExprList ParseAbsolutePath()
        {
            XPathExprList path  = null;
            XPathToken    token = this.NextToken();

            if (token != null)
            {
                XPathTokenID tokenID = token.TokenID;
                if (tokenID == XPathTokenID.Slash)
                {
                    path = new XPathExprList();
                    path.Add(new XPathStepExpr(new NodeSelectCriteria(QueryAxisType.Child, NodeQName.Empty, QueryNodeType.Root)));
                }
                else if (tokenID == XPathTokenID.DblSlash)
                {
                    path = new XPathExprList();
                    path.Add(new XPathStepExpr(new NodeSelectCriteria(QueryAxisType.Child, NodeQName.Empty, QueryNodeType.Root)));
                    path.Add(new XPathStepExpr(new NodeSelectCriteria(QueryAxisType.DescendantOrSelf, NodeQName.Empty, QueryNodeType.All)));
                }
                else
                {
                    this.PushToken(token);
                }
            }
            if (path != null)
            {
                this.ParseRelativePath(path);
            }
            return(path);
        }
        private XPathExprList ParsePredicates()
        {
            XPathExprList list = null;
            XPathExpr     expr = this.ParsePredicateExpression();

            if (expr != null)
            {
                list = new XPathExprList();
                list.Add(expr);
                while ((expr = this.ParsePredicateExpression()) != null)
                {
                    list.Add(expr);
                }
            }
            return(list);
        }
Esempio n. 5
0
        XPathExprList ParsePredicates()
        {
            XPathExprList predicates = null;
            XPathExpr     predicate  = this.ParsePredicateExpression();

            if (null != predicate)
            {
                predicates = new XPathExprList();
                predicates.Add(predicate);
                while (null != (predicate = this.ParsePredicateExpression()))
                {
                    predicates.Add(predicate);
                }
            }

            return(predicates);
        }
        private XPathExpr ParseFunctionExpression()
        {
            XPathExpr  expr;
            XPathToken token = this.NextToken(XPathTokenID.Function);

            if (token == null)
            {
                return(null);
            }
            NodeQName name = this.QualifyName(token.Prefix, token.Name);

            this.NextToken(XPathTokenID.LParen, QueryCompileError.InvalidFunction);
            XPathExprList args = new XPathExprList();

            while ((expr = this.ParseExpression()) != null)
            {
                args.Add(expr);
                if (this.NextToken(XPathTokenID.Comma) == null)
                {
                    break;
                }
            }
            XPathExpr expr2 = null;

            if (this.functionLibraries != null)
            {
                QueryFunction function = null;
                for (int i = 0; i < this.functionLibraries.Length; i++)
                {
                    function = this.functionLibraries[i].Bind(name.Name, name.Namespace, args);
                    if (function != null)
                    {
                        expr2 = new XPathFunctionExpr(function, args);
                        break;
                    }
                }
            }
            if ((expr2 == null) && (this.context != null))
            {
                XPathResultType[] argTypes = new XPathResultType[args.Count];
                for (int j = 0; j < args.Count; j++)
                {
                    argTypes[j] = XPathXsltFunctionExpr.ConvertTypeToXslt(args[j].ReturnType);
                }
                string prefix = this.context.LookupPrefix(name.Namespace);
                IXsltContextFunction function2 = this.context.ResolveFunction(prefix, name.Name, argTypes);
                if (function2 != null)
                {
                    expr2 = new XPathXsltFunctionExpr(this.context, function2, args);
                }
            }
            if (expr2 == null)
            {
                this.ThrowError(QueryCompileError.UnsupportedFunction);
            }
            this.NextToken(XPathTokenID.RParen, QueryCompileError.InvalidFunction);
            return(expr2);
        }
Esempio n. 7
0
        bool ParseRelativePath(XPathExprList path)
        {
            Fx.Assert(null != path, "");

            XPathStepExpr step = this.ParseStep();

            if (null == step)
            {
                return(false);
            }

            path.Add(step);
            while (true)
            {
                if (null != this.NextToken(XPathTokenID.Slash))
                {
                    step = this.ParseStep();
                }
                else if (null != this.NextToken(XPathTokenID.DblSlash))
                {
                    step = new XPathStepExpr(new NodeSelectCriteria(QueryAxisType.DescendantOrSelf, NodeQName.Empty, QueryNodeType.All));
                    path.Add(step);
                    step = this.ParseStep();
                }
                else
                {
                    break;
                }

                if (null == step)
                {
                    this.ThrowError(QueryCompileError.InvalidLocationPath);
                }

                path.Add(step);
            }

            return(true);
        }
Esempio n. 8
0
        XPathExpr ParseFunctionExpression()
        {
            XPathToken functionToken = this.NextToken(XPathTokenID.Function);

            if (null == functionToken)
            {
                return(null);
            }

            NodeQName functionName = this.QualifyName(functionToken.Prefix, functionToken.Name);

            this.NextToken(XPathTokenID.LParen, QueryCompileError.InvalidFunction);

            XPathExprList args = new XPathExprList();

            // Read in arguments
            XPathExpr arg;

            while (null != (arg = this.ParseExpression()))
            {
                args.Add(arg);
                if (null == this.NextToken(XPathTokenID.Comma))
                {
                    break;
                }
            }

            // Bind to the function
            // Try each library until we can bind the function
            XPathExpr functionImpl = null;

            if (null != this.functionLibraries)
            {
                QueryFunction fun = null;
                for (int i = 0; i < this.functionLibraries.Length; ++i)
                {
                    if (null != (fun = this.functionLibraries[i].Bind(functionName.Name, functionName.Namespace, args)))
                    {
                        functionImpl = new XPathFunctionExpr(fun, args);
                        break;
                    }
                }
            }

            // Try to bind using the XsltContext
            if (null == functionImpl && this.context != null)
            {
                XPathResultType[] argTypes = new XPathResultType[args.Count];
                for (int i = 0; i < args.Count; ++i)
                {
                    argTypes[i] = XPathXsltFunctionExpr.ConvertTypeToXslt(args[i].ReturnType);
                }
                string prefix = this.context.LookupPrefix(functionName.Namespace);
                IXsltContextFunction xsltFun = this.context.ResolveFunction(prefix, functionName.Name, argTypes);
                if (xsltFun != null)
                {
                    functionImpl = new XPathXsltFunctionExpr(this.context, xsltFun, args);
                }
            }

            if (null == functionImpl)
            {
                this.ThrowError(QueryCompileError.UnsupportedFunction);
            }

            this.NextToken(XPathTokenID.RParen, QueryCompileError.InvalidFunction);
            return(functionImpl);
        }
Esempio n. 9
0
        bool ParseRelativePath(XPathExprList path)
        {
            Fx.Assert(null != path, "");

            XPathStepExpr step = this.ParseStep();

            if (null == step)
            {
                return false;
            }

            path.Add(step);
            while (true)
            {
                if (null != this.NextToken(XPathTokenID.Slash))
                {
                    step = this.ParseStep();
                }
                else if (null != this.NextToken(XPathTokenID.DblSlash))
                {
                    step = new XPathStepExpr(new NodeSelectCriteria(QueryAxisType.DescendantOrSelf, NodeQName.Empty, QueryNodeType.All));
                    path.Add(step);
                    step = this.ParseStep();
                }
                else
                {
                    break;
                }

                if (null == step)
                {
                    this.ThrowError(QueryCompileError.InvalidLocationPath);
                }

                path.Add(step);
            }

            return true;
        }
Esempio n. 10
0
        XPathExprList ParsePredicates()
        {
            XPathExprList predicates = null;
            XPathExpr predicate = this.ParsePredicateExpression();

            if (null != predicate)
            {
                predicates = new XPathExprList();
                predicates.Add(predicate);
                while (null != (predicate = this.ParsePredicateExpression()))
                {
                    predicates.Add(predicate);
                }
            }

            return predicates;
        }
Esempio n. 11
0
        XPathExpr ParseFunctionExpression()
        {
            XPathToken functionToken = this.NextToken(XPathTokenID.Function);

            if (null == functionToken)
            {
                return null;
            }

            NodeQName functionName = this.QualifyName(functionToken.Prefix, functionToken.Name);
            this.NextToken(XPathTokenID.LParen, QueryCompileError.InvalidFunction);

            XPathExprList args = new XPathExprList();

            // Read in arguments
            XPathExpr arg;

            while (null != (arg = this.ParseExpression()))
            {
                args.Add(arg);
                if (null == this.NextToken(XPathTokenID.Comma))
                {
                    break;
                }
            }

            // Bind to the function
            // Try each library until we can bind the function
            XPathExpr functionImpl = null;
            if (null != this.functionLibraries)
            {
                QueryFunction fun = null;
                for (int i = 0; i < this.functionLibraries.Length; ++i)
                {
                    if (null != (fun = this.functionLibraries[i].Bind(functionName.Name, functionName.Namespace, args)))
                    {
                        functionImpl = new XPathFunctionExpr(fun, args);
                        break;
                    }
                }
            }

            // Try to bind using the XsltContext
            if (null == functionImpl && this.context != null)
            {
                XPathResultType[] argTypes = new XPathResultType[args.Count];
                for (int i = 0; i < args.Count; ++i)
                {
                    argTypes[i] = XPathXsltFunctionExpr.ConvertTypeToXslt(args[i].ReturnType);
                }
                string prefix = this.context.LookupPrefix(functionName.Namespace);
                IXsltContextFunction xsltFun = this.context.ResolveFunction(prefix, functionName.Name, argTypes);
                if (xsltFun != null)
                {
                    functionImpl = new XPathXsltFunctionExpr(this.context, xsltFun, args);
                }
            }

            if (null == functionImpl)
            {
                this.ThrowError(QueryCompileError.UnsupportedFunction);
            }

            this.NextToken(XPathTokenID.RParen, QueryCompileError.InvalidFunction);
            return functionImpl;
        }
Esempio n. 12
0
        XPathExprList ParseAbsolutePath()
        {
            XPathExprList path = null;
            XPathToken token = this.NextToken();

            if (null != token)
            {
                switch (token.TokenID)
                {
                    default:
                        this.PushToken(token);
                        break;

                    case XPathTokenID.Slash:
                        path = new XPathExprList();
                        path.Add(new XPathStepExpr(new NodeSelectCriteria(QueryAxisType.Child, NodeQName.Empty, QueryNodeType.Root)));
                        break;

                    case XPathTokenID.DblSlash:
                        // '//' is special. If found at the start of an absolute path, it implies that the descendant-or-self axis
                        // is applied to the ROOT
                        path = new XPathExprList();
                        path.Add(new XPathStepExpr(new NodeSelectCriteria(QueryAxisType.Child, NodeQName.Empty, QueryNodeType.Root)));
                        path.Add(new XPathStepExpr(new NodeSelectCriteria(QueryAxisType.DescendantOrSelf, NodeQName.Empty, QueryNodeType.All)));
                        break;
                }
            }

            if (null != path)
            {
                this.ParseRelativePath(path);
            }

            return path;
        }
 private bool ParseRelativePath(XPathExprList path)
 {
     XPathStepExpr expr = this.ParseStep();
     if (expr == null)
     {
         return false;
     }
     path.Add(expr);
     while (true)
     {
         if (this.NextToken(XPathTokenID.Slash) != null)
         {
             expr = this.ParseStep();
         }
         else
         {
             if (this.NextToken(XPathTokenID.DblSlash) == null)
             {
                 return true;
             }
             expr = new XPathStepExpr(new NodeSelectCriteria(QueryAxisType.DescendantOrSelf, NodeQName.Empty, QueryNodeType.All));
             path.Add(expr);
             expr = this.ParseStep();
         }
         if (expr == null)
         {
             this.ThrowError(QueryCompileError.InvalidLocationPath);
         }
         path.Add(expr);
     }
 }
 private XPathExprList ParsePredicates()
 {
     XPathExprList list = null;
     XPathExpr expr = this.ParsePredicateExpression();
     if (expr != null)
     {
         list = new XPathExprList();
         list.Add(expr);
         while ((expr = this.ParsePredicateExpression()) != null)
         {
             list.Add(expr);
         }
     }
     return list;
 }
 private XPathExpr ParseFunctionExpression()
 {
     XPathExpr expr;
     XPathToken token = this.NextToken(XPathTokenID.Function);
     if (token == null)
     {
         return null;
     }
     NodeQName name = this.QualifyName(token.Prefix, token.Name);
     this.NextToken(XPathTokenID.LParen, QueryCompileError.InvalidFunction);
     XPathExprList args = new XPathExprList();
     while ((expr = this.ParseExpression()) != null)
     {
         args.Add(expr);
         if (this.NextToken(XPathTokenID.Comma) == null)
         {
             break;
         }
     }
     XPathExpr expr2 = null;
     if (this.functionLibraries != null)
     {
         QueryFunction function = null;
         for (int i = 0; i < this.functionLibraries.Length; i++)
         {
             function = this.functionLibraries[i].Bind(name.Name, name.Namespace, args);
             if (function != null)
             {
                 expr2 = new XPathFunctionExpr(function, args);
                 break;
             }
         }
     }
     if ((expr2 == null) && (this.context != null))
     {
         XPathResultType[] argTypes = new XPathResultType[args.Count];
         for (int j = 0; j < args.Count; j++)
         {
             argTypes[j] = XPathXsltFunctionExpr.ConvertTypeToXslt(args[j].ReturnType);
         }
         string prefix = this.context.LookupPrefix(name.Namespace);
         IXsltContextFunction function2 = this.context.ResolveFunction(prefix, name.Name, argTypes);
         if (function2 != null)
         {
             expr2 = new XPathXsltFunctionExpr(this.context, function2, args);
         }
     }
     if (expr2 == null)
     {
         this.ThrowError(QueryCompileError.UnsupportedFunction);
     }
     this.NextToken(XPathTokenID.RParen, QueryCompileError.InvalidFunction);
     return expr2;
 }
 private XPathExprList ParseAbsolutePath()
 {
     XPathExprList path = null;
     XPathToken token = this.NextToken();
     if (token != null)
     {
         XPathTokenID tokenID = token.TokenID;
         if (tokenID == XPathTokenID.Slash)
         {
             path = new XPathExprList();
             path.Add(new XPathStepExpr(new NodeSelectCriteria(QueryAxisType.Child, NodeQName.Empty, QueryNodeType.Root)));
         }
         else if (tokenID == XPathTokenID.DblSlash)
         {
             path = new XPathExprList();
             path.Add(new XPathStepExpr(new NodeSelectCriteria(QueryAxisType.Child, NodeQName.Empty, QueryNodeType.Root)));
             path.Add(new XPathStepExpr(new NodeSelectCriteria(QueryAxisType.DescendantOrSelf, NodeQName.Empty, QueryNodeType.All)));
         }
         else
         {
             this.PushToken(token);
         }
     }
     if (path != null)
     {
         this.ParseRelativePath(path);
     }
     return path;
 }