mirror of
https://github.com/servo/servo.git
synced 2025-07-16 11:53:39 +01:00
style: Make document condition parsing a bit nicer.
Bug: 1475511 Reviewed-by: xidorn MozReview-Commit-ID: Gi0FxrEAYcE
This commit is contained in:
parent
095841db7f
commit
5634a3f670
1 changed files with 22 additions and 23 deletions
|
@ -122,33 +122,32 @@ impl DocumentMatchingFunction {
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<Self, ParseError<'i>> {
|
) -> Result<Self, ParseError<'i>> {
|
||||||
if input
|
if let Ok(url) = input.try(|input| CssUrl::parse(context, input)) {
|
||||||
.try(|input| input.expect_function_matching("url-prefix"))
|
return Ok(DocumentMatchingFunction::Url(url))
|
||||||
.is_ok()
|
|
||||||
{
|
|
||||||
return parse_quoted_or_unquoted_string!(input, DocumentMatchingFunction::UrlPrefix);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if input
|
let location = input.current_source_location();
|
||||||
.try(|input| input.expect_function_matching("domain"))
|
let function = input.expect_function()?.clone();
|
||||||
.is_ok()
|
match_ignore_ascii_case! { &function,
|
||||||
{
|
"url-prefix" => {
|
||||||
return parse_quoted_or_unquoted_string!(input, DocumentMatchingFunction::Domain);
|
parse_quoted_or_unquoted_string!(input, DocumentMatchingFunction::UrlPrefix)
|
||||||
}
|
}
|
||||||
|
"domain" => {
|
||||||
if input
|
parse_quoted_or_unquoted_string!(input, DocumentMatchingFunction::Domain)
|
||||||
.try(|input| input.expect_function_matching("regexp"))
|
}
|
||||||
.is_ok()
|
"regexp" => {
|
||||||
{
|
input.parse_nested_block(|input| {
|
||||||
return input.parse_nested_block(|input| {
|
Ok(DocumentMatchingFunction::Regexp(
|
||||||
Ok(DocumentMatchingFunction::Regexp(
|
input.expect_string()?.as_ref().to_owned(),
|
||||||
input.expect_string()?.as_ref().to_owned(),
|
))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
Err(location.new_custom_error(
|
||||||
|
StyleParseErrorKind::UnexpectedFunction(function.clone())
|
||||||
))
|
))
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let url = CssUrl::parse(context, input)?;
|
|
||||||
Ok(DocumentMatchingFunction::Url(url))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue