Skip to content

Commit 8649d88

Browse files
committed
1 parent 93a2e9a commit 8649d88

File tree

3 files changed

+154
-127
lines changed

3 files changed

+154
-127
lines changed

org/w3c/css/parser/CssSelectors.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public final class CssSelectors extends SelectorsList
7171
//private int hashGeneral;
7272

7373
// The CssStyle to use
74-
private static Class style;
74+
private static Class<?> style;
7575

7676
// see isEmpty and addProperty
7777
private boolean Init;
@@ -93,7 +93,7 @@ public CssSelectors(ApplContext ac) {
9393
this.ac = ac;
9494
}
9595

96-
private CssSelectors(Class style) {
96+
private CssSelectors(Class<?> style) {
9797
super();
9898
CssSelectors.style = style;
9999
try {
@@ -130,7 +130,7 @@ public CssSelectors(ApplContext ac, CssSelectors next) {
130130
*
131131
* @param style0 the style
132132
*/
133-
public void setStyle(Class style0) {
133+
public void setStyle(Class<?> style0) {
134134
Util.verbose("Style is : " + style0);
135135
style = style0;
136136
}
@@ -605,7 +605,7 @@ private boolean canMatch(CssSelectors selector) {
605605
Util.verbose("canMatch for attributes :" + result);
606606

607607
if ((hashElement != selector.hashElement) && hashElement != 0) {
608-
if ((connector == DESCENDANT_COMBINATOR) && (selector.next != null)) {
608+
if ((connector.equals(DESCENDANT_COMBINATOR)) && (selector.next != null)) {
609609
// here we are in this case :
610610
// H1 and HTML BODY H1 EM
611611
// H1 can't match EM but EM have next

org/w3c/css/parser/analyzer/CssParser.jj

Lines changed: 146 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,7 +1903,7 @@ String combinator() :
19031903
String connector = " ";
19041904
}
19051905
{
1906-
( ( <PLUS> { connector = "+" ; }
1906+
( ( <PLUS> { connector = "+" ; }
19071907
| <GREATER> { connector = ">" ; }
19081908
| <TILDE> { connector = "~" ; }
19091909
| <TWOPIPES> { connector = "||"; }
@@ -1966,12 +1966,12 @@ ArrayList<CssSelectors> selector_list() :
19661966
ArrayList<CssSelectors> context_set = new ArrayList<CssSelectors>();
19671967
}
19681968
{
1969-
selector=selector() {
1969+
selector=complex_selector(null) {
19701970
if (selector != null) {
19711971
context_set.add(selector);
19721972
}
19731973
}
1974-
( <COMMA> ( <S> )* selector=selector() {
1974+
( <COMMA> ( <S> )* selector=complex_selector(null) {
19751975
if (selector != null) {
19761976
context_set.add(selector);
19771977
}
@@ -2182,101 +2182,12 @@ CssSelectors relative_selector() :
21822182
current.addDescendantCombinator();
21832183
}
21842184
}
2185-
// FIXME should be complex_selector
2186-
current=simple_selector(current)
2185+
current=complex_selector(current)
21872186
{
21882187
return current;
21892188
}
21902189

21912190
}
2192-
/**
2193-
* @exception ParseException exception during the parse
2194-
*/
2195-
CssSelectors selector() :
2196-
{ String comb;
2197-
CssSelectors current; }
2198-
{
2199-
try {
2200-
current=simple_selector(null)
2201-
(
2202-
comb=combinator() {
2203-
if ((ac.getCssProfile() == CssProfile.MOBILE) ||
2204-
getAtRule().toString().equals("@media atsc-tv") ||
2205-
(ac.getCssVersion() == CssVersion.CSS1)) {
2206-
if (comb.equals("+") || comb.equals(">")) {
2207-
throw new InvalidParamException("nocomb", comb, ac);
2208-
}
2209-
} else if (ac.getCssProfile() == CssProfile.TV) {
2210-
if (comb.equals("+")) {
2211-
throw new InvalidParamException("nocomb", comb, ac);
2212-
}
2213-
}
2214-
// if version < CSS3, ~ is undefined
2215-
if (ac.getCssVersion().compareTo(CssVersion.CSS3) < 0) {
2216-
if (comb.equals("~") || comb.equals("||")) {
2217-
throw new InvalidParamException("nocomb", comb, ac);
2218-
}
2219-
}
2220-
switch(comb) {
2221-
case "+":
2222-
current.addNextSiblingCombinator();
2223-
break;
2224-
case ">":
2225-
current.addChildCombinator();
2226-
break;
2227-
case "~":
2228-
current.addSubsequentSiblingCombinator();
2229-
break;
2230-
case "||":
2231-
current.addColumnCombinator();
2232-
break;
2233-
default:
2234-
current.addDescendantCombinator();
2235-
}
2236-
//current.setConnector(comb);
2237-
}
2238-
current=simple_selector(current)
2239-
)*
2240-
{ return current; }
2241-
}
2242-
catch (InvalidParamException ie) {
2243-
// skipStatement();
2244-
// removeThisRule();
2245-
ac.getFrame()
2246-
.addError(new CssError(getSourceFile(), getBeginLine(),
2247-
getBeginColumn(), getEndLine(), getEndColumn(), ie));
2248-
Token t = getToken(1);
2249-
StringBuilder s = new StringBuilder();
2250-
s.append(getToken(0).image);
2251-
// eat until , { or EOF
2252-
while ((t.kind != COMMA) && (t.kind != LBRACE) && (t.kind != EOF)) {
2253-
s.append(t.image);
2254-
getNextToken();
2255-
t = getToken(1);
2256-
}
2257-
return null;
2258-
}
2259-
catch (ParseException e) {
2260-
// validSelector = false;
2261-
Token t = getToken(1);
2262-
StringBuilder s = new StringBuilder("[");
2263-
s.append(getToken(0).image);
2264-
// eat until , { or EOF
2265-
while ((t.kind != COMMA) && (t.kind != LBRACE) && (t.kind != EOF)) {
2266-
s.append(t.image);
2267-
getNextToken();
2268-
t = getToken(1);
2269-
}
2270-
s.append(']');
2271-
// if (validSelector) {
2272-
addError(e, s.toString());
2273-
// } else {
2274-
// addError(e,"");
2275-
// }
2276-
validSelector = true;
2277-
return null;
2278-
}
2279-
}
22802191

22812192
/**
22822193
* I made this rule to parse a selector from a document. Combinator are avoid.
@@ -2315,6 +2226,119 @@ CssSelectors simple_selector(CssSelectors next) :
23152226
}
23162227
}
23172228

2229+
CssSelectors subclass_selector(CssSelectors selector) :
2230+
{
2231+
}
2232+
{
2233+
( id_selector(selector)
2234+
| class_selector(selector)
2235+
| attribute_selector(selector)
2236+
| pseudo_class_selector(selector)
2237+
)
2238+
{
2239+
return selector;
2240+
}
2241+
}
2242+
2243+
CssSelectors complex_selector(CssSelectors sel) :
2244+
{
2245+
String comb;
2246+
CssSelectors current;
2247+
}
2248+
{
2249+
try {
2250+
current=compound_selector(sel)
2251+
( ( comb=combinator() {
2252+
if ((ac.getCssProfile() == CssProfile.MOBILE) ||
2253+
getAtRule().toString().equals("@media atsc-tv") ||
2254+
(ac.getCssVersion() == CssVersion.CSS1)) {
2255+
if (comb.equals("+") || comb.equals(">")) {
2256+
throw new InvalidParamException("nocomb", comb, ac);
2257+
}
2258+
} else if (ac.getCssProfile() == CssProfile.TV) {
2259+
if (comb.equals("+")) {
2260+
throw new InvalidParamException("nocomb", comb, ac);
2261+
}
2262+
}
2263+
// if version < CSS3, ~ is undefined
2264+
if (ac.getCssVersion().compareTo(CssVersion.CSS3) < 0) {
2265+
if (comb.equals("~") || comb.equals("||")) {
2266+
throw new InvalidParamException("nocomb", comb, ac);
2267+
}
2268+
}
2269+
switch(comb) {
2270+
case "+":
2271+
current.addNextSiblingCombinator();
2272+
break;
2273+
case ">":
2274+
current.addChildCombinator();
2275+
break;
2276+
case "~":
2277+
current.addSubsequentSiblingCombinator();
2278+
break;
2279+
case "||":
2280+
current.addColumnCombinator();
2281+
break;
2282+
default:
2283+
current.addDescendantCombinator();
2284+
}
2285+
} )?
2286+
current=compound_selector(current)
2287+
)*
2288+
{
2289+
return current;
2290+
}
2291+
} catch (InvalidParamException ie) {
2292+
// skipStatement();
2293+
// removeThisRule();
2294+
ac.getFrame().addError(new CssError(getSourceFile(), getBeginLine(),
2295+
getBeginColumn(), getEndLine(), getEndColumn(), ie));
2296+
Token t = getToken(1);
2297+
StringBuilder s = new StringBuilder();
2298+
s.append(getToken(0).image);
2299+
// eat until , { or EOF
2300+
while ((t.kind != COMMA) && (t.kind != LBRACE) && (t.kind != EOF)) {
2301+
s.append(t.image);
2302+
getNextToken();
2303+
t = getToken(1);
2304+
}
2305+
return null;
2306+
} catch (ParseException e) {
2307+
// validSelector = false;
2308+
Token t = getToken(1);
2309+
StringBuilder s = new StringBuilder("[");
2310+
s.append(getToken(0).image);
2311+
// eat until , { or EOF
2312+
while ((t.kind != COMMA) && (t.kind != LBRACE) && (t.kind != EOF)) {
2313+
s.append(t.image);
2314+
getNextToken();
2315+
t = getToken(1);
2316+
}
2317+
s.append(']');
2318+
// if (validSelector) {
2319+
addError(e, s.toString());
2320+
// } else {
2321+
// addError(e,"");
2322+
// }
2323+
validSelector = true;
2324+
return null;
2325+
}
2326+
2327+
}
2328+
2329+
CssSelectors compound_selector(CssSelectors next) :
2330+
{
2331+
CssSelectors selector = new CssSelectors(ac, next);
2332+
selector.setAtRule(getAtRule());
2333+
}
2334+
{
2335+
( LOOKAHEAD(3) ( ( ( type_selector(selector) )? ( LOOKAHEAD(2) subclass_selector(selector) )+ ) ( LOOKAHEAD(2) pseudo_element_selector(selector) ( LOOKAHEAD(2) pseudo_class_selector(selector) )* )* )
2336+
| ( type_selector(selector) ( LOOKAHEAD(2) pseudo_element_selector(selector) ( LOOKAHEAD(2) pseudo_class_selector(selector) )* )* )
2337+
| ( ( LOOKAHEAD(2) pseudo_element_selector(selector) ( LOOKAHEAD(2) pseudo_class_selector(selector) )* )+ ) ) {
2338+
return selector;
2339+
}
2340+
}
2341+
23182342
/**
23192343
* @exception ParseException exception during the parse
23202344
*/
@@ -2596,36 +2620,45 @@ void attribute_selector(CssSelectors s) :
25962620
}
25972621
}
25982622

2623+
void pseudo_element_selector(CssSelectors s) :
2624+
{
2625+
Token n;
2626+
}
2627+
{
2628+
<PSEUDOELEMENT_SYM> ( n=ident() ) {
2629+
try {
2630+
// should be >CSS3
2631+
if (ac.getCssVersion().compareTo(CssVersion.CSS3) >= 0) {
2632+
s.addPseudoElement(convertIdent(n.image).toLowerCase());
2633+
} else {
2634+
throw new InvalidParamException("pseudo-element",
2635+
"::" + convertIdent(n.image).toLowerCase(),
2636+
ac.getCssVersionString() ,ac);
2637+
}
2638+
} catch(InvalidParamException e) {
2639+
validSelector = false;
2640+
throw new ParseException(e.getMessage());
2641+
}
2642+
}
2643+
}
2644+
2645+
void pseudo(CssSelectors s) :
2646+
{}
2647+
{
2648+
pseudo_element_selector(s) | pseudo_class_selector(s)
2649+
2650+
}
25992651
/**
26002652
* @exception ParseException exception during the parse
26012653
*/
2602-
void pseudo(CssSelectors s) :
2654+
void pseudo_class_selector(CssSelectors s) :
26032655
{Token n;
26042656
Token language = null;
26052657
CssExpression param = null;
26062658
ArrayList<CssSelectors> selector_list = null;
26072659
String error_str = null;
26082660
}
26092661
{
2610-
<PSEUDOELEMENT_SYM> ( ( n=ident()
2611-
{
2612-
try {
2613-
// should be >CSS3
2614-
if (ac.getCssVersion().compareTo(CssVersion.CSS3) >= 0) {
2615-
s.addPseudoElement(convertIdent(n.image).toLowerCase());
2616-
} else {
2617-
throw new InvalidParamException("pseudo-element",
2618-
"::" + convertIdent(n.image).toLowerCase() ,
2619-
ac.getCssVersionString() ,ac);
2620-
}
2621-
} catch(InvalidParamException e) {
2622-
// removeThisRule();
2623-
// ac.getFrame().addError(new CssError(e));
2624-
validSelector = false;
2625-
throw new ParseException(e.getMessage());
2626-
}
2627-
} ) )
2628-
|
26292662
<COLON> ( ( n=ident()
26302663
{
26312664
try {

org/w3c/css/selectors/SelectorsList.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,10 @@ public int size() {
129129
* @throws InvalidParamException when trying to add a selector after a pseudo-element
130130
*/
131131
public void addSelector(Selector selector) throws InvalidParamException {
132-
if (selectors.size() > 0) {
133-
Selector last = selectors.get(selectors.size() - 1);
134-
if (last instanceof PseudoElementSelector
135-
&& !(selector instanceof PseudoClassSelector
136-
&& ((PseudoClassSelector) selector)
137-
.isUserAction())) {
138-
throw new InvalidParamException("pseudo-element-not-last",
139-
selector, last, ac);
140-
}
141-
}
132+
/* FIXME TODO
133+
the grammar is checking the basic structure but specific rules
134+
should appear here
135+
*/
142136
selectors.add(selector);
143137
stringrep = null;
144138
}

0 commit comments

Comments
 (0)