diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-06-10 15:07:33 +0200 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-06-11 03:12:02 +0200 |
commit | e3c4d03bdea85bdae163fd6b023e9bb698f3b1c8 (patch) | |
tree | f5f7f59fae8c71dcf306d18233e1c04bd5073ac4 /components/style/macros.rs | |
parent | ddfe8b0468dcd57cc5f98cca5c5ba31134c04719 (diff) | |
download | servo-e3c4d03bdea85bdae163fd6b023e9bb698f3b1c8.tar.gz servo-e3c4d03bdea85bdae163fd6b023e9bb698f3b1c8.zip |
style: Reduce some code duplication and ugliness when parsing identifiers.
Diffstat (limited to 'components/style/macros.rs')
-rw-r--r-- | components/style/macros.rs | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/components/style/macros.rs b/components/style/macros.rs index 8280f93adb3..151cfaa2f60 100644 --- a/components/style/macros.rs +++ b/components/style/macros.rs @@ -4,6 +4,24 @@ //! Various macro helpers. +/// A macro to parse an identifier, or return an `UnexpectedIndent` error +/// otherwise. +/// +/// FIXME(emilio): The fact that `UnexpectedIdent` is a `SelectorParseError` +/// doesn't make a lot of sense to me. +macro_rules! try_match_ident_ignore_ascii_case { + ($ident:expr, $( $match_body:tt )*) => { + let __ident = $ident; + (match_ignore_ascii_case! { &*__ident, + $( $match_body )* + _ => Err(()), + }) + .map_err(|()| { + ::selectors::parser::SelectorParseError::UnexpectedIdent(__ident).into() + }) + } +} + macro_rules! define_numbered_css_keyword_enum { ($name: ident: $( $css: expr => $variant: ident = $value: expr ),+,) => { define_numbered_css_keyword_enum!($name: $( $css => $variant = $value ),+); @@ -21,11 +39,9 @@ macro_rules! define_numbered_css_keyword_enum { fn parse<'i, 't>(_context: &$crate::parser::ParserContext, input: &mut ::cssparser::Parser<'i, 't>) -> Result<$name, ::style_traits::ParseError<'i>> { - let ident = try!(input.expect_ident()); - (match_ignore_ascii_case! { &ident, + try_match_ident_ignore_ascii_case! { input.expect_ident()?, $( $css => Ok($name::$variant), )+ - _ => Err(()) - }).map_err(|()| ::selectors::parser::SelectorParseError::UnexpectedIdent(ident).into()) + } } } |