W3C home > Mailing lists > Public > www-validator-cvs@w3.org > March 2008

2002/css-validator/org/w3c/css/parser/analyzer CssParser.jj,1.37,1.38

From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
Date: Fri, 28 Mar 2008 14:58:45 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1JfG2X-0006Fj-KD@lionel-hutz.w3.org>

Update of /sources/public/2002/css-validator/org/w3c/css/parser/analyzer
In directory hutz:/tmp/cvs-serv23969

Modified Files:
	CssParser.jj 
Log Message:
swtich comments from SKIP to SPECIAL_TOKEN to test in @charset that no comments exists 
between "@charset" and the first "


Index: CssParser.jj
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/analyzer/CssParser.jj,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- CssParser.jj	28 Mar 2008 08:01:49 -0000	1.37
+++ CssParser.jj	28 Mar 2008 14:58:43 -0000	1.38
@@ -10,7 +10,7 @@
 options {
     IGNORE_CASE  = true;
     STATIC = false;
-    /*    DEBUG_TOKEN_MANAGER = true; 
+/*        DEBUG_TOKEN_MANAGER = true; 
 	  DEBUG_PARSER = true;      */
 }
 
@@ -347,28 +347,9 @@
  */
 
 <DEFAULT>
-    MORE : 
-{
-    < "/*" > : IN_COMMENT
-}
-
-<IN_COMMENT>
-    SKIP :
-{
-    < "*/" > : DEFAULT
-}
-
-<IN_COMMENT>
-    MORE :
-{
-    < ~[] > : IN_COMMENT
-}
-
-
-<DEFAULT>
-SKIP :
+SPECIAL_TOKEN :
 {
-    < #COMMENT : "/*" ( ~["*"] )* ( "*" )+ ( ~["/", "*"] ( ~["*"] )* ( "*" )+ )* "/" >
+    < COMMENT : "/*" ( ~["*"] )* ( "*" )+ ( ~["/", "*"] ( ~["*"] )* ( "*" )+ )* "/" >
 } 
 
 <DEFAULT>
@@ -391,7 +372,7 @@
   | < #_STRING    : <STRING1> | <STRING2> >
   | < #_INVALID   : <INVALID1> | <INVALID2> >
   | < #_URL       : ( [ "!", "#", "$", "%", "&", "*", "+", "-"-"[", "]"-"~" ] | <NONASCII> | <ESCAPE> )* >
-  | < #_S         : ( [ " ", "\t" , "\n" , "\r", "\f" ] ( <COMMENT> )? )+ >
+  | < #_S         : ( [ " ", "\t" , "\n" , "\r", "\f" ] )+ >
   | < #_W         : ( <_S> )? >
   | < #NL         : ( "\n" | "\r\n" | "\r" | "\f" ) >
 }
@@ -509,7 +490,7 @@
 
 /* RESERVED ATRULE WORDS */
 <DEFAULT>
-TOKEN : // FIXME force to be case-sensitive
+TOKEN : 
 {
    < CHARSET_SYM           : "@charset" >
 }
@@ -602,7 +583,7 @@
 	// used as an error recovery for HTML tags in CSS pages
         ( ( n=<HTMLSTARTTAG> | n=<HTMLENDTAG> ) {
 	    addError ( new ParseException(ac.getMsg().getString("generator.dontmixhtml")), n.image); } )*
-	( charset() ";" )?
+	( charset() )?
 	    ( <S> | <CDO> | <CDC> )*
 	    ( importDeclaration() ( ignoreStatement() ) )*
 	    afterImportDeclaration()
@@ -618,28 +599,37 @@
     Token charsetToken = null;
     Token space1Token = null;
     Token space2Token = null;
+    Token semicolonToken = null;
+    int nb_S = 0;
 }
 {  
     try {
-	// There was * instead of ? in previous versions, but it's useless since
-	// <S> is already a +
-	charsetToken=<CHARSET_SYM> ( space1Token=<S> )? n=<STRING> ( space2Token=<S> )?
+	charsetToken=<CHARSET_SYM> ( space1Token=<S> { nb_S++;} )* 
+	    n=<STRING> ( space2Token=<S> )* semicolonToken=<SEMICOLON>
 	    {
 		// the @charset must be at the beginning of the document
 		if(charsetToken.beginLine != 1 || charsetToken.beginColumn != 1) {                     
 		    throw new ParseException(
 					     ac.getMsg().getString("parser.charset"));                    
 		}
-	        // stricter rule for CSS21 and soon for CSS3
-		else if("css21".equals(ac.getCssVersion()) &&
-			(!" ".equals(space1Token.image) || (space2Token != null &&
-							    !"".equals(space2Token.image)))) {
-		    throw new ParseException(ac.getMsg().getString(
-								   "parser.charsetspecial"));
+		// the @charset is case sensitive
+		if (!"@charset".equals(charsetToken.image)) {
+		    throw new ParseException(
+			ac.getMsg().getString("parser.charsetspecial"));   
 		}
-		else {
-		    addCharSet(n.image);                    
+	        // stricter rule for CSS21 and soon for CSS3
+		if ("css21".equals(ac.getCssVersion())) {
+		    if ( (nb_S != 1) ||
+			 (!" ".equals(space1Token.image)) || 
+			 (space2Token != null && !"".equals(space2Token.image)) ||
+			 (space1Token.specialToken != null) ||
+			 (semicolonToken.specialToken != null)
+			) {
+			throw new ParseException(ac.getMsg().getString(
+						     "parser.charsetspecial"));
+		    }
 		}
+		addCharSet(n.image);                    
 	    }
     } catch (Exception e) {
 	String skip = charsetToken +
Received on Friday, 28 March 2008 14:59:22 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 26 April 2012 12:55:00 GMT