- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Thu, 12 Feb 2009 21:26:37 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/parser/analyzer In directory hutz:/tmp/cvs-serv1130/org/w3c/css/parser/analyzer Modified Files: CssParser.java CssParser.jj CssParserConstants.java CssParserTokenManager.java Log Message: pseudo-function handling, per CSS3 selectors rules (note that some construction forbidden by the text are ok according to the grammar, so extra checks are needed) Initial support of namespaces. Index: CssParserTokenManager.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/analyzer/CssParserTokenManager.java,v retrieving revision 1.30 retrieving revision 1.31 diff -u -d -r1.30 -r1.31 --- CssParserTokenManager.java 12 Feb 2009 10:32:52 -0000 1.30 +++ CssParserTokenManager.java 12 Feb 2009 21:26:35 -0000 1.31 @@ -90,7 +90,7 @@ return jjMoveNfa_0(7, 0); case 58: jjmatchedKind = 51; - return jjMoveStringLiteralDfa1_0(0x0L, 0x4L); + return jjMoveStringLiteralDfa1_0(0x0L, 0x40000004L); case 59: jjmatchedKind = 43; return jjMoveNfa_0(7, 0); @@ -100,7 +100,7 @@ jjmatchedKind = 41; return jjMoveNfa_0(7, 0); [...1438 lines suppressed...] + if (kind > 92) + kind = 92; jjCheckNAddTwoStates(649, 650); break; default : break; @@ -5995,12 +6012,12 @@ "\52", "\56", "\51", "\50", "\72", null, 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, null, null, null, null, null, null, null, null, null, "\174", }; public static final String[] lexStateNames = { "DEFAULT", }; static final long[] jjtoToken = { - 0xffffffffffe00001L, 0xfc01ffffL, + 0xffffffffffe00001L, 0x7f803ffffL, }; static final long[] jjtoSkip = { 0x2L, 0x0L, Index: CssParser.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/analyzer/CssParser.java,v retrieving revision 1.50 retrieving revision 1.51 diff -u -d -r1.50 -r1.51 --- CssParser.java 12 Feb 2009 10:32:51 -0000 1.50 +++ CssParser.java 12 Feb 2009 21:26:35 -0000 1.51 @@ -415,6 +415,19 @@ importDeclaration(); ignoreStatement(); } + label_4: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case NAMESPACE_SYM: + ; + break; + default: + jj_la1[6] = jj_gen; [...2197 lines suppressed...] + jj_rescan = false; + } + + final private void jj_save(int index, int xla) { + JJCalls p = jj_2_rtns[index]; + while (p.gen > jj_gen) { + if (p.next == null) { p = p.next = new JJCalls(); break; } + p = p.next; + } + p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla; + } + + static final class JJCalls { + int gen; + Token first; + int arg; + JJCalls next; + } + } Index: CssParserConstants.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/analyzer/CssParserConstants.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- CssParserConstants.java 11 Feb 2009 21:45:35 -0000 1.14 +++ CssParserConstants.java 12 Feb 2009 21:26:35 -0000 1.15 @@ -69,36 +69,38 @@ int PERCENTAGE = 63; int NUMBER = 64; int IMPORTANT_SYM = 65; - int PSEUDOCLASS_SYM = 66; + int PSEUDOELEMENT_SYM = 66; int CHARSET_SYM = 67; int IMPORT_SYM = 68; - int MEDIA_SYM = 69; - int PAGE_SYM = 70; - int FONT_FACE_SYM = 71; - int PREF_SYM = 72; - int COLOR_PROFILE = 73; - int ATTOP = 74; - int ATRIGHT = 75; - int ATBOTTOM = 76; - int ATLEFT = 77; - int ATCOUNTER = 78; - int PHONETIC_ALPHABET_SYM = 79; - int ATKEYWORD = 80; - int RANGE0 = 81; - int RANGE1 = 82; - int RANGE2 = 83; - int RANGE3 = 84; - int RANGE4 = 85; - int RANGE5 = 86; - int RANGE6 = 87; - int RANGE = 88; - int UNI = 89; - int UNICODERANGE = 90; - int CLASS = 91; - int FUNCTIONLANG = 92; - int FUNCTION = 93; - int HTMLSTARTTAG = 94; - int HTMLENDTAG = 95; + int NAMESPACE_SYM = 69; + int MEDIA_SYM = 70; + int PAGE_SYM = 71; + int FONT_FACE_SYM = 72; + int PREF_SYM = 73; + int COLOR_PROFILE = 74; + int ATTOP = 75; + int ATRIGHT = 76; + int ATBOTTOM = 77; + int ATLEFT = 78; + int ATCOUNTER = 79; + int PHONETIC_ALPHABET_SYM = 80; + int ATKEYWORD = 81; + int RANGE0 = 82; + int RANGE1 = 83; + int RANGE2 = 84; + int RANGE3 = 85; + int RANGE4 = 86; + int RANGE5 = 87; + int RANGE6 = 88; + int RANGE = 89; + int UNI = 90; + int UNICODERANGE = 91; + int CLASS = 92; + int FUNCTIONLANG = 93; + int FUNCTIONNOT = 94; + int FUNCTION = 95; + int HTMLSTARTTAG = 96; + int HTMLENDTAG = 97; int DEFAULT = 0; @@ -172,6 +174,7 @@ "\"::\"", "\"@charset\"", "\"@import\"", + "\"@namespace\"", "\"@media\"", "\"@page\"", "\"@font-face\"", @@ -196,9 +199,11 @@ "<UNICODERANGE>", "<CLASS>", "\"lang(\"", + "\":not(\"", "<FUNCTION>", "<HTMLSTARTTAG>", "<HTMLENDTAG>", + "\"|\"", }; } Index: CssParser.jj =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/analyzer/CssParser.jj,v retrieving revision 1.50 retrieving revision 1.51 diff -u -d -r1.50 -r1.51 --- CssParser.jj 12 Feb 2009 10:32:52 -0000 1.50 +++ CssParser.jj 12 Feb 2009 21:26:35 -0000 1.51 @@ -493,7 +493,7 @@ <DEFAULT> TOKEN : { - <PSEUDOCLASS_SYM : "::" > + <PSEUDOELEMENT_SYM : "::" > } /* RESERVED ATRULE WORDS */ @@ -507,6 +507,7 @@ TOKEN [IGNORE_CASE] : { < IMPORT_SYM : "@import"> + | < NAMESPACE_SYM : "@namespace"> | < MEDIA_SYM : "@media" > | < PAGE_SYM : "@page" > | < FONT_FACE_SYM : "@font-face" > @@ -551,6 +552,13 @@ } <DEFAULT> +TOKEN [IGNORE_CASE] : +{ + < FUNCTIONNOT : ":not(" > +} + + +<DEFAULT> TOKEN : { < FUNCTION : <IDENT> "(" > @@ -594,6 +602,7 @@ ( charset() )? ( <S> | <CDO> | <CDC> )* ( importDeclaration() ( ignoreStatement() ) )* + ( namespaceDeclaration() ( ignoreStatement() ) )* afterImportDeclaration() } catch (TokenMgrError err) { addError (new ParseException(ac.getMsg().getString("generator.unrecognize")), err.getMessage()); @@ -683,6 +692,25 @@ ( ( <CDO> | <CDC> | atRuleDeclaration() ) ( <S> )* )* } +void namespaceDeclaration() : +{ Token n=null;} +{ + // FIXME add namespaces in context to match when a definition happens + ( <NAMESPACE_SYM> + ( <S> )* + ( n=<IDENT> ( <S> )* )? ( <STRING> | <URL> ) + ( <S> )* + <SEMICOLON> + ( <S> )* + ) { + if (!ac.getCssVersion().equals("css3")) { + addError(new InvalidParamException("at-rule", "@namespace", ac), + n.toString()); + } + if (n != null) { + } + } +} /** * The import statement * @@ -1365,13 +1393,15 @@ //selector.setUserMedium(getUserMedium()); } { + element_name(selector) ( hash(selector) | _class(selector) - | attrib(selector) | pseudo(selector) )* + | attrib(selector) | pseudo(selector) + | negation(selector) )* { return selector; } | ( hash(selector) | _class(selector) | attrib(selector) - | pseudo(selector) )+ + | pseudo(selector) | negation(selector) )+ { return selector; } @@ -1474,9 +1504,23 @@ * @exception ParseException exception during the parse */ void element_name(CssSelectors s) : -{Token n; } +{Token n=null; + Token p=null; } { - n=<IDENT> { // s.setElement(convertIdent(n.image), ac); + ( LOOKAHEAD(2) (n=<IDENT> | n=<ANY>)? p="|" )? { + // FIXME namespace, check versions of CSS in a better way. + if (!ac.getCssVersion().equals("css3") && (p!=null)) { + StringBuilder sb = new StringBuilder("namespace \""); + if (n != null) sb.append(n.toString()); + sb.append("\""); + ac.getFrame().addError(new CssError(new InvalidParamException("notversion", + "namespace", + ac.getCssVersion(), ac))); + // addError(new ParseException("namespace"), sb.toString()); + skipStatement(); + } + } + ( n=<IDENT> { // s.setElement(convertIdent(n.image), ac); s.addType(new TypeSelector(convertIdent(n.image)));} | <ANY> { if (!ac.getCssVersion().equals("css1")) { @@ -1487,6 +1531,7 @@ "*", ac.getCssVersion(), ac))); } } + ) } /** @@ -1567,22 +1612,45 @@ } } +void negation(CssSelectors s) : +{ + Token n; + CssSelectors ns = new CssSelectors(ac, null); +} +{ // S* negation_arg S* ')' + // type_selector | universal | HASH | class | attrib | pseudo + + <FUNCTIONNOT> ( <S> )* + ( + element_name(ns) | + hash(ns) | + _class(ns) | + attrib(ns) | + pseudo(ns) + ) + ( <S> )* <LPARAN> + { + s.setPseudoFun("not", ns.toString()); + } +} + /** * @exception ParseException exception during the parse */ void pseudo(CssSelectors s) : {Token n; Token language = null; -CssSelectors param = null; +CssExpression param = null; } { - <PSEUDOCLASS_SYM> ( ( n=<IDENT> + <PSEUDOELEMENT_SYM> ( ( n=<IDENT> { try { if (ac.getCssVersion().equals("css3")) { s.addPseudoElement(convertIdent(n.image).toLowerCase()); } else { - throw new InvalidParamException("pseudo-element", "::" + convertIdent(n.image).toLowerCase() , + throw new InvalidParamException("pseudo-element", + "::" + convertIdent(n.image).toLowerCase() , ac.getCssVersion() ,ac); } } catch(InvalidParamException e) { @@ -1603,7 +1671,7 @@ } } ) // FXIXME rewrite to make :lang( use a special case - | ( ( n=<FUNCTIONLANG> ( <S> )* (language=<NUMBER> | language=<IDENT> | language=<STRING> ) ) { + | ( ( n=<FUNCTIONLANG> ( <S> )* (language=<NUMBER> | language=<IDENT> | language=<STRING> ) ( <S> )* ) { try { s.setPseudoFun(convertStringIndex(n.image, 0, n.image.length() -1, false).toLowerCase(), @@ -1613,17 +1681,18 @@ ac.getFrame().addError(new CssError(e)); } } - | ( n=<FUNCTION> ( <S> )* param=simple_selector(null) ) { + | ( n=<FUNCTION> ( <S> )* param=expression() ) { try { s.setPseudoFun(convertStringIndex(n.image, 0, - n.image.length() -1, false).toLowerCase(), + n.image.length() -1, + false).toLowerCase(), param.toString()); } catch(InvalidParamException e) { removeThisRule(); ac.getFrame().addError(new CssError(e)); } } - ) ( <S> )* <LPARAN> + ) <LPARAN> ) } @@ -1811,6 +1880,23 @@ <IMPORTANT_SYM> ( <S> )* { return true; } } +CssExpression expression() : +{ + CssExpression exp = new CssExpression(); + char operator = ' '; + Token n = null; +} +{ + ( ( <PLUS> { operator = '+' ; } + | <MINUS> { operator = '-'; } + | n=<NUMBER> { setValue(new CssNumber(), exp, operator, n, NUMBER); } + // FIXME dimen should be a CssDimension() + | n=<DIMEN> { setValue(new CssIdent(), exp, operator, n, IDENT); } + | n=<STRING> { setValue(new CssString(), exp, operator, n, STRING); } + | n=<IDENT> { setValue(new CssIdent(), exp, operator, n, IDENT); } + ) ( <S> )* )+ + { return exp; } +} /** * @exception ParseException exception during the parse */
Received on Thursday, 12 February 2009 21:26:48 UTC