From 5634a3f67033e6e7a789a4693735e83d35792d90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 19 Jul 2018 19:12:18 +0200 Subject: [PATCH] style: Make document condition parsing a bit nicer. Bug: 1475511 Reviewed-by: xidorn MozReview-Commit-ID: Gi0FxrEAYcE --- components/style/stylesheets/document_rule.rs | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/components/style/stylesheets/document_rule.rs b/components/style/stylesheets/document_rule.rs index 9fc1bbfe16b..df8f3988337 100644 --- a/components/style/stylesheets/document_rule.rs +++ b/components/style/stylesheets/document_rule.rs @@ -122,33 +122,32 @@ impl DocumentMatchingFunction { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if input - .try(|input| input.expect_function_matching("url-prefix")) - .is_ok() - { - return parse_quoted_or_unquoted_string!(input, DocumentMatchingFunction::UrlPrefix); + if let Ok(url) = input.try(|input| CssUrl::parse(context, input)) { + return Ok(DocumentMatchingFunction::Url(url)) } - if input - .try(|input| input.expect_function_matching("domain")) - .is_ok() - { - return parse_quoted_or_unquoted_string!(input, DocumentMatchingFunction::Domain); - } - - if input - .try(|input| input.expect_function_matching("regexp")) - .is_ok() - { - return input.parse_nested_block(|input| { - Ok(DocumentMatchingFunction::Regexp( - input.expect_string()?.as_ref().to_owned(), + let location = input.current_source_location(); + let function = input.expect_function()?.clone(); + match_ignore_ascii_case! { &function, + "url-prefix" => { + parse_quoted_or_unquoted_string!(input, DocumentMatchingFunction::UrlPrefix) + } + "domain" => { + parse_quoted_or_unquoted_string!(input, DocumentMatchingFunction::Domain) + } + "regexp" => { + input.parse_nested_block(|input| { + Ok(DocumentMatchingFunction::Regexp( + 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")]