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 -->
This commit is contained in:
bors-servo 2017-06-09 14:31:48 -07:00 committed by GitHub
commit 061cb5f48e
123 changed files with 2212 additions and 1513 deletions

View file

@ -339,27 +339,32 @@ ${helpers.predefined_type("object-position",
}
/// [ row | column ] || dense
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<SpecifiedValue, ParseError<'i>> {
use self::computed_value::AutoFlow;
let mut value = None;
let mut dense = false;
while !input.is_exhausted() {
match_ignore_ascii_case! { &input.expect_ident()?,
let ident = input.expect_ident()?;
let success = match_ignore_ascii_case! { &ident,
"row" if value.is_none() => {
value = Some(AutoFlow::Row);
continue
true
},
"column" if value.is_none() => {
value = Some(AutoFlow::Column);
continue
true
},
"dense" if !dense => {
dense = true;
continue
true
},
_ => return Err(())
_ => false
};
if !success {
return Err(SelectorParseError::UnexpectedIdent(ident).into());
}
}
@ -369,7 +374,7 @@ ${helpers.predefined_type("object-position",
dense: dense,
})
} else {
Err(())
Err(StyleParseError::UnspecifiedError.into())
}
}
@ -435,7 +440,8 @@ ${helpers.predefined_type("object-position",
Either::Second(None_)
}
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<SpecifiedValue, ParseError<'i>> {
SpecifiedValue::parse(context, input)
}
@ -457,13 +463,15 @@ ${helpers.predefined_type("object-position",
impl ComputedValueAsSpecified for TemplateAreas {}
impl Parse for TemplateAreas {
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Self, ParseError<'i>> {
let mut strings = vec![];
while let Ok(string) = input.try(Parser::expect_string) {
strings.push(string.into_owned().into_boxed_str());
}
TemplateAreas::from_vec(strings)
.map_err(|()| StyleParseError::UnspecifiedError.into())
}
}