mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #19536 - emilio:compound-selector-list, r=mbrubeck
style: Move the code to parse a list of compound selectors. I'll need this for ::slotted(). <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19536) <!-- Reviewable:end -->
This commit is contained in:
commit
c6bf85eca9
2 changed files with 35 additions and 11 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue