2002/css-validator/org/w3c/css/parser/analyzer CssParser.jj,1.66,1.67

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

Modified Files:
	CssParser.jj 
Log Message:
fixes http://www.w3.org/Bugs/Public/show_bug.cgi?id=6640
The parser now uses ( charset() )* instead of ( charset() )? as the reinit 
would otherwise skip to afterImportDeclaration. It uses some flags to control 
the re-parsing of the same @charset token (although changing the parser state 
would have been another solution)


Index: CssParser.jj
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/analyzer/CssParser.jj,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -d -r1.66 -r1.67
--- CssParser.jj	25 Feb 2009 00:11:31 -0000	1.66
+++ CssParser.jj	1 Mar 2009 09:05:48 -0000	1.67
@@ -127,6 +127,7 @@
     protected boolean markRule;
 
     private boolean reinited = false;
+    private boolean charsetdeclared = false;
 
     static StringBuilder SPACE = new StringBuilder(" ");
 
@@ -633,7 +634,7 @@
 new ParseException(ac.getMsg().getString("generator.dontmixhtml")), n.image); 
 	}
 	    )*
-	( charset() )?
+	  ( charset() )* // * instead of ? to capture the reinit part
 	    ( <S> | <CDO> | <CDC> )*
 	    ( importDeclaration() ( ignoreStatement() ) )*
 	    ( namespaceDeclaration() ( ignoreStatement() ) )*
@@ -659,6 +660,10 @@
 	charsetToken=<CHARSET_SYM> ( space1Token=<S> { nb_S++;} )* 
 	    n=<STRING> ( space2Token=<S> )* semicolonToken=<SEMICOLON>
 	    {
+		if (charsetdeclared && !reinited) {
+		    throw new ParseException(
+				     ac.getMsg().getString("parser.charset"));
+		}
 		// the @charset must be at the beginning of the document
 		if(charsetToken.beginLine != 1 || 
 		   charsetToken.beginColumn != 1) {
@@ -690,7 +695,12 @@
 						     "parser.charsetspecial"));
 		    }
 		}
-		addCharSet(n.image.substring(1, n.image.length()-1));
+		if (!charsetdeclared) {
+		    addCharSet(n.image.substring(1, n.image.length()-1));
+		    charsetdeclared = true;
+		} else {
+		    reinited = false;
+		}
 	    }
     } catch (Exception e) {
 	String skip = charsetToken +
@@ -712,15 +722,15 @@
 	    }
 	  // quite ugly but necessary to avoid probably a lot of changes in the
 	  // grammar, still having a beautiful error message
-	    else if (!reinited && ret.startsWith("@charset")) {
+	    else if (ret.startsWith("@charset")) {
 		ParseException e = 
 		new ParseException(ac.getMsg().getString("parser.charset"));
 		addError(e, ret);
-	    } else if (!reinited && ret.startsWith("@import")) {
+	    } else if (ret.startsWith("@import")) {
 		ParseException e = 
 		new ParseException(ac.getMsg().getString("parser.import_not_allowed"));
 		addError(e, ret);
-	    } else if (!reinited) {
+	    } else {
 		ParseException e = 
 	     new ParseException(ac.getMsg().getString("generator.unrecognize"));
 		addError(e, ret);

Received on Sunday, 1 March 2009 09:06:04 UTC