W3C home > Mailing lists > Public > www-validator-cvs@w3.org > October 2012

2002/css-validator/org/w3c/css/parser/analyzer CssParser.java,1.85,1.86 CssParser.jj,1.84,1.85 CssParserConstants.java,1.21,1.22 CssParserTokenManager.java,1.45,1.46

From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
Date: Wed, 10 Oct 2012 07:47:33 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1TLr0v-0001xJ-J8@lionel-hutz.w3.org>
Update of /sources/public/2002/css-validator/org/w3c/css/parser/analyzer
In directory hutz:/tmp/cvs-serv7462/analyzer

Modified Files:
	CssParser.java CssParser.jj CssParserConstants.java 
	CssParserTokenManager.java 
Log Message:
allow empty prefix to match all properties from an @rule

Index: CssParserTokenManager.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/analyzer/CssParserTokenManager.java,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- CssParserTokenManager.java	4 Oct 2012 13:16:50 -0000	1.45
+++ CssParserTokenManager.java	10 Oct 2012 07:47:31 -0000	1.46
@@ -29,12 +29,14 @@
 import org.w3c.css.properties.css.CssProperty;
 import org.w3c.css.parser.Frame;
 import org.w3c.css.parser.CssError;
+import org.w3c.css.parser.CssErrorToken;
 import org.w3c.css.parser.CssSelectors;
 import org.w3c.css.parser.CssParseException;
 import org.w3c.css.parser.AtRule;
 import org.w3c.css.media.AtRuleMedia;
 import org.w3c.css.media.MediaFeature;
 import org.w3c.css.parser.AtRuleFontFace;
+import org.w3c.css.parser.AtRuleKeyframes;
[...1486 lines suppressed...]
                   break;
                default : break;
@@ -6187,14 +6240,15 @@
 "\135", "\52", "\56", "\51", "\50", "\72", null, null, null, null, null, null, null, 
 null, null, null, null, null, "\72\72", null, null, null, null, null, null, null, 
 null, null, null, null, null, null, null, null, null, null, null, null, null, null, 
-null, null, null, null, null, null, null, null, null, null, "\174", };
+null, null, null, null, null, null, null, null, null, null, null, null, null, 
+"\174", "\53", };
 
 /** Lexer state names. */
 public static final String[] lexStateNames = {
    "DEFAULT",
 };
 static final long[] jjtoToken = {
-   0xffffffffffe00001L, 0x3fc01ffffL, 
+   0xffffffffffe00001L, 0x3ff803ffffL, 
 };
 static final long[] jjtoSkip = {
    0x2L, 0x0L, 

Index: CssParser.jj
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/analyzer/CssParser.jj,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -d -r1.84 -r1.85
--- CssParser.jj	4 Oct 2012 13:16:50 -0000	1.84
+++ CssParser.jj	10 Oct 2012 07:47:31 -0000	1.85
@@ -51,12 +51,14 @@
 import org.w3c.css.properties.css.CssProperty;
 import org.w3c.css.parser.Frame;
 import org.w3c.css.parser.CssError;
+import org.w3c.css.parser.CssErrorToken;
 import org.w3c.css.parser.CssSelectors;
 import org.w3c.css.parser.CssParseException;
 import org.w3c.css.parser.AtRule;
 import org.w3c.css.media.AtRuleMedia;
 import org.w3c.css.media.MediaFeature;
 import org.w3c.css.parser.AtRuleFontFace;
+import org.w3c.css.parser.AtRuleKeyframes;
 import org.w3c.css.parser.AtRulePage;
 import org.w3c.css.parser.AtRulePreference;
 import org.w3c.css.parser.AtRulePhoneticAlphabet;
@@ -420,6 +422,15 @@
 	ac.getFrame().addError(error);
 	//	}
     }
+
+    private void addParseError(ParseException e, String skipped) {
+          if (Util.onDebug) {
+              System.err.println(e.getMessage());
+              e.printStackTrace();
+          }
+          CssErrorToken err = new CssErrorToken(e, skipped);
+          ac.getFrame().addError(err);
+    }
 }
 
 PARSER_END(CssParser)
