You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by zo...@apache.org on 2005/12/03 11:55:57 UTC

svn commit: r351910 - in /xalan/java/trunk/src/org/apache/xalan/xsltc/compiler: xpath.cup xpath.lex

Author: zongaro
Date: Sat Dec  3 02:55:53 2005
New Revision: 351910

URL: http://svn.apache.org/viewcvs?rev=351910&view=rev
Log:
Fix for XALANJ-2199.  Lexical disambiguation rules for an NCName with the same
name as an operator assumed that any such name that follows an asterisk, must
really be an NCName, and not an operator, under the assumption that the asterisk
must be a multiplication operator.  However, that causes the operator in an
expression like "* or doc/ch" to be treated as an NCName, resulting in an
incorrect syntax error.

Introduced a new token to distinguish between the use of asterisk as a wildcard
and its use as a multiplication operator, and added new disambuguation rules
to identify the two uses.

Patch was reviewed by Yash Talwar (ytalwar () ca ! ibm ! com)

Modified:
    xalan/java/trunk/src/org/apache/xalan/xsltc/compiler/xpath.cup
    xalan/java/trunk/src/org/apache/xalan/xsltc/compiler/xpath.lex

Modified: xalan/java/trunk/src/org/apache/xalan/xsltc/compiler/xpath.cup
URL: http://svn.apache.org/viewcvs/xalan/java/trunk/src/org/apache/xalan/xsltc/compiler/xpath.cup?rev=351910&r1=351909&r2=351910&view=diff
==============================================================================
--- xalan/java/trunk/src/org/apache/xalan/xsltc/compiler/xpath.cup (original)
+++ xalan/java/trunk/src/org/apache/xalan/xsltc/compiler/xpath.cup Sat Dec  3 02:55:53 2005
@@ -297,7 +297,7 @@
 terminal DDOT, DCOLON, DSLASH;
 terminal EQ, NE;
 terminal LT, GT, LE, GE;
-terminal PLUS, MINUS, DIV, MOD;
+terminal PLUS, MINUS, DIV, MOD, MULT;
 terminal String Literal;
 terminal String QNAME;
 terminal ID, KEY, TEXT, NODE, OR, AND, COMMENT, PI, PIPARAM, PRECEDINGSIBLING;
@@ -341,7 +341,7 @@
 precedence left LT, GT, LE, GE;
     
 precedence left PLUS, MINUS;
-precedence left DIV, MOD, STAR;
+precedence left DIV, MOD, MULT;
 precedence left DOLLAR;
 precedence left ATSIGN;
 precedence right DCOLON;
@@ -540,7 +540,7 @@
 MultiplicativeExpr ::= UnaryExpr:ue
         {: RESULT = ue; :}
 
-        | MultiplicativeExpr:me STAR UnaryExpr:ue
+        | MultiplicativeExpr:me MULT UnaryExpr:ue
         {: RESULT = new BinOpExpr(BinOpExpr.TIMES, me, ue); :}
 
         | MultiplicativeExpr:me DIV UnaryExpr:ue

Modified: xalan/java/trunk/src/org/apache/xalan/xsltc/compiler/xpath.lex
URL: http://svn.apache.org/viewcvs/xalan/java/trunk/src/org/apache/xalan/xsltc/compiler/xpath.lex?rev=351910&r1=351909&r2=351910&view=diff
==============================================================================
--- xalan/java/trunk/src/org/apache/xalan/xsltc/compiler/xpath.lex (original)
+++ xalan/java/trunk/src/org/apache/xalan/xsltc/compiler/xpath.lex Sat Dec  3 02:55:53 2005
@@ -86,7 +86,7 @@
             case sym.OR:
             case sym.MOD:
             case sym.DIV:
-            case sym.STAR:
+            case sym.MULT:
             case sym.SLASH:
             case sym.DSLASH:
             case sym.VBAR:
@@ -103,6 +103,40 @@
             return newSymbol(ss);
         }
 
+        /**
+         * If symbol is first token or if it follows any of the operators
+         * listed in http://www.w3.org/TR/xpath#exprlex then treat as a
+         * wildcard instead of a multiplication operator
+         */
+        Symbol disambiguateStar() throws Exception {
+            switch (last) {
+            case -1:    // first token
+            case sym.ATSIGN:
+            case sym.DCOLON:
+            case sym.LPAREN:
+            case sym.LBRACK:
+            case sym.COMMA:
+            case sym.AND:
+            case sym.OR:
+            case sym.MOD:
+            case sym.DIV:
+            case sym.MULT:
+            case sym.SLASH:
+            case sym.DSLASH:
+            case sym.VBAR:
+            case sym.PLUS:
+            case sym.MINUS:
+            case sym.EQ:
+            case sym.NE:
+            case sym.LT:
+            case sym.LE:
+            case sym.GT:
+            case sym.GE:
+                return newSymbol(sym.STAR);
+            }
+            return newSymbol(sym.MULT);
+        }
+
         Symbol newSymbol(int ss) {
             last = ss;
             return new Symbol(ss);
@@ -156,7 +190,7 @@
 
 %%
 
-"*"                      { return newSymbol(sym.STAR); }
+"*"                      { return disambiguateStar(); }
 "/"                      { return newSymbol(sym.SLASH); } 
 "+"                      { return newSymbol(sym.PLUS); }
 "-"                      { return newSymbol(sym.MINUS); }



---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org