style: Move the code to parse a list of compound selectors.

I'll need this for ::slotted().
This commit is contained in:
Emilio Cobos Álvarez 2017-12-09 16:45:06 +01:00
parent 051a715721
commit b1f25a2b1f
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 35 additions and 11 deletions

View file

@ -55,6 +55,7 @@ pub enum SelectorParseErrorKind<'i> {
EmptySelector,
DanglingCombinator,
NonSimpleSelectorInNegation,
NonCompoundSelector,
UnexpectedTokenInAttributeSelector(Token<'i>),
PseudoElementExpectedColon(Token<'i>),
PseudoElementExpectedIdent(Token<'i>),
@ -209,6 +210,33 @@ impl<Impl: SelectorImpl> SelectorList<Impl> {
}
}
/// Parse a comma separated list of compound selectors.
pub fn parse_compound_selector_list<'i, 't, P, Impl>(
parser: &P,
input: &mut CssParser<'i, 't>,
) -> Result<Box<[Selector<Impl>]>, ParseError<'i, P::Error>>
where
P: Parser<'i, Impl=Impl>,
Impl: SelectorImpl,
{
let location = input.current_source_location();
let selectors = input.parse_comma_separated(|input| {
Selector::parse(parser, input)
})?;
// Ensure they're actually all compound selectors.
if selectors
.iter()
.flat_map(|x| x.iter_raw_match_order())
.any(|s| s.is_combinator()) {
return Err(location.new_custom_error(
SelectorParseErrorKind::NonCompoundSelector
))
}
Ok(selectors.into_boxed_slice())
}
/// Ancestor hashes for the bloom filter. We precompute these and store them
/// inline with selectors to optimize cache performance during matching.
/// This matters a lot.