示例#1
0
 static internal AstNode NewAstNode(String parsestring)
 {
     try {
         return(XPathParser.ParseXPathExpresion(parsestring));
     }
     catch (XPathException e)
     {
         Debug.WriteLine(e.Message);
     }
     return(null);
 }
示例#2
0
        public static AstNode ParseXPathPattern(string xpathPattern)
        {
            XPathScanner scanner = new XPathScanner(xpathPattern);
            XPathParser  parser  = new XPathParser(scanner);
            AstNode      result  = parser.ParsePattern(null);

            if (scanner.Kind != XPathScanner.LexKind.Eof)
            {
                throw new XPathException(string.Format("'{0}' has an invalid token.", scanner.SourceText));
            }
            return(result);
        }
示例#3
0
        public void Build(string xpath, ArrayList compiledXPath, int depth)
        {
            IQuery query;
            //
            // build the AST node first
            //
            AstNode root = XPathParser.ParseXPathExpresion(xpath);

            Stack stack = new Stack();

            query = ProcessNode(root, null);

            while (query != null)
            {
                if (query is BaseAxisQuery)
                {
                    stack.Push(query);
                    query = ((BaseAxisQuery)query).QueryInput;
                }
                else
                {
                    // these queries are not supported
                    // for example, the primary exprission not in the predicate.
                    throw new XPathReaderException("XPath query is not supported!");
                }
            }

            query = (IQuery)stack.Peek();

            if (query is AbsoluteQuery)   //AbsoluteQuery at root means nothing. Throw it away.
            {
                stack.Pop();
            }

            // reverse the query
            // compute the query depth table
            while (stack.Count > 0)
            {
                compiledXPath.Add(stack.Pop());
                BaseAxisQuery currentQuery = (BaseAxisQuery)compiledXPath[compiledXPath.Count - 1];

                FilterQuery filterQuery = null;

                if (currentQuery is FilterQuery)
                {
                    filterQuery  = (FilterQuery)currentQuery;
                    currentQuery = ((FilterQuery)currentQuery).Axis;
                }

                if (currentQuery is ChildQuery || currentQuery is AttributeQuery || currentQuery is DescendantQuery)
                {
                    ++depth;
                }
                else if (currentQuery is AbsoluteQuery)
                {
                    depth = 0;
                }

                currentQuery.Depth = depth;

                if (filterQuery != null)
                {
                    filterQuery.Depth = depth;
                }
            }

            //
            // matchIndex always point to the next query to match.
            // We use the matchIndex to retriev the query depth info,
            // without this added Null query, we need to check the
            // condition all the time in the Expression Advance method.
            //
            compiledXPath.Add(new NullQuery());
        }