Skip to content
This repository has been archived by the owner on Feb 23, 2022. It is now read-only.

Commit

Permalink
Allow :host() and :host-context() selectors.
Browse files Browse the repository at this point in the history
Unlike ::slotted(), which only allows simple selectors
inside the parens, :host and :host-context allow
complex selectors to be placed inside the parens.
  • Loading branch information
JamesXNelson committed Nov 20, 2017
1 parent 94e2d57 commit 4ef475c
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/com/google/common/css/compiler/ast/GssParserCC.jj
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ PARSER_END(GssParserCC)
// Special handling needed because ':not' takes simple selectors as
// an argument.
| < NOTFUNCTION: "not" <LEFTROUND> >
| < HOSTFUNCTION: "host" ("-context")? <LEFTROUND> >
| < SLOTTEDFUNCTION: ":slotted" <LEFTROUND> >
| < LANGFUNCTION: "lang" <LEFTROUND> >

Expand Down Expand Up @@ -896,8 +897,15 @@ CssRefinerNode id() :
}

// pseudo
// : ':' [ IDENT | [ ':' IDENT ] | [ 'not(' S* simple_selector S* ')' ]
// | [ 'lang(' S* IDENT S* ')' ] | [ FUNCTION S* nth S* ')' ] ]?
// : ':' [ IDENT
// | [ ':' IDENT ]
// | [ 'not(' S* simple_selector S* ')' ]
// | [ 'lang(' S* IDENT S* ')' ]
// | [ FUNCTION S* nth S* ')' ]
// | [ ':slotted(' S* simple_selector S* ')' ]
// | [ ':host(' S* selector S* ')' ]
// | [ ':host-context(' S* selector S* ')' ]
// ]?
// ;
CssRefinerNode pseudo() :
{
Expand Down Expand Up @@ -943,6 +951,17 @@ CssRefinerNode pseudo() :
this.mergeLocations(beginLocation, endLocation), tokens); }
)
|
( // :host( complex > selector ) or :host-context( complex > selector )
t = <HOSTFUNCTION> ( <S> )* { beginLocation = this.getLocation();
pseudo = t.image; tokens.add(t); }
innerSelector = selector()
( <S> )*
t = <RIGHTROUND> { tokens.add(t);
endLocation = this.getLocation();
return nodeBuilder.buildPseudoClassNode(pseudo, innerSelector,
this.mergeLocations(beginLocation, endLocation), tokens); }
)
|
( // :lang( <IDENTIFIER> )
t = <LANGFUNCTION> ( <S> )* { beginLocation = this.getLocation();
pseudo = t.image; tokens.add(t); }
Expand Down

0 comments on commit 4ef475c

Please sign in to comment.