- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Fri, 21 Oct 2011 01:49:11 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/parser/analyzer In directory hutz:/tmp/cvs-serv28700/org/w3c/css/parser/analyzer Modified Files: CssParser.java CssParser.jj CssParserConstants.java CssParserTokenManager.java Log Message: redone the Media Features of media queries, up to date per http://www.w3.org/TR/2010/CR-css3-mediaqueries-20100727/, todo, parsing of media in HTML form Index: CssParserTokenManager.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/analyzer/CssParserTokenManager.java,v retrieving revision 1.39 retrieving revision 1.40 diff -u -d -r1.39 -r1.40 --- CssParserTokenManager.java 14 Sep 2011 16:31:49 -0000 1.39 +++ CssParserTokenManager.java 21 Oct 2011 01:49:09 -0000 1.40 @@ -28,7 +28,8 @@ import org.w3c.css.parser.CssSelectors; import org.w3c.css.parser.CssParseException; import org.w3c.css.parser.AtRule; -import org.w3c.css.parser.AtRuleMedia; +import org.w3c.css.media.AtRuleMedia; +import org.w3c.css.media.MediaFeature; import org.w3c.css.parser.AtRuleFontFace; import org.w3c.css.parser.AtRulePage; import org.w3c.css.parser.AtRulePreference; @@ -77,46 +78,46 @@ switch(curChar) [...1360 lines suppressed...] if (!jjCanMove_0(hiByte, i1, i2, l1, l2)) break; - if (kind > 36) - kind = 36; + if (kind > 37) + kind = 37; jjCheckNAddTwoStates(428, 429); break; case 443: @@ -6085,8 +6086,8 @@ "", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, "\74\41\55\55", "\55\55\76", null, "\174\75", null, null, null, null, null, null, null, null, null, null, null, -"\175", "\136\75", "\44\75", "\52\75", "\75", "\55", "\73", "\57", "\133", "\135", -"\52", "\56", "\51", "\50", "\72", null, null, null, null, null, null, null, null, +null, "\175", "\136\75", "\44\75", "\52\75", "\75", "\55", "\73", "\57", "\133", +"\135", "\52", "\56", "\51", "\50", "\72", null, 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", }; Index: CssParser.jj =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/analyzer/CssParser.jj,v retrieving revision 1.76 retrieving revision 1.77 diff -u -d -r1.76 -r1.77 --- CssParser.jj 29 Sep 2011 09:08:58 -0000 1.76 +++ CssParser.jj 21 Oct 2011 01:49:09 -0000 1.77 @@ -11,10 +11,10 @@ IGNORE_CASE = true; STATIC = false; UNICODE_INPUT = true; - /* + /* DEBUG_TOKEN_MANAGER = true; DEBUG_PARSER = true; - */ + */ } PARSER_BEGIN(CssParser) @@ -50,7 +50,8 @@ import org.w3c.css.parser.CssSelectors; import org.w3c.css.parser.CssParseException; import org.w3c.css.parser.AtRule; -import org.w3c.css.parser.AtRuleMedia; +import org.w3c.css.media.AtRuleMedia; +import org.w3c.css.media.MediaFeature; import org.w3c.css.parser.AtRuleFontFace; import org.w3c.css.parser.AtRulePage; import org.w3c.css.parser.AtRulePreference; @@ -95,7 +96,7 @@ 'c', 'd', 'e', 'f' }; // the current atRule protected AtRule atRule; - protected String mediaDeclaration = "off"; + protected boolean mediaDeclaration = false; /** * The URL of the document @@ -159,7 +160,7 @@ * * @param mediaDeclaration indicator if in a media expression list or not */ - public void setMediaDeclaration(String mediadeclaration) { + public void setMediaDeclaration(boolean mediadeclaration) { this.mediaDeclaration = mediadeclaration; } @@ -168,7 +169,7 @@ * * @return the value of the attribute */ - public String getMediaDeclaration() { + public boolean hasMediaDeclaration() { return mediaDeclaration; } @@ -270,6 +271,26 @@ throws InvalidParamException; /** + * Assign an expression to a mediafeature. + * This function create a new mediafeature + * with <code>featureName</code> and assign to it the expression. + * <p> + * A subclass must provide an implementation of this method. + * + * @param featureName the name of the media feature + * @param expr the expression representation of values + * + * @return <code>null</code>or a property + * + * @see org.w3c.css.css.CssProperty + */ + public abstract MediaFeature handleMediaFeature(String mediaFeature, + CssExpression expr) + throws InvalidParamException; + + + + /** * Adds a ArrayList of properties to a selector. * <p> * A subclass must provide an implementation of this method. @@ -449,6 +470,11 @@ < AND : "and" > } +TOKEN [IGNORE_CASE] : +{ + < MEDIARESTRICTOR : "only" | "not" > +} + <DEFAULT> TOKEN : { @@ -487,12 +513,6 @@ <DEFAULT> TOKEN [IGNORE_CASE] : { - < MEDIARESTRICTOR : "only" | "not" > -} - -<DEFAULT> -TOKEN [IGNORE_CASE] : -{ < URL : "url(" ( <S> )* ( <STRING> | <_URL> ) ( <S> )* ")" > } @@ -547,7 +567,7 @@ | < FONT_FACE_SYM : "@font-face" > | < PREF_SYM : "@preference" > | < COLOR_PROFILE : "@color-profile" > - | < ATTOP : "@top" > + | < ATTOP : "@top" > | < ATRIGHT : "@right" > | < ATBOTTOM : "@bottom" > | < ATLEFT : "@left" > @@ -803,7 +823,7 @@ */ void importDeclaration() : {Token n; - AtRuleMedia media = new AtRuleMedia(); + AtRuleMedia media = AtRuleMedia.getInstance(ac.getCssVersion()); CssValue val; String importFile; boolean is_url = false; @@ -827,9 +847,7 @@ } ) ( <S> )* - ( medium(media) - ( <COMMA> ( <S> )* medium(media) - )* )? <SEMICOLON> + ( mediaquerylist(media) )? <SEMICOLON> ( <S> )* { handleImport(getURL(), importFile, is_url, media); @@ -845,7 +863,7 @@ void media() : { AtRule old = getAtRule(); - AtRuleMedia newRule = new AtRuleMedia(); + AtRuleMedia newRule = AtRuleMedia.getInstance(ac.getCssVersion()); setAtRule(newRule); Token n; CssProperty p = null; @@ -853,62 +871,88 @@ } { try { - <MEDIA_SYM> ( <S> )* - // <CSS3> - (n=<MEDIARESTRICTOR> { newRule.addMediaRestrictor(convertIdent(n.image), ac); } ( <S> )+)? - medium(newRule) - // </CSS3> - ( <COMMA> ( <S> )* medium(newRule) )* - // <CSS3> - (<AND> ( <S> )* <RPARAN> ( <S> )* p=mediadeclaration() { newRule.addMediaFeature(p); } <LPARAN> ( <S> )* )* - // </CSS3> - + n=<MEDIA_SYM> ( <S> )* + mediaquerylist(newRule) { - String media = getAtRule().toString(); - if (ac.getMedium() != null && - !(media.equals(ac.getMedium())) && - !(ac.getMedium().equals("all"))) { + String media = getAtRule().toString(); + if (ac.getMedium() != null && + !(media.equals(ac.getMedium())) && + !(ac.getMedium().equals("all"))) { - ac.getFrame().addWarning("noothermedium", - getAtRule().toString()); - } - if (isCss1) { - skipStatement(); - addError(new InvalidParamException("noatruleyet", "", ac), - getAtRule().toString()); - } else { - newAtRule(getAtRule()); - } + ac.getFrame().addWarning("noothermedium", getAtRule().toString()); + } + if (isCss1) { + skipStatement(); + addError(new InvalidParamException("noatruleyet", "", ac), + getAtRule().toString()); + } else { + newAtRule(getAtRule()); + } } <LBRACE> ( <S> )* ( ruleSet() )* <RBRACE> ( <S> )* { - if (!isCss1) { - endOfAtRule(); - } + if (!isCss1) { + endOfAtRule(); + } } } catch (ParseException e) { - if (!isCss1) { - addError(e, skipStatement()); - } - } finally { - setAtRule(old); + if (!isCss1) { + addError(e, skipStatement()); + } + } finally { + setAtRule(old); } } -/** - * @exception ParseException exception during the parse - */ -void medium(AtRuleMedia media) : /* tv, projection, screen, ... */ -{Token n;} + +void mediaquerylist(AtRuleMedia mediaRule) : { - n=<IDENT> ( <S> )* - { - try { - media.addMedia(convertIdent(n.image), ac); - } catch (InvalidParamException e) { - CssError error = new CssError(getSourceFile(), getLine(), e); - ac.getFrame().addError(error); - } + CssVersion v = ac.getCssVersion(); + boolean isCss1 = (v == CssVersion.CSS1); +} +{ + mediaquery(mediaRule) + ( <COMMA> ( <S> )* mediaquery(mediaRule) )* +} + +void mediaquery(AtRuleMedia mediaRule) : +{ + CssVersion v = ac.getCssVersion(); + boolean isCss1 = (v == CssVersion.CSS1); + Token n; + String mediarestrictor = null; +} +{ + ( ( (n=<MEDIARESTRICTOR> { + mediarestrictor = convertIdent(n.image); + } ( <S> )+ )? + n=<IDENT> { mediaRule.addMedia(mediarestrictor, convertIdent(n.image), ac); } ( <S> )* + (<AND> ( <S> )+ mediaexpression(mediaRule, false) )* ) | + (mediaexpression(mediaRule, true) (<AND> ( <S> )+ mediaexpression(mediaRule, false) )* ) ) { + + } +} + +void mediaexpression(AtRuleMedia mediaRule, boolean defaultMedia) : +{ + CssVersion v = ac.getCssVersion(); + boolean isCss1 = (v == CssVersion.CSS1); + CssExpression val = null; + String mediaFeatureName = null; + Token n; +} +{ + <RPARAN> ( <S> )* n=<IDENT> { + // here we add the default media if not present + if (defaultMedia) { + mediaRule.addMedia(null, null, ac); + } + mediaFeatureName = convertIdent(n.image); } + ( <S> )* + ( <COLON> ( <S> )* val=expr() )? + <LPARAN> ( <S> )* { + MediaFeature mf = handleMediaFeature(mediaFeatureName, val); + mediaRule.addMediaFeature(mf, ac); } } @@ -1414,7 +1458,7 @@ throw new InvalidParamException("nocomb", "+", ac); } } - // FIXME should be >= css3 + // if version < CSS3, ~ is undefined if (ac.getCssVersion().compareTo(CssVersion.CSS3) < 0) { if (comb == '~') { throw new InvalidParamException("nocomb", "~", ac); @@ -1922,7 +1966,7 @@ { String string_property; CssExpression values = null; boolean important = false; - setMediaDeclaration("on"); + setMediaDeclaration(true); } { try { @@ -1958,7 +2002,7 @@ skipAfterExpression(e); return null; } finally { - setMediaDeclaration("off"); + setMediaDeclaration(false); } } Index: CssParser.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/analyzer/CssParser.java,v retrieving revision 1.77 retrieving revision 1.78 diff -u -d -r1.77 -r1.78 --- CssParser.java 4 Oct 2011 13:05:22 -0000 1.77 +++ CssParser.java 21 Oct 2011 01:49:09 -0000 1.78 @@ -30,7 +30,8 @@ import org.w3c.css.parser.CssSelectors; import org.w3c.css.parser.CssParseException; import org.w3c.css.parser.AtRule; -import org.w3c.css.parser.AtRuleMedia; +import org.w3c.css.media.AtRuleMedia; +import org.w3c.css.media.MediaFeature; import org.w3c.css.parser.AtRuleFontFace; import org.w3c.css.parser.AtRulePage; import org.w3c.css.parser.AtRulePreference; @@ -75,7 +76,7 @@ 'c', 'd', 'e', 'f' }; [...1948 lines suppressed...] } @@ -3868,7 +3952,7 @@ token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 130; i++) jj_la1[i] = -1; + for (int i = 0; i < 134; i++) jj_la1[i] = -1; for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); } @@ -3985,7 +4069,7 @@ la1tokens[jj_kind] = true; jj_kind = -1; } - for (int i = 0; i < 130; i++) { + for (int i = 0; i < 134; i++) { if (jj_la1[i] == jj_gen) { for (int j = 0; j < 32; j++) { if ((jj_la1_0[i] & (1<<j)) != 0) { Index: CssParserConstants.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/analyzer/CssParserConstants.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- CssParserConstants.java 17 Dec 2009 16:08:11 -0000 1.16 +++ CssParserConstants.java 21 Oct 2011 01:49:09 -0000 1.17 @@ -73,47 +73,47 @@ /** RegularExpression Id. */ int AND = 31; /** RegularExpression Id. */ - int STRING = 32; + int MEDIARESTRICTOR = 32; /** RegularExpression Id. */ - int INVALID = 33; + int STRING = 33; /** RegularExpression Id. */ - int IDENT = 34; + int INVALID = 34; /** RegularExpression Id. */ - int HASHIDENT = 35; + int IDENT = 35; /** RegularExpression Id. */ - int HASH = 36; + int HASHIDENT = 36; /** RegularExpression Id. */ - int RBRACE = 37; + int HASH = 37; /** RegularExpression Id. */ - int PREFIXMATCH = 38; + int RBRACE = 38; /** RegularExpression Id. */ - int SUFFIXMATCH = 39; + int PREFIXMATCH = 39; /** RegularExpression Id. */ - int SUBSTRINGMATCH = 40; + int SUFFIXMATCH = 40; /** RegularExpression Id. */ - int EQ = 41; + int SUBSTRINGMATCH = 41; /** RegularExpression Id. */ - int MINUS = 42; + int EQ = 42; /** RegularExpression Id. */ - int SEMICOLON = 43; + int MINUS = 43; /** RegularExpression Id. */ - int DIV = 44; + int SEMICOLON = 44; /** RegularExpression Id. */ - int LBRACKET = 45; + int DIV = 45; /** RegularExpression Id. */ - int RBRACKET = 46; + int LBRACKET = 46; /** RegularExpression Id. */ - int ANY = 47; + int RBRACKET = 47; /** RegularExpression Id. */ - int DOT = 48; + int ANY = 48; /** RegularExpression Id. */ - int LPARAN = 49; + int DOT = 49; /** RegularExpression Id. */ - int RPARAN = 50; + int LPARAN = 50; /** RegularExpression Id. */ - int COLON = 51; + int RPARAN = 51; /** RegularExpression Id. */ - int MEDIARESTRICTOR = 52; + int COLON = 52; /** RegularExpression Id. */ int URL = 53; /** RegularExpression Id. */ @@ -242,6 +242,7 @@ "<COMMA>", "<TILDE>", "\"and\"", + "<MEDIARESTRICTOR>", "<STRING>", "<INVALID>", "<IDENT>", @@ -262,7 +263,6 @@ "\")\"", "\"(\"", "\":\"", - "<MEDIARESTRICTOR>", "<URL>", "<LENGTH>", "<EMS>",
Received on Friday, 21 October 2011 01:49:49 UTC