// Six possible causes of exceptions in the builder:
        // 1. Undefined prefix in a node test.
        // 2. Undefined prefix in a variable reference, or unknown variable.
        // 3. Undefined prefix in a function call, or unknown function, or wrong number/types of arguments.
        // 4. Argument of Union operator is not a node-set.
        // 5. First argument of Predicate is not a node-set.
        // 6. Argument of Axis is not a node-set.

        public Node Parse(string xpathExpr, IXPathBuilder <Node> builder)
        {
            Debug.Assert(this.scanner == null && this.builder == null);
            Debug.Assert(builder != null);

            Node result = default(Node);

            this.scanner = new XPathScanner(xpathExpr);
            this.builder = builder;
            this.posInfo.Clear();

            try {
                builder.StartBuild();
                result = ParseExpr();
                scanner.CheckToken(LexKind.Eof);
            }
            catch (XPathParserException e) {
                if (e.queryString == null)
                {
                    e.queryString = scanner.Source;
                    PopPosInfo(out e.startChar, out e.endChar);
                }
                throw;
            }
            finally {
                result = builder.EndBuild(result);
#if DEBUG
                this.builder = null;
                this.scanner = null;
#endif
            }
            Debug.Assert(posInfo.Count == 0, "PushPosInfo() and PopPosInfo() calls have been unbalanced");
            return(result);
        }
Exemple #2
0
        public Node Parse(XPathScanner scanner, IXPathBuilder <Node> builder, LexKind endLex)
        {
            Debug.Assert(_scanner == null && _builder == null);
            Debug.Assert(scanner != null && builder != null);

            Node result = default(Node);

            _scanner = scanner;
            _builder = builder;
            _posInfo.Clear();

            try
            {
                builder.StartBuild();
                result = ParseExpr();
                scanner.CheckToken(endLex);
            }
            catch (XPathCompileException e)
            {
                if (e.queryString == null)
                {
                    e.queryString = scanner.Source;
                    PopPosInfo(out e.startChar, out e.endChar);
                }
                throw;
            }
            finally
            {
                result = builder.EndBuild(result);
#if DEBUG
                _builder = null;
                _scanner = null;
#endif
            }
            Debug.Assert(_posInfo.Count == 0, "PushPosInfo() and PopPosInfo() calls have been unbalanced");
            return(result !);
        }