2002/css-validator/org/w3c/css/parser/analyzer CssParser.java,1.54,1.55 CssParser.jj,1.54,1.55

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

Modified Files:
	CssParser.java CssParser.jj 
Log Message:
support of @charset (generating re-parsing using the new charset definition)

Index: CssParser.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/analyzer/CssParser.java,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- CssParser.java	14 Feb 2009 00:12:45 -0000	1.54
+++ CssParser.java	14 Feb 2009 09:05:03 -0000	1.55
@@ -106,6 +106,8 @@
      */
     protected boolean markRule;
 
+    private boolean reinited = false;
+
     static StringBuffer SPACE = new StringBuffer(" ");
 
     // to be able to remove a ruleset if the selector is not valid
@@ -162,18 +164,24 @@
      * @param stream the stream data to parse.
      * @param ac  the new ac to use for parsing.
      */
-    public void ReInitWithAc(InputStream stream, ApplContext ac, String charset) {
-        InputStream is = new  CommentSkipperInputStream(stream);
+    public void ReInitWithAc(InputStream stream, ApplContext ac,
+                             String charset)
+    {
+        InputStream is = /*new  CommentSkipperInputStream(stream);*/stream;
         if (charset == null) {
             charset = "iso-8859-1";
         }
         InputStreamReader isr = null;
         try {
             isr = new InputStreamReader(is, charset);
-        } catch (UnsupportedEncodingException uex) {}; // reinit, it can not happen...
+        } catch (UnsupportedEncodingException uex) {
+            isr = new InputStreamReader(is);
+        }
+        // reinit, it can not happen...
         // ...in theory ;)
         ReInit(isr);
         markRule = false;
+        reinited = true;
         setApplContext(ac);
     }
 
@@ -386,7 +394,8 @@
           jj_consume_token(-1);
           throw new ParseException();
         }
-            addError ( new ParseException(ac.getMsg().getString("generator.dontmixhtml")), n.image);
+            addError (
+new ParseException(ac.getMsg().getString("generator.dontmixhtml")), n.image);
       }
       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
       case CHARSET_SYM:
@@ -452,7 +461,8 @@
       }
       afterImportDeclaration();
     } catch (TokenMgrError err) {
-        addError (new ParseException(ac.getMsg().getString("generator.unrecognize")), err.getMessage());
+   addError (new ParseException(ac.getMsg().getString("generator.unrecognize")),
+             err.getMessage());
     }
     jj_consume_token(0);
   }
@@ -494,9 +504,10 @@
       }
       semicolonToken = jj_consume_token(SEMICOLON);
                 // the @charset must be at the beginning of the document
-                if(charsetToken.beginLine != 1 || charsetToken.beginColumn != 1) {
+                if(charsetToken.beginLine != 1 ||
+                   charsetToken.beginColumn != 1) {
                     {if (true) throw new ParseException(
-                                             ac.getMsg().getString("parser.charset"));}
+                                  ac.getMsg().getString("parser.charset"));}
                 }
                 // stricter rule for CSS21 and soon for CSS3
                 if ("css21".equals(ac.getCssVersion())) {
@@ -508,7 +519,8 @@
                     if ( (nb_S != 1) ||
                          (!"@charset".equals(charsetToken.image)) ||
                          (!" ".equals(space1Token.image)) ||
-                         (space2Token != null && !"".equals(space2Token.image)) ||
+                         (space2Token != null &&
+                          !"".equals(space2Token.image)) ||
                          (space1Token.specialToken != null) ||
                          (n.specialToken != null) ||
                          (semicolonToken.specialToken != null) ||
@@ -520,6 +532,7 @@
                 }
                 addCharSet(n.image.substring(1, n.image.length()-1));
     } catch (Exception e) {
+e.printStackTrace();
         String skip = charsetToken +
             ((space1Token == null) ? "" : space1Token.image) +
             n +
@@ -582,14 +595,13 @@
             }
           // quite ugly but necessary to avoid probably a lot of changes in the
           // grammar, still having a beatiful error message
-            else if(ret.startsWith("@charset")) {
+            else if (!reinited && ret.startsWith("@charset")) {
                 ParseException e =
                 new ParseException(ac.getMsg().getString("parser.charset"));
                 addError(e, ret);
-            }
-            else {
+            } else if (!reinited) {
                 ParseException e =
-                    new ParseException(ac.getMsg().getString("generator.unrecognize"));
+             new ParseException(ac.getMsg().getString("generator.unrecognize"));
                 addError(e, ret);
             }
       }
@@ -3616,14 +3628,6 @@
     finally { jj_save(0, xla); }
   }
 
-  final private boolean jj_3_1() {
-    Token xsp;
-    xsp = jj_scanpos;
-    if (jj_3R_83()) jj_scanpos = xsp;
-    if (jj_scan_token(98)) return true;
-    return false;
-  }
-
   final private boolean jj_3R_83() {
     Token xsp;
     xsp = jj_scanpos;
@@ -3634,6 +3638,14 @@
     return false;
   }
 
