diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-06-09 14:31:48 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-09 14:31:48 -0700 |
commit | 061cb5f48e5c93a5decf39e530aea4a566e97341 (patch) | |
tree | 1682083740ce2a850c5204cd046918a8427c57ba /components/style/macros.rs | |
parent | 8fee7f45e0481bf6074788029f8a1eaea24fcca5 (diff) | |
parent | 27ae1ef2e7d78f38e744f2e00e177302f2d6aa82 (diff) | |
download | servo-061cb5f48e5c93a5decf39e530aea4a566e97341.tar.gz servo-061cb5f48e5c93a5decf39e530aea4a566e97341.zip |
Auto merge of #16752 - jdm:css-parse-error, r=SimonSapin
Report more informative CSS errors
This requires https://github.com/servo/rust-cssparser/pull/143 for the final commit. There's no better way to split that work up, unfortunately, and it's extremely easy to bitrot. I would appreciate if we could expedite reviewing this work.
This is the work necessary to enable https://bugzilla.mozilla.org/show_bug.cgi?id=1352669. It makes sense to merge it separately because it's so much effort to keep it up to date with the ongoing Stylo work.
---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [x] There are tests for these changes
<!-- 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/16752)
<!-- Reviewable:end -->
Diffstat (limited to 'components/style/macros.rs')
-rw-r--r-- | components/style/macros.rs | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/components/style/macros.rs b/components/style/macros.rs index 092dc7bb8f2..8280f93adb3 100644 --- a/components/style/macros.rs +++ b/components/style/macros.rs @@ -18,11 +18,14 @@ macro_rules! define_numbered_css_keyword_enum { impl $crate::parser::Parse for $name { #[allow(missing_docs)] - fn parse(_context: &$crate::parser::ParserContext, input: &mut ::cssparser::Parser) -> Result<$name, ()> { - match_ignore_ascii_case! { &try!(input.expect_ident()), + 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, $( $css => Ok($name::$variant), )+ _ => Err(()) - } + }).map_err(|()| ::selectors::parser::SelectorParseError::UnexpectedIdent(ident).into()) } } @@ -49,9 +52,9 @@ macro_rules! add_impls_for_keyword_enum { ($name:ident) => { impl $crate::parser::Parse for $name { #[inline] - fn parse(_context: &$crate::parser::ParserContext, - input: &mut ::cssparser::Parser) - -> Result<Self, ()> { + fn parse<'i, 't>(_context: &$crate::parser::ParserContext, + input: &mut ::cssparser::Parser<'i, 't>) + -> Result<Self, ::style_traits::ParseError<'i>> { $name::parse(input) } } @@ -89,10 +92,10 @@ macro_rules! define_keyword_type { } impl $crate::parser::Parse for $name { - fn parse(_context: &$crate::parser::ParserContext, - input: &mut ::cssparser::Parser) - -> Result<$name, ()> { - input.expect_ident_matching($css).map(|_| $name) + fn parse<'i, 't>(_context: &$crate::parser::ParserContext, + input: &mut ::cssparser::Parser<'i, 't>) + -> Result<$name, ::style_traits::ParseError<'i>> { + input.expect_ident_matching($css).map(|_| $name).map_err(|e| e.into()) } } |