- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Thu, 08 Sep 2005 12:23:35 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/parser/analyzer
In directory hutz:/tmp/cvs-serv8236/org/w3c/css/parser/analyzer
Modified Files:
Couple.java CssParser.java CssParser.jj
CssParserTokenManager.java TokenMgrError.java
Log Message:
Changes from Jean-Guilhem Rouel
Bug fixed: 1174 845 160 766
See
http://www.w3.org/Bugs/Public/show_bug.cgi?id=1174
http://www.w3.org/Bugs/Public/show_bug.cgi?id=845
http://www.w3.org/Bugs/Public/show_bug.cgi?id=160
http://www.w3.org/Bugs/Public/show_bug.cgi?id=766
The handling of selectors has been redone almost entirely.
Also, changelog in files has been removed.
Index: CssParserTokenManager.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/analyzer/CssParserTokenManager.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- CssParserTokenManager.java 8 Aug 2005 13:18:11 -0000 1.9
+++ CssParserTokenManager.java 8 Sep 2005 12:23:33 -0000 1.10
@@ -5,55 +5,22 @@
{
public java.io.PrintStream debugStream = System.out;
public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; }
-private final int jjStopAtPos(int pos, int kind)
-{
- jjmatchedKind = kind;
- jjmatchedPos = pos;
- return pos + 1;
-}
-private final int jjMoveStringLiteralDfa0_1()
-{
[...4371 lines suppressed...]
@@ -3756,8 +3848,8 @@
0x14L, 0x0L,
};
protected SimpleCharStream input_stream;
-private final int[] jjrounds = new int[380];
-private final int[] jjstateSet = new int[760];
+private final int[] jjrounds = new int[388];
+private final int[] jjstateSet = new int[776];
StringBuffer image;
int jjimageLen;
int lengthOfMatch;
@@ -3784,7 +3876,7 @@
{
int i;
jjround = 0x80000001;
- for (i = 380; i-- > 0;)
+ for (i = 388; i-- > 0;)
jjrounds[i] = 0x80000000;
}
public void ReInit(SimpleCharStream stream, int lexState)
Index: CssParser.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/analyzer/CssParser.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- CssParser.java 23 Aug 2005 16:22:54 -0000 1.16
+++ CssParser.java 8 Sep 2005 12:23:33 -0000 1.17
@@ -2,39 +2,59 @@
package org.w3c.css.parser.analyzer;
import java.io.InputStream;
-import java.net.URL;
-import java.util.Enumeration;
import java.util.Vector;
+import java.util.Enumeration;
+import java.net.URL;
+import org.w3c.css.values.CssValue;
+import org.w3c.css.values.CssExpression;
+import org.w3c.css.values.CssString;
+import org.w3c.css.values.CssURL;
+import org.w3c.css.values.CssLength;
+import org.w3c.css.values.CssNumber;
+import org.w3c.css.values.CssColor;
+import org.w3c.css.values.CssIdent;
+import org.w3c.css.values.CssPercentage;
+import org.w3c.css.values.CssFrequency;
+import org.w3c.css.values.CssTime;
+import org.w3c.css.values.CssDate;
+import org.w3c.css.values.CssAngle;
+import org.w3c.css.values.CssFunction;
+import org.w3c.css.values.CssUnicodeRange;
+import org.w3c.css.values.CssResolution;
+import org.w3c.css.properties.css1.CssProperty;
+import org.w3c.css.parser.Frame;
+import org.w3c.css.util.ApplContext;
+import org.w3c.css.parser.CssError;
+import org.w3c.css.parser.CssSelectors;
+import org.w3c.css.parser.CssParseException;
import org.w3c.css.parser.AtRule;
-import org.w3c.css.parser.AtRuleFontFace;
import org.w3c.css.parser.AtRuleMedia;
+import org.w3c.css.parser.AtRuleFontFace;
import org.w3c.css.parser.AtRulePage;
-import org.w3c.css.parser.AtRulePhoneticAlphabet;
import org.w3c.css.parser.AtRulePreference;
-import org.w3c.css.parser.CssError;
-import org.w3c.css.parser.CssParseException;
-import org.w3c.css.parser.CssSelectors;
-import org.w3c.css.properties.css1.CssProperty;
+import org.w3c.css.parser.AtRulePhoneticAlphabet;
import org.w3c.css.properties.svg.AtRuleColorProfile;
-import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.util.Util;
-import org.w3c.css.values.CssAngle;
-import org.w3c.css.values.CssDate;
-import org.w3c.css.values.CssExpression;
-import org.w3c.css.values.CssFrequency;
-import org.w3c.css.values.CssFunction;
-import org.w3c.css.values.CssIdent;
-import org.w3c.css.values.CssLength;
-import org.w3c.css.values.CssNumber;
-import org.w3c.css.values.CssPercentage;
-import org.w3c.css.values.CssResolution;
-import org.w3c.css.values.CssString;
-import org.w3c.css.values.CssTime;
-import org.w3c.css.values.CssURL;
-import org.w3c.css.values.CssUnicodeRange;
-import org.w3c.css.values.CssValue;
+import org.w3c.css.util.Messages;
+import org.w3c.css.css.StyleSheetCom;
+
+import org.w3c.css.selectors.AdjacentSelector;
+import org.w3c.css.selectors.AttributeSelector;
+import org.w3c.css.selectors.ChildSelector;
+import org.w3c.css.selectors.ClassSelector;
+import org.w3c.css.selectors.DescendantSelector;
+import org.w3c.css.selectors.IdSelector;
+import org.w3c.css.selectors.TypeSelector;
+import org.w3c.css.selectors.UniversalSelector;
+import org.w3c.css.selectors.attributes.AttributeAny;
+import org.w3c.css.selectors.attributes.AttributeBegin;
+import org.w3c.css.selectors.attributes.AttributeExact;
+import org.w3c.css.selectors.attributes.AttributeOneOf;
+import org.w3c.css.selectors.attributes.AttributeStart;
+import org.w3c.css.selectors.attributes.AttributeSubstr;
+import org.w3c.css.selectors.attributes.AttributeSuffix;
/**
* A CSS3 parser
@@ -247,7 +267,8 @@
if (ac.getCssVersion().equals("css1") && (n.image).equals("inherit")) {
incompatible_error = true;
- }
+ }
+
if (n.kind == CssParserConstants.IDENT) {
v.set( convertIdent(operator+n.image).trim(), ac);
} else if (n.kind == CssParserConstants.STRING) {
@@ -1374,11 +1395,11 @@
* @exception ParseException exception during the parse
*/
final public void atRuleDeclaration() throws ParseException {
- Token n;
- n = jj_consume_token(ATKEYWORD);
+ Token n;
+ n = jj_consume_token(ATKEYWORD);
//ac.getFrame().addWarning("at-rule", token.toString());
ac.getFrame().addError(
- new CssError(new InvalidParamException("at-rule", token, ac)));
+ new CssError(new InvalidParamException("at-rule", token, ac)));
skipStatement();
}
@@ -1769,7 +1790,18 @@
{if (true) throw new InvalidParamException("nocomb", "~", ac);}
}
}
- current.setConnector(comb);
+ switch(comb) {
+ case '+':
+ current.addAdjacent(new AdjacentSelector());
+ break;
+ case '>':
+ current.addChild(new ChildSelector());
+ break;
+ default:
+ current.addDescendant(new DescendantSelector());
+ }
+ //current.setConnector(comb);
+
current = simple_selector(current);
}
label_62:
@@ -2161,8 +2193,9 @@
/* "." n=<IDENT> { */
n = jj_consume_token(CLASS);
try {
- s.addAttribute("class", convertIdent(n.image.substring(1)),
- CssSelectors.ATTRIBUTE_CLASS_SEL);
+ s.addClass(new ClassSelector(convertIdent(n.image.substring(1))));
+// s.addAttribute("class", convertIdent(n.image.substring(1)),
+// CssSelectors.ATTRIBUTE_CLASS_SEL);
} catch (InvalidParamException e) {
removeThisRule();
ac.getFrame().addError(new CssError(e));
@@ -2178,34 +2211,56 @@
case DIMEN:
n = deprecated_class();
if (n.image.charAt(0) == '.') {
- n.image = n.image.substring(1);
+n.image = n.image.substring(1);
+
+ // the class with the first digit escaped
String cl = "\\" + Integer.toString(n.image.charAt(0), 16);
- int len = n.image.length();
- if (len != 1) {
- int i = 1;
- do {
- char c = n.image.charAt(i);
- if (((c <= 9) && (c >= -1))
- || ((c <= 'f') && (c >= 'a'))
- || ((c <= 'F') && (c >= 'A'))) {
- cl += "\\" + Integer.toString(c, 16);
- } else {
- break;
+ cl += n.image.substring(1);
+
+ String profile = ac.getProfile();
+ if(profile == null || profile.equals("")) {
+ profile = ac.getCssVersion();
+ }
+
+ if(!profile.equals("css1")) {
+ addError(new ParseException(ac.getMsg().getString(
+ "parser.old_class")),
+ "To make \"." + n.image + "\" a valid class, CSS2" +
+ " requires the first digit to be escaped " +
+ "(\"." + cl + "\")");
+ s.addClass(new ClassSelector(n.image));
+ removeThisRule();
+ }
+ else {
+ CssLength length = new CssLength();
+ boolean isLength = false;
+ try {
+ length.set(n.image, ac);
+ isLength = true;
+ }
+ catch(Exception e) {
+ System.out.println("CssParser._class(): " + e.getClass());
+ isLength = false;
+ }
+ if(isLength) {
+ addError(new ParseException(ac.getMsg().getString(
+ "parser.class_dim")), n.image);
+ s.addClass(new ClassSelector(n.image));
+ removeThisRule();
+ }
+ else {
+ try {
+ // for css > 1, we add the rule to have a context,
+ // and we then remove it
+ s.addClass(new ClassSelector(n.image));
+
+ ac.getFrame().addWarning("old_class");
+ } catch (InvalidParamException e) {
+ ac.getFrame().addError(new CssError(e));
+ removeThisRule();
}
- } while (++i < len);
- if (i < len) {
- cl += n.image.substring(i);
}
}
- addError(new ParseException(ac.getMsg().getString("parser.old_class")),
- "To make \"." + n.image + "\" a valid class, CSS2 requires"
- + " the first digit to be escaped (\"." + cl + "\")");
- try {
- s.addAttribute("class", cl, CssSelectors.ATTRIBUTE_ONE_OF);
- } catch (InvalidParamException e) {
- removeThisRule();
- ac.getFrame().addError(new CssError(e));
- }
} else {
{if (true) throw new ParseException("Unrecognized ");}
}
@@ -2268,12 +2323,14 @@
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case IDENT:
n = jj_consume_token(IDENT);
- s.setElement(convertIdent(n.image), ac);
+ // s.setElement(convertIdent(n.image), ac);
+ s.addType(new TypeSelector(convertIdent(n.image)));
break;
case ANY:
jj_consume_token(ANY);
if (!ac.getCssVersion().equals("css1")) {
- s.setElement(null);
+// s.setElement(null);
+ s.addUniversal(new UniversalSelector());
} else {
ac.getFrame().addError(new CssError(new InvalidParamException("notversion",
"*", ac.getCssVersion(), ac)));
@@ -2402,15 +2459,48 @@
jj_consume_token(RBRACKET);
if (selectorType == CssSelectors.ATTRIBUTE_ANY) {
try {
- s.addAttribute(att.image.toLowerCase(), null, selectorType);
+ s.addAttribute(new AttributeAny(att.image.toLowerCase()));
+// s.addAttribute(att.image.toLowerCase(), null, selectorType);
} catch (InvalidParamException e) {
removeThisRule();
ac.getFrame().addError(new CssError(e));
}
} else {
+ AttributeSelector attribute;
+ switch(selectorType) {
+ case CssSelectors.ATTRIBUTE_BEGIN:
+ attribute = new AttributeBegin(att.image.toLowerCase(),
+ val.image);
+ break;
+ case CssSelectors.ATTRIBUTE_EXACT:
+ attribute = new AttributeExact(att.image.toLowerCase(),
+ val.image);
+ break;
+ case CssSelectors.ATTRIBUTE_ONE_OF:
+ attribute = new AttributeOneOf(att.image.toLowerCase(),
+ val.image);
+ break;
+ case CssSelectors.ATTRIBUTE_START:
+ attribute = new AttributeStart(att.image.toLowerCase(),
+ val.image);
+ break;
+ case CssSelectors.ATTRIBUTE_SUBSTR:
+ attribute = new AttributeSubstr(att.image.toLowerCase(),
+ val.image);
+ break;
+ case CssSelectors.ATTRIBUTE_SUFFIX:
+ attribute = new AttributeSuffix(att.image.toLowerCase(),
+ val.image);
+ break;
+ default:
+ attribute = new AttributeExact(att.image.toLowerCase(),
+ val.image);
+ break;
+ }
try {
- s.addAttribute(att.image.toLowerCase(), val.image,
- selectorType);
+ s.addAttribute(attribute);
+// s.addAttribute(att.image.toLowerCase(), val.image,
+// selectorType);
} catch (InvalidParamException e) {
removeThisRule();
ac.getFrame().addError(new CssError(e));
@@ -2547,12 +2637,64 @@
final public void hash(CssSelectors s) throws ParseException {
Token n;
n = jj_consume_token(HASH);
- try {
- s.addAttribute("id", n.image.substring(1),
- CssSelectors.ATTRIBUTE_EXACT);
- } catch (InvalidParamException e) {
- removeThisRule();
- ac.getFrame().addError(new CssError(e));
+ n.image = n.image.substring(1);
+ if(Character.isDigit(n.image.charAt(0))) {
+ String profile = ac.getProfile();
+ if(profile == null || profile.equals("")) {
+ profile = ac.getCssVersion();
+ }
+
+ if(!profile.equals("css1")) {
+ // the id with the first digit escaped
+ String cl = "\\" + Integer.toString(n.image.charAt(0), 16);
+ cl += n.image.substring(1);
+
+ addError(new ParseException(ac.getMsg().getString(
+ "parser.old_id")),
+ "To make \"." + n.image + "\" a valid id, CSS2" +
+ " requires the first digit to be escaped " +
+ "(\"#" + cl + "\")");
+ // for css > 1, we add the rule to have a context,
+ // and we then remove it
+ s.addId(new IdSelector(n.image));
+ removeThisRule();
+ }
+ else {
+ CssLength length = new CssLength();
+ boolean isLength = false;
+ try {
+ length.set(n.image, ac);
+ isLength = true;
+ }
+ catch(Exception e) {
+ System.out.println("CssParser._id(): " + e.getClass());
+ isLength = false;
+ }
+ if(isLength) {
+ addError(new ParseException(ac.getMsg().getString(
+ "parser.id_dim")), n.image);
+ // we add the rule to have a context, and then we remove it
+ s.addId(new IdSelector(n.image));
+ removeThisRule();
+ }
+ else {
+ try {
+ s.addId(new IdSelector(n.image));
+ ac.getFrame().addWarning("old_id");
+ } catch (InvalidParamException e) {
+ ac.getFrame().addError(new CssError(e));
+ removeThisRule();
+ }
+ }
+ }
+ }
+ else {
+ try {
+ s.addId(new IdSelector(n.image));
+ } catch (InvalidParamException e) {
+ ac.getFrame().addError(new CssError(e));
+ removeThisRule();
+ }
}
}
@@ -2649,7 +2791,7 @@
}
jj_consume_token(S);
}
- values = expr();
+ values = expr();
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case IMPORTANT_SYM:
important = prio();
@@ -2671,7 +2813,7 @@
values, important);
// Did the property recognize all values in the expression ?
- if (!values.end() && ac.getMedium() == null) {
+ if (!values.end() && ac.getMedium() == null) {
addError(new InvalidParamException("unrecognize", "", ac),
values);
} else {
@@ -2727,7 +2869,7 @@
*/
final public CssExpression expr() throws ParseException {
CssExpression values = new CssExpression();
- term(values);
+ term(values);
label_79:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
@@ -2766,9 +2908,9 @@
default:
jj_la1[112] = jj_gen;
;
- }
+ }
term(values);
- }
+ }
{if (true) return values;}
throw new Error("Missing return statement in function");
}
@@ -2924,8 +3066,8 @@
jj_la1[116] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
- }
- label_81:
+ }
+ label_81:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case S:
@@ -2942,7 +3084,7 @@
jj_la1[118] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
- }
+ }
}
/**
@@ -3159,18 +3301,8 @@
finally { jj_save(0, xla); }
}
- final private boolean jj_3R_103() {
- if (jj_scan_token(IDENT)) return true;
- return false;
- }
-
- final private boolean jj_3R_95() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_103()) {
- jj_scanpos = xsp;
- if (jj_3R_104()) return true;
- }
+ final private boolean jj_3R_96() {
+ if (jj_scan_token(HASH)) return true;
return false;
}
@@ -3184,26 +3316,11 @@
return false;
}
- final private boolean jj_3R_117() {
- if (jj_scan_token(DIMEN)) return true;
- return false;
- }
-
final private boolean jj_3R_100() {
if (jj_scan_token(PLUS)) return true;
return false;
}
- final private boolean jj_3R_116() {
- if (jj_scan_token(RESOLUTION)) return true;
- return false;
- }
-
- final private boolean jj_3R_115() {
- if (jj_scan_token(FREQ)) return true;
- return false;
- }
-
final private boolean jj_3R_94() {
Token xsp;
xsp = jj_scanpos;
@@ -3217,59 +3334,6 @@
return false;
}
- final private boolean jj_3R_114() {
- if (jj_scan_token(TIME)) return true;
- return false;
- }
-
- final private boolean jj_3R_113() {
- if (jj_scan_token(ANGLE)) return true;
- return false;
- }
-
- final private boolean jj_3R_112() {
- if (jj_scan_token(EXS)) return true;
- return false;
- }
-
- final private boolean jj_3R_111() {
- if (jj_scan_token(EMS)) return true;
- return false;
- }
-
- final private boolean jj_3R_110() {
- if (jj_scan_token(LENGTH)) return true;
- return false;
- }
-
- final private boolean jj_3R_109() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_110()) {
- jj_scanpos = xsp;
- if (jj_3R_111()) {
- jj_scanpos = xsp;
- if (jj_3R_112()) {
- jj_scanpos = xsp;
- if (jj_3R_113()) {
- jj_scanpos = xsp;
- if (jj_3R_114()) {
- jj_scanpos = xsp;
- if (jj_3R_115()) {
- jj_scanpos = xsp;
- if (jj_3R_116()) {
- jj_scanpos = xsp;
- if (jj_3R_117()) return true;
- }
- }
- }
- }
- }
- }
- }
- return false;
- }
-
final private boolean jj_3R_88() {
if (jj_scan_token(S)) return true;
Token xsp;
@@ -3298,16 +3362,6 @@
return false;
}
- final private boolean jj_3R_85() {
- if (jj_scan_token(PLUS)) return true;
- Token xsp;
- while (true) {
- xsp = jj_scanpos;
- if (jj_scan_token(1)) { jj_scanpos = xsp; break; }
- }
- return false;
- }
-
final private boolean jj_3R_83() {
Token xsp;
xsp = jj_scanpos;
@@ -3324,13 +3378,43 @@
return false;
}
+ final private boolean jj_3R_85() {
+ if (jj_scan_token(PLUS)) return true;
+ Token xsp;
+ while (true) {
+ xsp = jj_scanpos;
+ if (jj_scan_token(1)) { jj_scanpos = xsp; break; }
+ }
+ return false;
+ }
+
+ final private boolean jj_3R_99() {
+ if (jj_scan_token(LBRACKET)) return true;
+ return false;
+ }
+
final private boolean jj_3R_108() {
if (jj_scan_token(COLON)) return true;
return false;
}
- final private boolean jj_3R_107() {
- if (jj_scan_token(84)) return true;
+ final private boolean jj_3R_106() {
+ if (jj_3R_109()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_97() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_105()) {
+ jj_scanpos = xsp;
+ if (jj_3R_106()) return true;
+ }
+ return false;
+ }
+
+ final private boolean jj_3R_105() {
+ if (jj_scan_token(CLASS)) return true;
return false;
}
@@ -3344,38 +3428,63 @@
return false;
}
- final private boolean jj_3R_106() {
- if (jj_3R_109()) return true;
+ final private boolean jj_3R_107() {
+ if (jj_scan_token(84)) return true;
return false;
}
- final private boolean jj_3R_105() {
- if (jj_scan_token(CLASS)) return true;
+ final private boolean jj_3R_104() {
+ if (jj_scan_token(ANY)) return true;
return false;
}
- final private boolean jj_3R_97() {
+ final private boolean jj_3R_95() {
Token xsp;
xsp = jj_scanpos;
- if (jj_3R_105()) {
+ if (jj_3R_103()) {
jj_scanpos = xsp;
- if (jj_3R_106()) return true;
+ if (jj_3R_104()) return true;
}
return false;
}
+ final private boolean jj_3R_103() {
+ if (jj_scan_token(IDENT)) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_117() {
+ if (jj_scan_token(DIMEN)) return true;
+ return false;
+ }
+
final private boolean jj_3R_93() {
if (jj_3R_99()) return true;
return false;
}
- final private boolean jj_3R_99() {
- if (jj_scan_token(LBRACKET)) return true;
+ final private boolean jj_3R_116() {
+ if (jj_scan_token(RESOLUTION)) return true;
return false;
}
- final private boolean jj_3R_96() {
- if (jj_scan_token(HASH)) return true;
+ final private boolean jj_3R_115() {
+ if (jj_scan_token(FREQ)) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_114() {
+ if (jj_scan_token(TIME)) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_113() {
+ if (jj_scan_token(ANGLE)) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_112() {
+ if (jj_scan_token(EXS)) return true;
return false;
}
@@ -3384,29 +3493,51 @@
return false;
}
- final private boolean jj_3_1() {
- if (jj_3R_83()) return true;
- if (jj_3R_84()) return true;
+ final private boolean jj_3R_111() {
+ if (jj_scan_token(EMS)) return true;
return false;
}
- final private boolean jj_3R_91() {
- if (jj_3R_97()) return true;
+ final private boolean jj_3R_109() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_110()) {
+ jj_scanpos = xsp;
+ if (jj_3R_111()) {
+ jj_scanpos = xsp;
+ if (jj_3R_112()) {
+ jj_scanpos = xsp;
+ if (jj_3R_113()) {
+ jj_scanpos = xsp;
+ if (jj_3R_114()) {
+ jj_scanpos = xsp;
+ if (jj_3R_115()) {
+ jj_scanpos = xsp;
+ if (jj_3R_116()) {
+ jj_scanpos = xsp;
+ if (jj_3R_117()) return true;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
return false;
}
- final private boolean jj_3R_90() {
- if (jj_3R_96()) return true;
+ final private boolean jj_3R_110() {
+ if (jj_scan_token(LENGTH)) return true;
return false;
}
- final private boolean jj_3R_104() {
- if (jj_scan_token(ANY)) return true;
+ final private boolean jj_3R_91() {
+ if (jj_3R_97()) return true;
return false;
}
- final private boolean jj_3R_89() {
- if (jj_3R_95()) return true;
+ final private boolean jj_3R_90() {
+ if (jj_3R_96()) return true;
return false;
}
@@ -3429,6 +3560,17 @@
return false;
}
+ final private boolean jj_3R_89() {
+ if (jj_3R_95()) return true;
+ return false;
+ }
+
+ final private boolean jj_3_1() {
+ if (jj_3R_83()) return true;
+ if (jj_3R_84()) return true;
+ return false;
+ }
+
public CssParserTokenManager token_source;
SimpleCharStream jj_input_stream;
public Token token, jj_nt;
Index: TokenMgrError.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/analyzer/TokenMgrError.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- TokenMgrError.java 22 Jul 2005 09:45:18 -0000 1.4
+++ TokenMgrError.java 8 Sep 2005 12:23:33 -0000 1.5
@@ -32,13 +32,13 @@
* one of the above 4 values.
*/
int errorCode;
-
+
private int errorLine;
public int getErrorLine() {
return errorLine;
}
-
+
/**
* Replaces unprintable characters by their espaced (or unicode escaped)
* equivalents in the given string
Index: CssParser.jj
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/analyzer/CssParser.jj,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- CssParser.jj 8 Aug 2005 13:18:11 -0000 1.14
+++ CssParser.jj 8 Sep 2005 12:23:33 -0000 1.15
@@ -40,7 +40,7 @@
import org.w3c.css.values.CssFunction;
import org.w3c.css.values.CssUnicodeRange;
import org.w3c.css.values.CssResolution;
-import org.w3c.css.properties.CssProperty;
+import org.w3c.css.properties.css1.CssProperty;
import org.w3c.css.parser.Frame;
import org.w3c.css.util.ApplContext;
import org.w3c.css.parser.CssError;
@@ -52,12 +52,28 @@
import org.w3c.css.parser.AtRulePage;
import org.w3c.css.parser.AtRulePreference;
import org.w3c.css.parser.AtRulePhoneticAlphabet;
-import org.w3c.css.svgproperties.AtRuleColorProfile;
+import org.w3c.css.properties.svg.AtRuleColorProfile;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.util.Util;
import org.w3c.css.util.Messages;
import org.w3c.css.css.StyleSheetCom;
+import org.w3c.css.selectors.AdjacentSelector;
+import org.w3c.css.selectors.AttributeSelector;
+import org.w3c.css.selectors.ChildSelector;
+import org.w3c.css.selectors.ClassSelector;
+import org.w3c.css.selectors.DescendantSelector;
+import org.w3c.css.selectors.IdSelector;
+import org.w3c.css.selectors.TypeSelector;
+import org.w3c.css.selectors.UniversalSelector;
+import org.w3c.css.selectors.attributes.AttributeAny;
+import org.w3c.css.selectors.attributes.AttributeBegin;
+import org.w3c.css.selectors.attributes.AttributeExact;
+import org.w3c.css.selectors.attributes.AttributeOneOf;
+import org.w3c.css.selectors.attributes.AttributeStart;
+import org.w3c.css.selectors.attributes.AttributeSubstr;
+import org.w3c.css.selectors.attributes.AttributeSuffix;
+
/**
* A CSS3 parser
*
@@ -451,7 +467,7 @@
<DEFAULT>
TOKEN :
{
- < HASH : "#" <NAME> >
+ < HASH : "#" <IDENT> >
}
<DEFAULT>
@@ -1135,7 +1151,17 @@
throw new InvalidParamException("nocomb", "~", ac);
}
}
- current.setConnector(comb);
+ switch(comb) {
+ case '+':
+ current.addAdjacent(new AdjacentSelector());
+ break;
+ case '>':
+ current.addChild(new ChildSelector());
+ break;
+ default:
+ current.addDescendant(new DescendantSelector());
+ }
+ //current.setConnector(comb);
}
current=simple_selector(current)
)* ( <S> )*
@@ -1243,8 +1269,9 @@
/* "." n=<IDENT> { */
n=<CLASS> {
try {
- s.addAttribute("class", convertIdent(n.image.substring(1)),
- CssSelectors.ATTRIBUTE_CLASS_SEL);
+ s.addClass(new ClassSelector(convertIdent(n.image.substring(1))));
+// s.addAttribute("class", convertIdent(n.image.substring(1)),
+// CssSelectors.ATTRIBUTE_CLASS_SEL);
} catch (InvalidParamException e) {
removeThisRule();
ac.getFrame().addError(new CssError(e));
@@ -1253,33 +1280,55 @@
| n=deprecated_class() {
if (n.image.charAt(0) == '.') {
- n.image = n.image.substring(1);
- String cl = "\\" + Integer.toString(n.image.charAt(0), 16);
- int len = n.image.length();
- if (len != 1) {
- int i = 1;
- do {
- char c = n.image.charAt(i);
- if (((c <= 9) && (c >= -1))
- || ((c <= 'f') && (c >= 'a'))
- || ((c <= 'F') && (c >= 'A'))) {
- cl += "\\" + Integer.toString(c, 16);
- } else {
- break;
- }
- } while (++i < len);
- if (i < len) {
- cl += n.image.substring(i);
- }
- }
- addError(new ParseException(ac.getMsg().getString("parser.old_class")),
- "To make \"." + n.image + "\" a valid class, CSS2 requires"
- + " the first digit to be escaped (\"." + cl + "\")");
- try {
- s.addAttribute("class", cl, CssSelectors.ATTRIBUTE_ONE_OF);
- } catch (InvalidParamException e) {
- removeThisRule();
- ac.getFrame().addError(new CssError(e));
+n.image = n.image.substring(1);
+
+ // the class with the first digit escaped
+ String cl = "\\" + Integer.toString(n.image.charAt(0), 16);
+ cl += n.image.substring(1);
+
+ String profile = ac.getProfile();
+ if(profile == null || profile.equals("")) {
+ profile = ac.getCssVersion();
+ }
+
+ if(!profile.equals("css1")) {
+ addError(new ParseException(ac.getMsg().getString(
+ "parser.old_class")),
+ "To make \"." + n.image + "\" a valid class, CSS2" +
+ " requires the first digit to be escaped " +
+ "(\"." + cl + "\")");
+ s.addClass(new ClassSelector(n.image));
+ removeThisRule();
+ }
+ else {
+ CssLength length = new CssLength();
+ boolean isLength = false;
+ try {
+ length.set(n.image, ac);
+ isLength = true;
+ }
+ catch(Exception e) {
+ System.out.println("CssParser._class(): " + e.getClass());
+ isLength = false;
+ }
+ if(isLength) {
+ addError(new ParseException(ac.getMsg().getString(
+ "parser.class_dim")), n.image);
+ s.addClass(new ClassSelector(n.image));
+ removeThisRule();
+ }
+ else {
+ try {
+ // for css > 1, we add the rule to have a context,
+ // and we then remove it
+ s.addClass(new ClassSelector(n.image));
+
+ ac.getFrame().addWarning("old_class");
+ } catch (InvalidParamException e) {
+ ac.getFrame().addError(new CssError(e));
+ removeThisRule();
+ }
+ }
}
} else {
throw new ParseException("Unrecognized ");
@@ -1306,10 +1355,12 @@
void element_name(CssSelectors s) :
{Token n; }
{
- n=<IDENT> { s.setElement(convertIdent(n.image), ac); }
+ n=<IDENT> { // s.setElement(convertIdent(n.image), ac);
+ s.addType(new TypeSelector(convertIdent(n.image)));}
| "*" {
if (!ac.getCssVersion().equals("css1")) {
- s.setElement(null);
+// s.setElement(null);
+ s.addUniversal(new UniversalSelector());
} else {
ac.getFrame().addError(new CssError(new InvalidParamException("notversion",
"*", ac.getCssVersion(), ac)));
@@ -1345,15 +1396,48 @@
{
if (selectorType == CssSelectors.ATTRIBUTE_ANY) {
try {
- s.addAttribute(att.image.toLowerCase(), null, selectorType);
+ s.addAttribute(new AttributeAny(att.image.toLowerCase()));
+// s.addAttribute(att.image.toLowerCase(), null, selectorType);
} catch (InvalidParamException e) {
removeThisRule();
ac.getFrame().addError(new CssError(e));
}
} else {
+ AttributeSelector attribute;
+ switch(selectorType) {
+ case CssSelectors.ATTRIBUTE_BEGIN:
+ attribute = new AttributeBegin(att.image.toLowerCase(),
+ val.image);
+ break;
+ case CssSelectors.ATTRIBUTE_EXACT:
+ attribute = new AttributeExact(att.image.toLowerCase(),
+ val.image);
+ break;
+ case CssSelectors.ATTRIBUTE_ONE_OF:
+ attribute = new AttributeOneOf(att.image.toLowerCase(),
+ val.image);
+ break;
+ case CssSelectors.ATTRIBUTE_START:
+ attribute = new AttributeStart(att.image.toLowerCase(),
+ val.image);
+ break;
+ case CssSelectors.ATTRIBUTE_SUBSTR:
+ attribute = new AttributeSubstr(att.image.toLowerCase(),
+ val.image);
+ break;
+ case CssSelectors.ATTRIBUTE_SUFFIX:
+ attribute = new AttributeSuffix(att.image.toLowerCase(),
+ val.image);
+ break;
+ default:
+ attribute = new AttributeExact(att.image.toLowerCase(),
+ val.image);
+ break;
+ }
try {
- s.addAttribute(att.image.toLowerCase(), val.image,
- selectorType);
+ s.addAttribute(attribute);
+// s.addAttribute(att.image.toLowerCase(), val.image,
+// selectorType);
} catch (InvalidParamException e) {
removeThisRule();
ac.getFrame().addError(new CssError(e));
@@ -1426,12 +1510,64 @@
{Token n; }
{
n=<HASH> {
- try {
- s.addAttribute("id", n.image.substring(1),
- CssSelectors.ATTRIBUTE_EXACT);
- } catch (InvalidParamException e) {
- removeThisRule();
- ac.getFrame().addError(new CssError(e));
+ n.image = n.image.substring(1);
+ if(Character.isDigit(n.image.charAt(0))) {
+ String profile = ac.getProfile();
+ if(profile == null || profile.equals("")) {
+ profile = ac.getCssVersion();
+ }
+
+ if(!profile.equals("css1")) {
+ // the id with the first digit escaped
+ String cl = "\\" + Integer.toString(n.image.charAt(0), 16);
+ cl += n.image.substring(1);
+
+ addError(new ParseException(ac.getMsg().getString(
+ "parser.old_id")),
+ "To make \"." + n.image + "\" a valid id, CSS2" +
+ " requires the first digit to be escaped " +
+ "(\"#" + cl + "\")");
+ // for css > 1, we add the rule to have a context,
+ // and we then remove it
+ s.addId(new IdSelector(n.image));
+ removeThisRule();
+ }
+ else {
+ CssLength length = new CssLength();
+ boolean isLength = false;
+ try {
+ length.set(n.image, ac);
+ isLength = true;
+ }
+ catch(Exception e) {
+ System.out.println("CssParser._id(): " + e.getClass());
+ isLength = false;
+ }
+ if(isLength) {
+ addError(new ParseException(ac.getMsg().getString(
+ "parser.id_dim")), n.image);
+ // we add the rule to have a context, and then we remove it
+ s.addId(new IdSelector(n.image));
+ removeThisRule();
+ }
+ else {
+ try {
+ s.addId(new IdSelector(n.image));
+ ac.getFrame().addWarning("old_id");
+ } catch (InvalidParamException e) {
+ ac.getFrame().addError(new CssError(e));
+ removeThisRule();
+ }
+ }
+ }
+ }
+ else {
+ try {
+ s.addId(new IdSelector(n.image));
+ } catch (InvalidParamException e) {
+ ac.getFrame().addError(new CssError(e));
+ removeThisRule();
+ }
}
}
}
Index: Couple.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/parser/analyzer/Couple.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Couple.java 8 Apr 2002 21:24:03 -0000 1.2
+++ Couple.java 8 Sep 2005 12:23:33 -0000 1.3
@@ -4,12 +4,7 @@
//
// (c) COPYRIGHT MIT and INRIA, 1997.
// Please first read the full copyright statement in file COPYRIGHT.html
-/*
- * $Log$
- * Revision 1.2 2002/04/08 21:24:03 plehegar
- * New
- *
- */
+
package org.w3c.css.parser.analyzer;
import org.w3c.css.values.CssExpression;
Received on Thursday, 8 September 2005 12:24:43 UTC