+  final private boolean jj_3_1() {
+    Token xsp;
+    xsp = jj_scanpos;
+    if (jj_3R_83()) jj_scanpos = xsp;
+    if (jj_scan_token(98)) return true;
+    return false;
+  }
+
   public CssParserTokenManager token_source;
   SimpleCharStream jj_input_stream;
   public Token token, jj_nt;

Index: CssParser.jj
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/analyzer/CssParser.jj,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- CssParser.jj	14 Feb 2009 00:12:32 -0000	1.54
+++ CssParser.jj	14 Feb 2009 09:05:03 -0000	1.55
@@ -126,6 +126,8 @@
      */  
     protected boolean markRule;
 
+    private boolean reinited = false;
+
     static StringBuffer SPACE = new StringBuffer(" ");
 
     // to be able to remove a ruleset if the selector is not valid
@@ -182,18 +184,24 @@
      * @param stream the stream data to parse.
      * @param ac  the new ac to use for parsing.
      */
-    public void ReInitWithAc(InputStream stream, ApplContext ac, String charset) {
-	InputStream is = new  CommentSkipperInputStream(stream);
+    public void ReInitWithAc(InputStream stream, ApplContext ac, 
+			     String charset)
+    {
+	InputStream is = /*new  CommentSkipperInputStream(stream);*/stream;
 	if (charset == null) {
 	    charset = "iso-8859-1";
 	}
 	InputStreamReader isr = null;
 	try {
 	    isr = new InputStreamReader(is, charset);
-	} catch (UnsupportedEncodingException uex) {}; // reinit, it can not happen...
+	} catch (UnsupportedEncodingException uex) {
+	    isr = new InputStreamReader(is);
+	}
+	// reinit, it can not happen...
 	// ...in theory ;)
     	ReInit(isr);
 	markRule = false;
+	reinited = true;
 	setApplContext(ac);
     }
   
@@ -621,14 +629,18 @@
     try {
 	// 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); } )*
+	    addError (
+new ParseException(ac.getMsg().getString("generator.dontmixhtml")), n.image); 
+	}
+	    )*
 	( charset() )?
 	    ( <S> | <CDO> | <CDC> )*
 	    ( importDeclaration() ( ignoreStatement() ) )*
 	    ( namespaceDeclaration() ( ignoreStatement() ) )*
 	    afterImportDeclaration()
 	 } catch (TokenMgrError err) {
-	addError (new ParseException(ac.getMsg().getString("generator.unrecognize")), err.getMessage());
+   addError (new ParseException(ac.getMsg().getString("generator.unrecognize")),
+	     err.getMessage());
     }
     <EOF>
 }
@@ -648,9 +660,10 @@
 	    n=<STRING> ( space2Token=<S> )* semicolonToken=<SEMICOLON>
 	    {
 		// the @charset must be at the beginning of the document
-		if(charsetToken.beginLine != 1 || charsetToken.beginColumn != 1) {                     
+		if(charsetToken.beginLine != 1 || 
+		   charsetToken.beginColumn != 1) {
 		    throw new ParseException(
-					     ac.getMsg().getString("parser.charset"));                    
+				  ac.getMsg().getString("parser.charset"));
 		}
 	        // stricter rule for CSS21 and soon for CSS3
 		if ("css21".equals(ac.getCssVersion())) {
@@ -662,7 +675,8 @@
 		    if ( (nb_S != 1) ||
 			 (!"@charset".equals(charsetToken.image)) ||
 			 (!" ".equals(space1Token.image)) || 
-			 (space2Token != null && !"".equals(space2Token.image)) ||
+			 (space2Token != null && 
+			  !"".equals(space2Token.image)) ||
 			 (space1Token.specialToken != null) ||
 			 (n.specialToken != null) ||
 			 (semicolonToken.specialToken != null) ||
@@ -675,6 +689,7 @@
 		addCharSet(n.image.substring(1, n.image.length()-1));
 	    }
     } catch (Exception e) {
+e.printStackTrace();
 	String skip = charsetToken +
 	    ((space1Token == null) ? "" : space1Token.image) +
 	    n +
@@ -695,14 +710,13 @@
 	    }
 	  // quite ugly but necessary to avoid probably a lot of changes in the
 	  // grammar, still having a beatiful error message
-	    else if(ret.startsWith("@charset")) {
+	    else if (!reinited && ret.startsWith("@charset")) {
 		ParseException e = 
 		new ParseException(ac.getMsg().getString("parser.charset"));
 		addError(e, ret);
-	    }
-	    else {
+	    } else if (!reinited) {
 		ParseException e = 
-		    new ParseException(ac.getMsg().getString("generator.unrecognize"));
+	     new ParseException(ac.getMsg().getString("generator.unrecognize"));
 		addError(e, ret);
 	    }
 	}

Received on Saturday, 14 February 2009 09:05:15 UTC