@@ -540,7 +551,6 @@
   < URL         : "url(" ( <S> )* ( <STRING> | <_URL>  ) ( <S> )* ")" >
 }
 
-
 <DEFAULT>
 TOKEN [IGNORE_CASE] :
 {
@@ -594,6 +604,7 @@
   | < MEDIA_SYM             : "@media" >
   | < PAGE_SYM              : "@page"  >
   | < FONT_FACE_SYM         : "@font-face" >
+  | < KEYFRAMES_SYM         : "@keyframes" >
   | < PREF_SYM              : "@preference" >
   | < COLOR_PROFILE         : "@color-profile" >
   | < ATTOP	                : "@top" >
@@ -631,16 +642,12 @@
 <DEFAULT>
 TOKEN [IGNORE_CASE] :
 {
-    < FUNCTIONLANG : "lang(" >
-}
-
-<DEFAULT>
-TOKEN [IGNORE_CASE] :
-{
-    < FUNCTIONNOT : ":not(" >
+    < FUNCTIONLANG  : "lang(" >
+    | <FUNCTIONNOT  : ":not(" >
+    | <FUNCTIONCALC : "calc(" >
+    | <FUNCTIONATTR : "attr(" >
 }
 
-
 <DEFAULT>
     TOKEN :
 {
@@ -768,7 +775,7 @@
 void afterImportDeclaration() :
 {String ret; }
 {
-    ( ( ruleSet() | media() | page() | fontFace() | preference() | 
+    ( ( ruleSet() | media() | page() | fontFace() | keyframes() | preference() |
 	colorprofile() | phoneticAlphabet() | ret=skipStatement() 
 	{ if ((ret == null) || (ret.length() == 0)) {
 		return; 
@@ -1118,6 +1125,127 @@
     }
 }
 
+/**
+ * @exception ParseException exception during the parse
+ */
+CssSelectors keyframe_selector(CssSelectors next) :
+{ CssSelectors selector = new CssSelectors(ac, next);
+    selector.setAtRule(getAtRule());
+    Token n;
+}
+{
+    try {
+    ( n=<IDENT> {
+      selector.addType(new TypeSelector(convertIdent(n.image)));
+    } | n=<PERCENTAGE> {
+      selector.addType(new TypeSelector(n.image));
+    } )  ( <S> )*
+	{
+	    return selector;
+	}
+	} catch (InvalidParamException ie) {
+      	ac.getFrame().addError(new CssError(ie));
+      	Token t = getToken(1);
+      	StringBuilder s = new StringBuilder();
+      	s.append(getToken(0).image);
+      	// eat until , { or EOF
+      	while ((t.kind != COMMA) && (t.kind != LBRACE) && (t.kind != EOF)) {
+      	    s.append(t.image);
+      	    getNextToken();
+      	    t = getToken(1);
+      	}
+      	return null;
+    } catch (ParseException e) {
+       // TODO fix the error
+      	Token t = getToken(1);
+      	int _line = t.beginLine;
+      	int _col  = t.beginColumn;
+      	StringBuilder s = new StringBuilder();
+      	s.append(" [");
+      	s.append(getToken(0).image);
+      	// eat until , { or EOF
+      	while ((t.kind != COMMA) && (t.kind != LBRACE) && (t.kind != EOF)) {
+      	    s.append(t.image);
+      	    getNextToken();
+      	    t = getToken(1);
+      	}
+      	s.append(']');
+      	addParseError(e, s.toString());
+      	validSelector = true;
+      	return null;
+     }
+}
+
+
+void keyframes() :
+{
+  Token n;
+  ArrayList<CssProperty> v;
+  AtRule old = getAtRule();
+  AtRuleKeyframes krule = new AtRuleKeyframes("-internal-");
+  setAtRule(krule);
+  CssSelectors s;
+  ArrayList<CssSelectors> sl;
+  CssVersion version = ac.getCssVersion();
+}
+{
+  try {
+    <KEYFRAMES_SYM> ( <S> )+ n=<IDENT> ( <S> )* {
+      krule.setName(convertIdent(n.image));
+      if (version.compareTo(CssVersion.CSS3) < 0) {
+        skipStatement();
+        addError(new InvalidParamException("noatruleyet", "", ac),
+    			     getAtRule().toString());
+      } else {
+        newAtRule(getAtRule());
+      }
+    }
+    <LBRACE> ( <S> )*
+    ( s=keyframe_selector(null) {
+        sl = new ArrayList<CssSelectors>();
+        if (s != null) {
+          s.setAtRule(getAtRule());
+          sl.add(s);
+        }
+    }
+    ( <COMMA> ( <S> )* s=keyframe_selector(null) {
+       if (s != null) {
+         s.setAtRule(getAtRule());
+         sl.add(s);
+       }
+    } )*
+      <LBRACE> ( <S> )* v=declarations() <RBRACE> ( <S> )* {
+      	validSelector = (sl.size() != 0);
+        if (v == null) {
+          ac.getFrame().addWarning("no-declaration");
+        } else {
+          boolean first = true;
+          for (CssSelectors _s : sl) {
+            if (first) {
+               handleRule(_s, v);
+               first = false;
+            } else {
+               ArrayList<CssProperty> vcopy = new ArrayList<CssProperty>(v.size());
+               for (CssProperty p : v) {
+                 vcopy.add(p.duplicate());
+               }
+               handleRule(_s, vcopy);
+            }
+          }
+        }
+        setSelectorList(sl);
+        endOfRule();
+    }
+    )* <RBRACE> ( <S> )*  {
+        endOfAtRule();
+    }
+  } catch (ParseException e) {
+    addError(e, skipStatement());
+  } finally {
+    setAtRule(old);
+  }
+}
+
 void fontFace() :
 {
     ArrayList<CssProperty> v;
@@ -1399,10 +1527,7 @@
 			} else {*/
 		if (value_set != null) {
 		    boolean first = true;
-		    CssSelectors sel = null;
-                    Iterator<CssSelectors> e = context_set.iterator();
-		    while (e.hasNext()) {
-			sel = e.next();
+                    for (CssSelectors sel : context_set) {
 			if (first) {
 			    handleRule(sel, value_set);
 			    first = false;
@@ -1412,9 +1537,9 @@
 			    // badly with conflict detection
 			    int vsize = value_set.size();
 			    ArrayList<CssProperty> v = new ArrayList<CssProperty>(vsize);
-			    for (int i=0; i<vsize; i++) {
-				v.add(value_set.get(i).duplicate());
-			    }
+                            for (CssProperty p : value_set) {
+			        v.add(p.duplicate());
+        		    }
 			    handleRule(sel, v);
 			}
 		    }
@@ -1425,7 +1550,7 @@
 	    }
     } catch (ParseException e) {
     if ((ac.getCssProfile() != CssProfile.MOBILE) && !context_set.isEmpty()) {
-		addError(e, skipStatement()); 
+		addError(e, skipStatement());
 	}
     } catch (TokenMgrError e) {
 	addError(new ParseException(e.getMessage()), skipStatement());
@@ -2285,6 +2410,91 @@
 				UNICODERANGE); }
     ) ( <S> )* )
 }
+
+CssCheckableValue mathcalc() :
+{
+CssCheckableValue v;
+}
+{
+  ( <FUNCTIONCALC>  ( <S> )* v=mathsum() ( <S> )* ")" ) {
+    return v;
+  }
+}
+
+CssCheckableValue mathsum() :
+{ Token n,o;
+  CssCheckableValue v1 = null;
+  CssCheckableValue v2 = null;
+}
+{   // product [ S+ [ "+" | "-" ] S+ product ]*;
+   ( v1=mathproduct() ( LOOKAHEAD(1) ( <S> )+ ( o="+" | o="-" ) ( <S> )+ v2=mathproduct() {
+                      // TODO add stuff, type checking etc...
+                     }
+                    )*
+ ) { return v1; }
+}
+
+
+CssCheckableValue mathproduct() :
+{ Token n,o;
+  CssCheckableValue v1 = null;
+  CssCheckableValue v2 = null;
+}
+{
+
+ ( v1=mathunit()  ( LOOKAHEAD(1) ( <S> )* (  ( o="*" ( <S> )* v2=mathunit() )
+                             | ( o="/" ( <S> )* n=<NUMBER> { v2 = new CssNumber(); v2.set(n.image, ac); } )
+                          ) { /* TODO check */
+                              if ("/".equals(o.image)) {
+                                  BigDecimal p = (BigDecimal) v1.get();
+                                  BigDecimal d = (BigDecimal) v2.get();
+                                  if (BigDecimal.ZERO.equals(d)) {
+                                  // TODO throw divided by zero error
+                                  }
+                                  p.divide(d);
+                                  v1.setValue(p);
+                              } else {
+                                  if ((v1.getType() != CssTypes.CSS_NUMBER) &&
+                                      (v2.getType() != CssTypes.CSS_NUMBER)) {
+                                  // TODO one operand must be a number
+                                  }
+                                  BigDecimal p = (BigDecimal) v1.get();
+                                  BigDecimal d = (BigDecimal) v2.get();
+                                  p.multiply(d);
+                                  if (v1.getType() == CssTypes.CSS_NUMBER) {
+                                     v2.setValue(p);
+                                     v1 = v2;
+                                  } else {
+                                     v1.setValue(p);
+                                  }
+                              }
+                          }
+                  )*
+ ) { return v1; }
+}
+
+CssCheckableValue mathunit() :
+{ Token n;
+CssCheckableValue v = null;
+}
+{
+( n=<NUMBER> { v = new CssNumber(); v.set(n.image, ac); }
+ | n=<PERCENTAGE> { v = new CssPercentage(); v.set(n.image, ac); }
+     | n=<RELFONTLENGTH> { v = new CssLength(); v.set(n.image, ac); }
+     | n=<RELVIEWLENGTH> { v = new CssLength(); v.set(n.image, ac); }
+     | n=<ABSOLUTLENGTH> { v = new CssLength(); v.set(n.image, ac); }
+     | n=<ANGLE> { v = new CssAngle(); v.set(n.image, ac); }
+     | n=<TIME> { v = new CssTime(); v.set(n.image, ac); }
+     | n=<FREQ> { v= new CssFrequency(); v.set(n.image, ac); }
+     | ( "(" ( <S> )* v=mathsum() ( <S> )* ")" )
+     | v=mathcalc()
+   // | v=attr()
+     ) {
+     return v;
+     }
+}
+
+
 /**
  * @exception ParseException exception during the parse
  */

Index: CssParser.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/analyzer/CssParser.java,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -d -r1.85 -r1.86
--- CssParser.java	4 Oct 2012 13:16:49 -0000	1.85
+++ CssParser.java	10 Oct 2012 07:47:30 -0000	1.86
@@ -31,12 +31,14 @@
 import org.w3c.css.properties.css.CssProperty;
 import org.w3c.css.parser.Frame;
 import org.w3c.css.parser.CssError;
+import org.w3c.css.parser.CssErrorToken;
 import org.w3c.css.parser.CssSelectors;
 import org.w3c.css.parser.CssParseException;
 import org.w3c.css.parser.AtRule;
 import org.w3c.css.media.AtRuleMedia;
 import org.w3c.css.media.MediaFeature;
 import org.w3c.css.parser.AtRuleFontFace;
+import org.w3c.css.parser.AtRuleKeyframes;
[...1846 lines suppressed...]
-    boolean[] la1tokens = new boolean[98];
+    boolean[] la1tokens = new boolean[102];
     if (jj_kind >= 0) {
       la1tokens[jj_kind] = true;
       jj_kind = -1;
     }
-    for (int i = 0; i < 143; i++) {
+    for (int i = 0; i < 168; i++) {
       if (jj_la1[i] == jj_gen) {
         for (int j = 0; j < 32; j++) {
           if ((jj_la1_0[i] & (1<<j)) != 0) {
@@ -4378,7 +4895,7 @@
         }
       }
     }
-    for (int i = 0; i < 98; i++) {
+    for (int i = 0; i < 102; i++) {
       if (la1tokens[i]) {
         jj_expentry = new int[1];
         jj_expentry[0] = i;

Index: CssParserConstants.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/analyzer/CssParserConstants.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- CssParserConstants.java	6 Sep 2012 12:37:53 -0000	1.21
+++ CssParserConstants.java	10 Oct 2012 07:47:31 -0000	1.22
@@ -153,55 +153,61 @@
   /** RegularExpression Id. */
   int FONT_FACE_SYM = 71;
   /** RegularExpression Id. */
-  int PREF_SYM = 72;
+  int KEYFRAMES_SYM = 72;
   /** RegularExpression Id. */
-  int COLOR_PROFILE = 73;
+  int PREF_SYM = 73;
   /** RegularExpression Id. */
-  int ATTOP = 74;
+  int COLOR_PROFILE = 74;
   /** RegularExpression Id. */
-  int ATRIGHT = 75;
+  int ATTOP = 75;
   /** RegularExpression Id. */
-  int ATBOTTOM = 76;
+  int ATRIGHT = 76;
   /** RegularExpression Id. */
-  int ATLEFT = 77;
+  int ATBOTTOM = 77;
   /** RegularExpression Id. */
-  int ATCOUNTER = 78;
+  int ATLEFT = 78;
   /** RegularExpression Id. */
-  int PHONETIC_ALPHABET_SYM = 79;
+  int ATCOUNTER = 79;
   /** RegularExpression Id. */
-  int ATKEYWORD = 80;
+  int PHONETIC_ALPHABET_SYM = 80;
   /** RegularExpression Id. */
-  int RANGE0 = 81;
+  int ATKEYWORD = 81;
   /** RegularExpression Id. */
-  int RANGE1 = 82;
+  int RANGE0 = 82;
   /** RegularExpression Id. */
-  int RANGE2 = 83;
+  int RANGE1 = 83;
   /** RegularExpression Id. */
-  int RANGE3 = 84;
+  int RANGE2 = 84;
   /** RegularExpression Id. */
-  int RANGE4 = 85;
+  int RANGE3 = 85;
   /** RegularExpression Id. */
-  int RANGE5 = 86;
+  int RANGE4 = 86;
   /** RegularExpression Id. */
-  int RANGE6 = 87;
+  int RANGE5 = 87;
   /** RegularExpression Id. */
-  int RANGE = 88;
+  int RANGE6 = 88;
   /** RegularExpression Id. */
-  int UNI = 89;
+  int RANGE = 89;
   /** RegularExpression Id. */
-  int UNICODERANGE = 90;
+  int UNI = 90;
   /** RegularExpression Id. */
-  int CLASS = 91;
+  int UNICODERANGE = 91;
   /** RegularExpression Id. */
-  int FUNCTIONLANG = 92;
+  int CLASS = 92;
   /** RegularExpression Id. */
-  int FUNCTIONNOT = 93;
+  int FUNCTIONLANG = 93;
   /** RegularExpression Id. */
-  int FUNCTION = 94;
+  int FUNCTIONNOT = 94;
   /** RegularExpression Id. */
-  int HTMLSTARTTAG = 95;
+  int FUNCTIONCALC = 95;
   /** RegularExpression Id. */
-  int HTMLENDTAG = 96;
+  int FUNCTIONATTR = 96;
+  /** RegularExpression Id. */
+  int FUNCTION = 97;
+  /** RegularExpression Id. */
+  int HTMLSTARTTAG = 98;
+  /** RegularExpression Id. */
+  int HTMLENDTAG = 99;
 
   /** Lexical state. */
   int DEFAULT = 0;
@@ -280,6 +286,7 @@
     "\"@media\"",
     "\"@page\"",
     "\"@font-face\"",
+    "\"@keyframes\"",
     "\"@preference\"",
     "\"@color-profile\"",
     "\"@top\"",
@@ -302,10 +309,13 @@
     "<CLASS>",
     "\"lang(\"",
     "\":not(\"",
+    "\"calc(\"",
+    "\"attr(\"",
     "<FUNCTION>",
     "<HTMLSTARTTAG>",
     "<HTMLENDTAG>",
     "\"|\"",
+    "\"+\"",
   };
 
 }
Received on Wednesday, 10 October 2012 07:47:34 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 15:17:52 UTC