Author: atsushi
Date: 2005-03-16 15:55:55 -0500 (Wed, 16 Mar 2005)
New Revision: 41921

Modified:
   trunk/mcs/class/System.XML/System.Xml.XPath/ChangeLog
   trunk/mcs/class/System.XML/System.Xml.XPath/Parser.jay
Log:
2004-03-16  Atsushi Enomoto  <[EMAIL PROTECTED]>

        * Parser.jay : rewrote step part to be reusable for upcoming XSLT
          pattern parser.



Modified: trunk/mcs/class/System.XML/System.Xml.XPath/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/System.Xml.XPath/ChangeLog       2005-03-16 
19:21:23 UTC (rev 41920)
+++ trunk/mcs/class/System.XML/System.Xml.XPath/ChangeLog       2005-03-16 
20:55:55 UTC (rev 41921)
@@ -1,5 +1,10 @@
 2004-03-16  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
+       * Parser.jay : rewrote step part to be reusable for upcoming XSLT
+         pattern parser.
+
+2004-03-16  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
        * Iterator.cs : reduced extra clone.
 
 2004-03-15  Atsushi Enomoto  <[EMAIL PROTECTED]>

Modified: trunk/mcs/class/System.XML/System.Xml.XPath/Parser.jay
===================================================================
--- trunk/mcs/class/System.XML/System.Xml.XPath/Parser.jay      2005-03-16 
19:21:23 UTC (rev 41920)
+++ trunk/mcs/class/System.XML/System.Xml.XPath/Parser.jay      2005-03-16 
20:55:55 UTC (rev 41921)
@@ -5,6 +5,7 @@
 //
 
 using System;
+using System.Collections;
 using System.Xml;
 using System.Xml.XPath;
 
@@ -20,6 +21,7 @@
                {
                        Context = context;
                        ErrorOutput = System.IO.TextWriter.Null;
+//                     debug = new yydebug.yyDebugSimple ();
                }
                
                internal Expression Compile (string xpath)
@@ -28,12 +30,39 @@
                                Tokenizer tokenizer = new Tokenizer (xpath);
                                return (Expression) yyparse (tokenizer);
                        } catch (XPathException e) {
-                               throw e;
+                               throw;
                        } catch (Exception e) {
                                throw new XPathException ("Error during parse 
of " + xpath, e);
                        }
                }
                static int yacc_verbose_flag;
+
+               private NodeSet CreateNodeTest (Axes axis, object nodeTest, 
ArrayList plist)
+               {
+                       NodeSet test = CreateNodeTest (axis, nodeTest);
+                       if (plist != null) {
+                               for (int i = 0; i < plist.Count; i++)
+                                       test = new ExprFilter (test,
+                                               (Expression) plist [i]);
+                       }
+                       return test;
+               }
+
+               private NodeTest CreateNodeTest (Axes axis, object test)
+               {
+                       if (test is XPathNodeType)
+                               return new NodeTypeTest (axis,
+                                       (XPathNodeType) test, null);
+                       else if (test is string || test == null)
+                               return new NodeTypeTest (axis,
+                                       XPathNodeType.ProcessingInstruction,
+                                       (string) test);
+                       XmlQualifiedName q = (XmlQualifiedName) test;
+                       if (q == XmlQualifiedName.Empty)
+                               return new NodeTypeTest (axis);
+                       else
+                               return new NodeNameTest (axis, q, Context);
+               }
 %}
 
 %token ERROR
@@ -116,6 +145,7 @@
 %%
 
 
+
 Expr
        : OrExpr
        ;
@@ -258,41 +288,68 @@
        ;
 
 Step
-       : PredicatedStep
-       | DOT
+       : AxisSpecifier NodeTest Predicates
        {
-               $$ = new NodeTypeTest (Axes.Self, XPathNodeType.All);
+               $$ = CreateNodeTest ((Axes) $1, $2, (ArrayList) $3);
        }
-       | DOT2
+       | AbbreviatedStep
+       ;
+
+NodeTest // QName, XPathNodeType or string
+       : NameTest
+       | NodeType PAREN_OPEN PAREN_CLOSE
        {
-               $$ = new NodeTypeTest (Axes.Parent, XPathNodeType.All);
+               $$ = (XPathNodeType) $1;
        }
+       | PROCESSING_INSTRUCTION PAREN_OPEN OptionalLiteral PAREN_CLOSE
+       {
+               $$ = (string) $3;
+       }
        ;
 
-PredicatedStep
-       : AxisTest
-       | PredicatedStep Predicate
+NameTest
+       : ASTERISK
        {
-               $$ = new ExprFilter ((NodeSet) $1, (Expression) $2);
+               $$ = XmlQualifiedName.Empty;
        }
+       | QName // token QName also contains "blah:*"
        ;
 
-AxisTest
-       : AxisSpecifier QName
+AbbreviatedStep
+       : DOT
        {
-               $$ = new NodeNameTest ((Axes) $1, (XmlQualifiedName) $2, 
Context);
+               $$ = new NodeTypeTest (Axes.Self, XPathNodeType.All);
        }
-       | AxisSpecifier ASTERISK
+       | DOT2
        {
-               $$ = new NodeTypeTest ((Axes) $1);
+               $$ = new NodeTypeTest (Axes.Parent, XPathNodeType.All);
        }
-       | AxisSpecifier NodeType PAREN_OPEN OptionalLiteral PAREN_CLOSE
+       ;
+
+Predicates
+       : /* empty */
        {
-               $$ = new NodeTypeTest ((Axes) $1, (XPathNodeType) $2, (String) 
$4);
+               $$ = null;
        }
+       | Predicates Predicate
+       {
+               ArrayList al = (ArrayList) $1;
+               if (al == null)
+                       al = new ArrayList ();
+               al.Add ($2);
+               $$ = al;
+       }
        ;
 
 AxisSpecifier
+       : AxisName COLON2
+       {
+               $$ = $1;
+       }
+       | AbbreviatedAxisSpecifier
+       ;
+
+AbbreviatedAxisSpecifier
        : /* empty */
        {
                $$ = Axes.Child;
@@ -301,10 +358,6 @@
        {
                $$ = Axes.Attribute;
        }
-       | AxisName COLON2
-       {
-               $$ = $1;
-       }
        ;
 
 NodeType

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to