From 4ef475c91dfa9e9783cc9e671865c58e326db7d1 Mon Sep 17 00:00:00 2001 From: "James X. Nelson" Date: Sat, 4 Mar 2017 20:42:58 -0800 Subject: [PATCH] Allow :host() and :host-context() selectors. Unlike ::slotted(), which only allows simple selectors inside the parens, :host and :host-context allow complex selectors to be placed inside the parens. --- .../common/css/compiler/ast/GssParserCC.jj | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/com/google/common/css/compiler/ast/GssParserCC.jj b/src/com/google/common/css/compiler/ast/GssParserCC.jj index 9f7a0992..7ebc2729 100644 --- a/src/com/google/common/css/compiler/ast/GssParserCC.jj +++ b/src/com/google/common/css/compiler/ast/GssParserCC.jj @@ -707,6 +707,7 @@ PARSER_END(GssParserCC) // Special handling needed because ':not' takes simple selectors as // an argument. | < NOTFUNCTION: "not" > + | < HOSTFUNCTION: "host" ("-context")? > | < SLOTTEDFUNCTION: ":slotted" > | < LANGFUNCTION: "lang" > @@ -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() : { @@ -943,6 +951,17 @@ CssRefinerNode pseudo() : this.mergeLocations(beginLocation, endLocation), tokens); } ) | + ( // :host( complex > selector ) or :host-context( complex > selector ) + t = ( )* { beginLocation = this.getLocation(); + pseudo = t.image; tokens.add(t); } + innerSelector = selector() + ( )* + t = { tokens.add(t); + endLocation = this.getLocation(); + return nodeBuilder.buildPseudoClassNode(pseudo, innerSelector, + this.mergeLocations(beginLocation, endLocation), tokens); } + ) + | ( // :lang( ) t = ( )* { beginLocation = this.getLocation(); pseudo = t.image; tokens.add(t); }