Skip to content

Commit fc1a866

Browse files
committed
use ident() at more places
1 parent 1bb280a commit fc1a866

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

src/main/javacc/CSS3Parser.jj

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ Property mediaExpression() :
787787
<LROUND>
788788
( <S> )*
789789
(
790-
t = <IDENT> ( <S> )* { p = unescape(t.image, false); }
790+
t = identExcludingOnly() ( <S> )* { p = unescape(t.image, false); }
791791
| t = <CUSTOM_PROPERTY_NAME> ( <S> )* { p = unescape(t.image, false); }
792792
)
793793
(
@@ -826,7 +826,7 @@ String medium() :
826826
Token t;
827827
}
828828
{
829-
t = <IDENT> ( <S> )*
829+
t = identExcludingOnly() ( <S> )*
830830
{
831831
return unescape(t.image, false);
832832
}
@@ -915,7 +915,7 @@ String pageSelector() :
915915
(
916916
pseudo = pseudoPage() { pseudos.append(pseudo); }
917917
|
918-
ident = <IDENT> { pseudos.append(unescape(ident.image, false)); }
918+
ident = ident() { pseudos.append(unescape(ident.image, false)); }
919919
)
920920
( pseudo = pseudoPage() { pseudos.append(pseudo); } )*
921921
( <S> )*
@@ -933,7 +933,7 @@ String pseudoPage() :
933933
Token t;
934934
}
935935
{
936-
<COLON> t = <IDENT> { return ":" + normalizeAndValidatePagePseudoClass(t); }
936+
<COLON> t = ident() { return ":" + normalizeAndValidatePagePseudoClass(t); }
937937
}
938938

939939
//
@@ -1373,7 +1373,7 @@ Object pseudo(boolean pseudoElementFound) :
13731373
(<COLON> { doubleColon = true; } )?
13741374

13751375
(
1376-
t = <IDENT>
1376+
t = ident()
13771377
{
13781378
String s = unescape(t.image, false);
13791379
if (pseudoElementFound) { throw toCSSParseException("duplicatePseudo", new String[] { s }, locator); }
@@ -1401,7 +1401,7 @@ Object pseudo(boolean pseudoElementFound) :
14011401
(
14021402
t = <FUNCTION_LANG> { function = unescape(t.image, false); }
14031403
( <S> )*
1404-
t = <IDENT> { String lang = unescape(t.image, false); }
1404+
t = ident() { String lang = unescape(t.image, false); }
14051405
( <S> )*
14061406
<RROUND>
14071407
{
@@ -1414,7 +1414,7 @@ Object pseudo(boolean pseudoElementFound) :
14141414
t = <FUNCTION> { function = unescape(t.image, false); StringBuilder args = new StringBuilder(); }
14151415
( <S> )*
14161416
(
1417-
(t = <PLUS> | t = <MINUS> | t = <DIMENSION> | t = <NUMBER> | t = <STRING> | t = <IDENT>)
1417+
(t = <PLUS> | t = <MINUS> | t = <DIMENSION> | t = <NUMBER> | t = <STRING> | t = ident())
14181418
{ args.append(unescape(t.image, false)); }
14191419
( t = <S>
14201420
{ args.append(unescape(t.image, false)); }
@@ -2370,6 +2370,31 @@ Token identExcludingInherit() :
23702370
}
23712371
}
23722372

2373+
Token identExcludingOnly() :
2374+
{
2375+
Token t;
2376+
}
2377+
{
2378+
t = <IDENT> { return t; }
2379+
|
2380+
(
2381+
t = <INHERIT>
2382+
| t = <NONE>
2383+
| t = <FROM>
2384+
)
2385+
{
2386+
Token ident = new Token(IDENT, unescape(t.image, false));
2387+
ident.beginLine = t.beginLine;
2388+
ident.beginColumn = t.endColumn;
2389+
ident.endLine = t.beginLine;
2390+
ident.endColumn = t.endColumn;
2391+
ident.next = t.next;
2392+
ident.specialToken = t.specialToken;
2393+
return ident;
2394+
2395+
}
2396+
}
2397+
23732398

23742399
//
23752400
// number()

src/test/java/org/htmlunit/cssparser/parser/CSS3ParserTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4140,7 +4140,8 @@ public void pseudoElementsErrors() throws Exception {
41404140
"Duplicate pseudo class \":foo(ab)\" or pseudo class \":foo(ab)\" not at end.");
41414141
checkErrorSelector("input:before:",
41424142
"Error in pseudo class or element. (Invalid token \"<EOF>\". "
4143-
+ "Was expecting one of: <IDENT>, \":\", <FUNCTION_NOT>, <FUNCTION_LANG>, <FUNCTION>.)");
4143+
+ "Was expecting one of: \"only\", \"inherit\", \"none\", \"from\", <IDENT>, "
4144+
+ "\":\", <FUNCTION_NOT>, <FUNCTION_LANG>, <FUNCTION>.)");
41444145

41454146
// pseudo element not at end
41464147
checkErrorSelector("input:before:not(#test)",

0 commit comments

Comments
 (0)