- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Thu, 13 Mar 2008 14:24:41 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/parser/analyzer In directory hutz:/tmp/cvs-serv24985 Modified Files: CssParser.jj Log Message: Added special case for HTML tags at the beginning of CSS files (common error) It fixes http://www.w3.org/Bugs/Public/show_bug.cgi?id=4469 There is also a top-level catch of Token errors. skipStatement fixed to avoid returning null when multiple tokens are read before <EOF> is reached Index: CssParser.jj =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/analyzer/CssParser.jj,v retrieving revision 1.27 retrieving revision 1.28 diff -u -d -r1.27 -r1.28 --- CssParser.jj 12 Mar 2008 16:24:00 -0000 1.27 +++ CssParser.jj 13 Mar 2008 14:24:39 -0000 1.28 @@ -11,8 +11,7 @@ IGNORE_CASE = true; STATIC = false; /* DEBUG_TOKEN_MANAGER = true; - DEBUG_PARSER = true; */ - + DEBUG_PARSER = true; */ } PARSER_BEGIN(CssParser) @@ -77,7 +76,7 @@ /** * A CSS3 parser * - * @author Philippe Le H???garet and Sijtsche Smeman + * @author Philippe Le Hegaret and Sijtsche Smeman * @version $Revision$ */ public abstract class CssParser { @@ -559,6 +558,17 @@ < FUNCTION : <IDENT> "(" > } +/* Quick and dirty way to catch HTML tags starting CSS documents + (common mistake) */ +<DEFAULT> + TOKEN: +{ + <HTMLSTARTTAG : "<" ( <S> )* <IDENT> ( <S> )* + ( <IDENT> "=" ( <IDENT> | <STRING> ) ( <S> )* )* + ">" > + | <HTMLENDTAG : "</" ( <S> )* <IDENT> ( <S> )* ">" > +} + //<DEFAULT, IN_COMMENT> //TOKEN : //{ /* avoid token manager error */ @@ -575,12 +585,21 @@ * @exception ParseException exception during the parse */ void parserUnit() : -{} { - ( charset() )? - ( <S> | ignoreStatement() )* - ( importDeclaration() ( ignoreStatement() ( <S> )* )* )* - afterImportDeclaration() + Token n = null; +} +{ + try { + // used as an error recovery for HTML tags in CSS pages + ( ( n=<HTMLSTARTTAG> | n=<HTMLENDTAG> ) { + addError ( new ParseException(ac.getMsg().getString("Parse error - Unrecognized")), n.image); } )* + ( charset() )? + ( <S> | ignoreStatement() )* + ( importDeclaration() ( ignoreStatement() ( <S> )* )* )* + afterImportDeclaration() + } catch (TokenMgrError err) { + addError (new ParseException(ac.getMsg().getString("Parse error - Unrecognized")), err.getMessage()); + } <EOF> } @@ -641,7 +660,7 @@ } else { ParseException e = - new ParseException("Parse error - Unrecognized "); + new ParseException(ac.getMsg().getString("Parse error - Unrecognized")); addError(e, ret); } } @@ -1882,6 +1901,8 @@ String skipStatement() { StringBuffer s = new StringBuffer(); Token tok = getToken(0); + boolean first = true; + if (tok.image != null) { s.append(tok.image); } @@ -1895,7 +1916,11 @@ try { tok = getToken(1); if (tok.kind == EOF) { - return null; + if (first) { + return null; + } else { + break; + } } s.append(tok.image); if (tok.kind == LBRACE) { @@ -1919,6 +1944,7 @@ return s.toString().trim(); } } + first = false; } // skip white space
Received on Thursday, 13 March 2008 14:25:16 UTC