Untry style

This commit is contained in:
Simon Sapin 2017-06-18 12:40:03 +02:00
parent 4c5f7bfaa3
commit a5bb55790f
45 changed files with 518 additions and 527 deletions

View file

@ -512,8 +512,8 @@ pub fn parse_legacy_color(mut input: &str) -> Result<RGBA, ()> {
0 => Err(()), 0 => Err(()),
1 => hex(string[0] as char), 1 => hex(string[0] as char),
_ => { _ => {
let upper = try!(hex(string[0] as char)); let upper = hex(string[0] as char)?;
let lower = try!(hex(string[1] as char)); let lower = hex(string[1] as char)?;
Ok((upper << 4) | lower) Ok((upper << 4) | lower)
} }
} }

View file

@ -220,22 +220,22 @@ impl<'a> Add for &'a TraversalStatistics {
impl fmt::Display for TraversalStatistics { impl fmt::Display for TraversalStatistics {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
debug_assert!(self.traversal_time_ms != 0.0, "should have set traversal time"); debug_assert!(self.traversal_time_ms != 0.0, "should have set traversal time");
try!(writeln!(f, "[PERF] perf block start")); writeln!(f, "[PERF] perf block start")?;
try!(writeln!(f, "[PERF],traversal,{}", if self.is_parallel.unwrap() { writeln!(f, "[PERF],traversal,{}", if self.is_parallel.unwrap() {
"parallel" "parallel"
} else { } else {
"sequential" "sequential"
})); })?;
try!(writeln!(f, "[PERF],elements_traversed,{}", self.elements_traversed)); writeln!(f, "[PERF],elements_traversed,{}", self.elements_traversed)?;
try!(writeln!(f, "[PERF],elements_styled,{}", self.elements_styled)); writeln!(f, "[PERF],elements_styled,{}", self.elements_styled)?;
try!(writeln!(f, "[PERF],elements_matched,{}", self.elements_matched)); writeln!(f, "[PERF],elements_matched,{}", self.elements_matched)?;
try!(writeln!(f, "[PERF],styles_shared,{}", self.styles_shared)); writeln!(f, "[PERF],styles_shared,{}", self.styles_shared)?;
try!(writeln!(f, "[PERF],selectors,{}", self.selectors)); writeln!(f, "[PERF],selectors,{}", self.selectors)?;
try!(writeln!(f, "[PERF],revalidation_selectors,{}", self.revalidation_selectors)); writeln!(f, "[PERF],revalidation_selectors,{}", self.revalidation_selectors)?;
try!(writeln!(f, "[PERF],dependency_selectors,{}", self.dependency_selectors)); writeln!(f, "[PERF],dependency_selectors,{}", self.dependency_selectors)?;
try!(writeln!(f, "[PERF],declarations,{}", self.declarations)); writeln!(f, "[PERF],declarations,{}", self.declarations)?;
try!(writeln!(f, "[PERF],stylist_rebuilds,{}", self.stylist_rebuilds)); writeln!(f, "[PERF],stylist_rebuilds,{}", self.stylist_rebuilds)?;
try!(writeln!(f, "[PERF],traversal_time_ms,{}", self.traversal_time_ms)); writeln!(f, "[PERF],traversal_time_ms,{}", self.traversal_time_ms)?;
writeln!(f, "[PERF] perf block end") writeln!(f, "[PERF] perf block end")
} }
} }

View file

@ -135,7 +135,7 @@ impl SpecifiedValue {
pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Box<Self>, ParseError<'i>> { -> Result<Box<Self>, ParseError<'i>> {
let mut references = Some(HashSet::new()); let mut references = Some(HashSet::new());
let (first, css, last) = try!(parse_self_contained_declaration_value(input, &mut references)); let (first, css, last) = parse_self_contained_declaration_value(input, &mut references)?;
Ok(Box::new(SpecifiedValue { Ok(Box::new(SpecifiedValue {
css: css.into_owned(), css: css.into_owned(),
first_token_type: first, first_token_type: first,
@ -149,7 +149,7 @@ impl SpecifiedValue {
pub fn parse_non_custom_with_var<'i, 't> pub fn parse_non_custom_with_var<'i, 't>
(input: &mut Parser<'i, 't>) (input: &mut Parser<'i, 't>)
-> Result<(TokenSerializationType, Cow<'i, str>), ParseError<'i>> { -> Result<(TokenSerializationType, Cow<'i, str>), ParseError<'i>> {
let (first_token_type, css, _) = try!(parse_self_contained_declaration_value(input, &mut None)); let (first_token_type, css, _) = parse_self_contained_declaration_value(input, &mut None)?;
Ok((first_token_type, css)) Ok((first_token_type, css))
} }
@ -163,8 +163,7 @@ fn parse_self_contained_declaration_value<'i, 't>
), ParseError<'i>> { ), ParseError<'i>> {
let start_position = input.position(); let start_position = input.position();
let mut missing_closing_characters = String::new(); let mut missing_closing_characters = String::new();
let (first, last) = try!( let (first, last) = parse_declaration_value(input, references, &mut missing_closing_characters)?;
parse_declaration_value(input, references, &mut missing_closing_characters));
let mut css: Cow<str> = input.slice_from(start_position).into(); let mut css: Cow<str> = input.slice_from(start_position).into();
if !missing_closing_characters.is_empty() { if !missing_closing_characters.is_empty() {
// Unescaped backslash at EOF in a quoted string is ignored. // Unescaped backslash at EOF in a quoted string is ignored.
@ -185,7 +184,7 @@ fn parse_declaration_value<'i, 't>
input.parse_until_before(Delimiter::Bang | Delimiter::Semicolon, |input| { input.parse_until_before(Delimiter::Bang | Delimiter::Semicolon, |input| {
// Need at least one token // Need at least one token
let start_position = input.position(); let start_position = input.position();
try!(input.next_including_whitespace()); input.next_including_whitespace()?;
input.reset(start_position); input.reset(start_position);
parse_declaration_value_block(input, references, missing_closing_characters) parse_declaration_value_block(input, references, missing_closing_characters)
@ -209,9 +208,9 @@ fn parse_declaration_value_block<'i, 't>
loop { loop {
macro_rules! nested { macro_rules! nested {
() => { () => {
try!(input.parse_nested_block(|input| { input.parse_nested_block(|input| {
parse_declaration_value_block(input, references, missing_closing_characters) parse_declaration_value_block(input, references, missing_closing_characters)
})) })?
} }
} }
macro_rules! check_closed { macro_rules! check_closed {
@ -243,9 +242,9 @@ fn parse_declaration_value_block<'i, 't>
Token::Function(ref name) => { Token::Function(ref name) => {
if name.eq_ignore_ascii_case("var") { if name.eq_ignore_ascii_case("var") {
let position = input.position(); let position = input.position();
try!(input.parse_nested_block(|input| { input.parse_nested_block(|input| {
parse_var_function(input, references) parse_var_function(input, references)
})); })?;
input.reset(position); input.reset(position);
} }
nested!(); nested!();
@ -311,21 +310,21 @@ fn parse_declaration_value_block<'i, 't>
fn parse_var_function<'i, 't>(input: &mut Parser<'i, 't>, fn parse_var_function<'i, 't>(input: &mut Parser<'i, 't>,
references: &mut Option<HashSet<Name>>) references: &mut Option<HashSet<Name>>)
-> Result<(), ParseError<'i>> { -> Result<(), ParseError<'i>> {
let name = try!(input.expect_ident()); let name = input.expect_ident()?;
let name: Result<_, ParseError> = let name: Result<_, ParseError> =
parse_name(&name) parse_name(&name)
.map_err(|()| SelectorParseError::UnexpectedIdent(name.clone()).into()); .map_err(|()| SelectorParseError::UnexpectedIdent(name.clone()).into());
let name = try!(name); let name = name?;
if input.try(|input| input.expect_comma()).is_ok() { if input.try(|input| input.expect_comma()).is_ok() {
// Exclude `!` and `;` at the top level // Exclude `!` and `;` at the top level
// https://drafts.csswg.org/css-syntax/#typedef-declaration-value // https://drafts.csswg.org/css-syntax/#typedef-declaration-value
try!(input.parse_until_before(Delimiter::Bang | Delimiter::Semicolon, |input| { input.parse_until_before(Delimiter::Bang | Delimiter::Semicolon, |input| {
// At least one non-comment token. // At least one non-comment token.
try!(input.next_including_whitespace()); input.next_including_whitespace()?;
// Skip until the end. // Skip until the end.
while let Ok(_) = input.next_including_whitespace_and_comments() {} while let Ok(_) = input.next_including_whitespace_and_comments() {}
Ok(()) Ok(())
})); })?;
} }
if let Some(ref mut refs) = *references { if let Some(ref mut refs) = *references {
refs.insert(Atom::from(name)); refs.insert(Atom::from(name));
@ -562,7 +561,7 @@ fn substitute_block<'i, 't, F>(input: &mut Parser<'i, 't>,
Token::Function(ref name) if name.eq_ignore_ascii_case("var") => { Token::Function(ref name) if name.eq_ignore_ascii_case("var") => {
partial_computed_value.push( partial_computed_value.push(
input.slice(position.0..before_this_token), position.1, last_token_type); input.slice(position.0..before_this_token), position.1, last_token_type);
try!(input.parse_nested_block(|input| { input.parse_nested_block(|input| {
// parse_var_function() ensures neither .unwrap() will fail. // parse_var_function() ensures neither .unwrap() will fail.
let name = input.expect_ident().unwrap(); let name = input.expect_ident().unwrap();
let name = Atom::from(parse_name(&name).unwrap()); let name = Atom::from(parse_name(&name).unwrap());
@ -574,7 +573,7 @@ fn substitute_block<'i, 't, F>(input: &mut Parser<'i, 't>,
// FIXME: Add a specialized method to cssparser to do this with less work. // FIXME: Add a specialized method to cssparser to do this with less work.
while let Ok(_) = input.next() {} while let Ok(_) = input.next() {}
} else { } else {
try!(input.expect_comma()); input.expect_comma()?;
let position = input.position(); let position = input.position();
let first_token_type = input.next_including_whitespace_and_comments() let first_token_type = input.next_including_whitespace_and_comments()
// parse_var_function() ensures that .unwrap() will not fail. // parse_var_function() ensures that .unwrap() will not fail.
@ -582,12 +581,12 @@ fn substitute_block<'i, 't, F>(input: &mut Parser<'i, 't>,
.serialization_type(); .serialization_type();
input.reset(position); input.reset(position);
let mut position = (position, first_token_type); let mut position = (position, first_token_type);
last_token_type = try!(substitute_block( last_token_type = substitute_block(
input, &mut position, partial_computed_value, substitute_one)); input, &mut position, partial_computed_value, substitute_one)?;
partial_computed_value.push_from(position, input, last_token_type); partial_computed_value.push_from(position, input, last_token_type);
} }
Ok(()) Ok(())
})); })?;
set_position_at_next_iteration = true set_position_at_next_iteration = true
} }
@ -595,9 +594,9 @@ fn substitute_block<'i, 't, F>(input: &mut Parser<'i, 't>,
Token::ParenthesisBlock | Token::ParenthesisBlock |
Token::CurlyBracketBlock | Token::CurlyBracketBlock |
Token::SquareBracketBlock => { Token::SquareBracketBlock => {
try!(input.parse_nested_block(|input| { input.parse_nested_block(|input| {
substitute_block(input, position, partial_computed_value, substitute_one) substitute_block(input, position, partial_computed_value, substitute_one)
})); })?;
// Its the same type for CloseCurlyBracket and CloseSquareBracket. // Its the same type for CloseCurlyBracket and CloseSquareBracket.
last_token_type = Token::CloseParenthesis.serialization_type(); last_token_type = Token::CloseParenthesis.serialization_type();
} }
@ -623,7 +622,7 @@ pub fn substitute<'i>(input: &'i str, first_token_type: TokenSerializationType,
let mut input = ParserInput::new(input); let mut input = ParserInput::new(input);
let mut input = Parser::new(&mut input); let mut input = Parser::new(&mut input);
let mut position = (input.position(), first_token_type); let mut position = (input.position(), first_token_type);
let last_token_type = try!(substitute_block( let last_token_type = substitute_block(
&mut input, &mut position, &mut substituted, &mut |name, substituted| { &mut input, &mut position, &mut substituted, &mut |name, substituted| {
if let Some(value) = computed_values_map.as_ref().and_then(|map| map.get(name)) { if let Some(value) = computed_values_map.as_ref().and_then(|map| map.get(name)) {
substituted.push_variable(value); substituted.push_variable(value);
@ -632,7 +631,7 @@ pub fn substitute<'i>(input: &'i str, first_token_type: TokenSerializationType,
Err(()) Err(())
} }
} }
)); )?;
substituted.push_from(position, &input, last_token_type); substituted.push_from(position, &input, last_token_type);
Ok(substituted.css) Ok(substituted.css)
} }

View file

@ -180,7 +180,7 @@ impl<N: TNode> Debug for ShowDataAndPrimaryValues<N> {
pub struct ShowSubtree<N: TNode>(pub N); pub struct ShowSubtree<N: TNode>(pub N);
impl<N: TNode> Debug for ShowSubtree<N> { impl<N: TNode> Debug for ShowSubtree<N> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(writeln!(f, "DOM Subtree:")); writeln!(f, "DOM Subtree:")?;
fmt_subtree(f, &|f, n| write!(f, "{:?}", n), self.0, 1) fmt_subtree(f, &|f, n| write!(f, "{:?}", n), self.0, 1)
} }
} }
@ -190,7 +190,7 @@ impl<N: TNode> Debug for ShowSubtree<N> {
pub struct ShowSubtreeData<N: TNode>(pub N); pub struct ShowSubtreeData<N: TNode>(pub N);
impl<N: TNode> Debug for ShowSubtreeData<N> { impl<N: TNode> Debug for ShowSubtreeData<N> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(writeln!(f, "DOM Subtree:")); writeln!(f, "DOM Subtree:")?;
fmt_subtree(f, &|f, n| fmt_with_data(f, n), self.0, 1) fmt_subtree(f, &|f, n| fmt_with_data(f, n), self.0, 1)
} }
} }
@ -200,7 +200,7 @@ impl<N: TNode> Debug for ShowSubtreeData<N> {
pub struct ShowSubtreeDataAndPrimaryValues<N: TNode>(pub N); pub struct ShowSubtreeDataAndPrimaryValues<N: TNode>(pub N);
impl<N: TNode> Debug for ShowSubtreeDataAndPrimaryValues<N> { impl<N: TNode> Debug for ShowSubtreeDataAndPrimaryValues<N> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(writeln!(f, "DOM Subtree:")); writeln!(f, "DOM Subtree:")?;
fmt_subtree(f, &|f, n| fmt_with_data_and_primary_values(f, n), self.0, 1) fmt_subtree(f, &|f, n| fmt_with_data_and_primary_values(f, n), self.0, 1)
} }
} }
@ -230,12 +230,12 @@ fn fmt_subtree<F, N: TNode>(f: &mut fmt::Formatter, stringify: &F, n: N, indent:
where F: Fn(&mut fmt::Formatter, N) -> fmt::Result where F: Fn(&mut fmt::Formatter, N) -> fmt::Result
{ {
for _ in 0..indent { for _ in 0..indent {
try!(write!(f, " ")); write!(f, " ")?;
} }
try!(stringify(f, n)); stringify(f, n)?;
for kid in n.traversal_children() { for kid in n.traversal_children() {
try!(writeln!(f, "")); writeln!(f, "")?;
try!(fmt_subtree(f, stringify, kid, indent + 1)); fmt_subtree(f, stringify, kid, indent + 1)?;
} }
Ok(()) Ok(())

View file

@ -230,7 +230,7 @@ impl Resolution {
} }
fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> { fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
let (value, unit) = match try!(input.next()) { let (value, unit) = match input.next()? {
Token::Dimension { value, unit, .. } => { Token::Dimension { value, unit, .. } => {
(value, unit) (value, unit)
}, },
@ -462,9 +462,9 @@ impl Expression {
/// ``` /// ```
pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Self, ParseError<'i>> { -> Result<Self, ParseError<'i>> {
try!(input.expect_parenthesis_block()); input.expect_parenthesis_block()?;
input.parse_nested_block(|input| { input.parse_nested_block(|input| {
let ident = try!(input.expect_ident()); let ident = input.expect_ident()?;
let mut flags = 0; let mut flags = 0;
let result = { let result = {

View file

@ -407,9 +407,9 @@ pub struct GeckoElement<'le>(pub &'le RawGeckoElement);
impl<'le> fmt::Debug for GeckoElement<'le> { impl<'le> fmt::Debug for GeckoElement<'le> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "<{}", self.get_local_name())); write!(f, "<{}", self.get_local_name())?;
if let Some(id) = self.get_id() { if let Some(id) = self.get_id() {
try!(write!(f, " id={}", id)); write!(f, " id={}", id)?;
} }
let mut first = true; let mut first = true;

View file

@ -235,7 +235,7 @@ impl fmt::Debug for WeakAtom {
impl fmt::Display for WeakAtom { impl fmt::Display for WeakAtom {
fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
for c in self.chars() { for c in self.chars() {
try!(w.write_char(c.unwrap_or(char::REPLACEMENT_CHARACTER))) w.write_char(c.unwrap_or(char::REPLACEMENT_CHARACTER))?
} }
Ok(()) Ok(())
} }

View file

@ -207,11 +207,11 @@ pub fn serialize_comma_separated_list<W, T>(dest: &mut W,
return Ok(()); return Ok(());
} }
try!(list[0].to_css(dest)); list[0].to_css(dest)?;
for item in list.iter().skip(1) { for item in list.iter().skip(1) {
try!(write!(dest, ", ")); write!(dest, ", ")?;
try!(item.to_css(dest)); item.to_css(dest)?;
} }
Ok(()) Ok(())

View file

@ -144,20 +144,20 @@ impl WritingMode {
impl fmt::Display for WritingMode { impl fmt::Display for WritingMode {
fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error> { fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error> {
if self.is_vertical() { if self.is_vertical() {
try!(write!(formatter, "V")); write!(formatter, "V")?;
if self.is_vertical_lr() { if self.is_vertical_lr() {
try!(write!(formatter, " LR")); write!(formatter, " LR")?;
} else { } else {
try!(write!(formatter, " RL")); write!(formatter, " RL")?;
} }
if self.intersects(FLAG_SIDEWAYS) { if self.intersects(FLAG_SIDEWAYS) {
try!(write!(formatter, " Sideways")); write!(formatter, " Sideways")?;
} }
if self.intersects(FLAG_LINE_INVERTED) { if self.intersects(FLAG_LINE_INVERTED) {
try!(write!(formatter, " Inverted")); write!(formatter, " Inverted")?;
} }
} else { } else {
try!(write!(formatter, "H")); write!(formatter, "H")?;
} }
if self.is_bidi_ltr() { if self.is_bidi_ltr() {
write!(formatter, " LTR") write!(formatter, " LTR")

View file

@ -94,8 +94,8 @@ impl ToCss for MediaQuery {
where W: fmt::Write, where W: fmt::Write,
{ {
if let Some(qual) = self.qualifier { if let Some(qual) = self.qualifier {
try!(qual.to_css(dest)); qual.to_css(dest)?;
try!(write!(dest, " ")); write!(dest, " ")?;
} }
match self.media_type { match self.media_type {
@ -106,12 +106,12 @@ impl ToCss for MediaQuery {
// Otherwise, we'd serialize media queries like "(min-width: // Otherwise, we'd serialize media queries like "(min-width:
// 40px)" in "all (min-width: 40px)", which is unexpected. // 40px)" in "all (min-width: 40px)", which is unexpected.
if self.qualifier.is_some() || self.expressions.is_empty() { if self.qualifier.is_some() || self.expressions.is_empty() {
try!(write!(dest, "all")); write!(dest, "all")?;
} }
}, },
MediaQueryType::Known(MediaType::Screen) => try!(write!(dest, "screen")), MediaQueryType::Known(MediaType::Screen) => write!(dest, "screen")?,
MediaQueryType::Known(MediaType::Print) => try!(write!(dest, "print")), MediaQueryType::Known(MediaType::Print) => write!(dest, "print")?,
MediaQueryType::Unknown(ref desc) => try!(write!(dest, "{}", desc)), MediaQueryType::Unknown(ref desc) => write!(dest, "{}", desc)?,
} }
if self.expressions.is_empty() { if self.expressions.is_empty() {
@ -119,14 +119,14 @@ impl ToCss for MediaQuery {
} }
if self.media_type != MediaQueryType::All || self.qualifier.is_some() { if self.media_type != MediaQueryType::All || self.qualifier.is_some() {
try!(write!(dest, " and ")); write!(dest, " and ")?;
} }
try!(self.expressions[0].to_css(dest)); self.expressions[0].to_css(dest)?;
for expr in self.expressions.iter().skip(1) { for expr in self.expressions.iter().skip(1) {
try!(write!(dest, " and ")); write!(dest, " and ")?;
try!(expr.to_css(dest)); expr.to_css(dest)?;
} }
Ok(()) Ok(())
} }
@ -215,7 +215,7 @@ impl MediaQuery {
Ok(ident) => { Ok(ident) => {
let result: Result<_, ParseError> = MediaQueryType::parse(&*ident) let result: Result<_, ParseError> = MediaQueryType::parse(&*ident)
.map_err(|()| SelectorParseError::UnexpectedIdent(ident).into()); .map_err(|()| SelectorParseError::UnexpectedIdent(ident).into());
try!(result) result?
} }
Err(_) => { Err(_) => {
// Media type is only optional if qualifier is not specified. // Media type is only optional if qualifier is not specified.
@ -224,7 +224,7 @@ impl MediaQuery {
} }
// Without a media type, require at least one expression. // Without a media type, require at least one expression.
expressions.push(try!(Expression::parse(context, input))); expressions.push(Expression::parse(context, input)?);
MediaQueryType::All MediaQueryType::All
} }
@ -235,7 +235,7 @@ impl MediaQuery {
if input.try(|input| input.expect_ident_matching("and")).is_err() { if input.try(|input| input.expect_ident_matching("and")).is_err() {
return Ok(MediaQuery::new(qualifier, media_type, expressions)) return Ok(MediaQuery::new(qualifier, media_type, expressions))
} }
expressions.push(try!(Expression::parse(context, input))) expressions.push(Expression::parse(context, input)?)
} }
} }
} }

View file

@ -840,10 +840,10 @@ pub fn append_serialization<'a, W, I, N>(dest: &mut W,
I: Iterator<Item=&'a PropertyDeclaration>, I: Iterator<Item=&'a PropertyDeclaration>,
N: ToCss, N: ToCss,
{ {
try!(handle_first_serialization(dest, is_first_serialization)); handle_first_serialization(dest, is_first_serialization)?;
try!(property_name.to_css(dest)); property_name.to_css(dest)?;
try!(dest.write_char(':')); dest.write_char(':')?;
// for normal parsed values, add a space between key: and value // for normal parsed values, add a space between key: and value
match appendable_value { match appendable_value {
@ -863,10 +863,10 @@ pub fn append_serialization<'a, W, I, N>(dest: &mut W,
AppendableValue::DeclarationsForShorthand(..) => unreachable!(), AppendableValue::DeclarationsForShorthand(..) => unreachable!(),
} }
try!(append_declaration_value(dest, appendable_value)); append_declaration_value(dest, appendable_value)?;
if importance.important() { if importance.important() {
try!(dest.write_str(" !important")); dest.write_str(" !important")?;
} }
dest.write_char(';') dest.write_char(';')
@ -934,7 +934,7 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for PropertyDeclarationParser<'a, 'b> {
fn parse_value<'t>(&mut self, name: CompactCowStr<'i>, input: &mut Parser<'i, 't>) fn parse_value<'t>(&mut self, name: CompactCowStr<'i>, input: &mut Parser<'i, 't>)
-> Result<Importance, ParseError<'i>> { -> Result<Importance, ParseError<'i>> {
let id = try!(PropertyId::parse(name)); let id = PropertyId::parse(name)?;
input.parse_until_before(Delimiter::Bang, |input| { input.parse_until_before(Delimiter::Bang, |input| {
PropertyDeclaration::parse_into(self.declarations, id, self.context, input) PropertyDeclaration::parse_into(self.declarations, id, self.context, input)
.map_err(|e| e.into()) .map_err(|e| e.into())

View file

@ -158,17 +158,17 @@
{ {
let mut iter = self.0.iter(); let mut iter = self.0.iter();
if let Some(val) = iter.next() { if let Some(val) = iter.next() {
try!(val.to_css(dest)); val.to_css(dest)?;
} else { } else {
% if allow_empty: % if allow_empty:
try!(dest.write_str("none")); dest.write_str("none")?;
% else: % else:
warn!("Found empty value for property ${name}"); warn!("Found empty value for property ${name}");
% endif % endif
} }
for i in iter { for i in iter {
try!(dest.write_str(", ")); dest.write_str(", ")?;
try!(i.to_css(dest)); i.to_css(dest)?;
} }
Ok(()) Ok(())
} }
@ -185,17 +185,17 @@
{ {
let mut iter = self.0.iter(); let mut iter = self.0.iter();
if let Some(val) = iter.next() { if let Some(val) = iter.next() {
try!(val.to_css(dest)); val.to_css(dest)?;
} else { } else {
% if allow_empty: % if allow_empty:
try!(dest.write_str("none")); dest.write_str("none")?;
% else: % else:
warn!("Found empty value for property ${name}"); warn!("Found empty value for property ${name}");
% endif % endif
} }
for i in iter { for i in iter {
try!(dest.write_str(", ")); dest.write_str(", ")?;
try!(i.to_css(dest)); i.to_css(dest)?;
} }
Ok(()) Ok(())
} }
@ -462,8 +462,8 @@
let var = input.seen_var_functions(); let var = input.seen_var_functions();
if specified.is_err() && var { if specified.is_err() && var {
input.reset(start); input.reset(start);
let (first_token_type, css) = try!( let (first_token_type, css) =
::custom_properties::parse_non_custom_with_var(input)); ::custom_properties::parse_non_custom_with_var(input)?;
return Ok(PropertyDeclaration::WithVariables(LonghandId::${property.camel_case}, return Ok(PropertyDeclaration::WithVariables(LonghandId::${property.camel_case},
Arc::new(UnparsedValue { Arc::new(UnparsedValue {
css: css.into_owned(), css: css.into_owned(),
@ -876,8 +876,8 @@
Ok(()) Ok(())
} else if var { } else if var {
input.reset(start); input.reset(start);
let (first_token_type, css) = try!( let (first_token_type, css) =
::custom_properties::parse_non_custom_with_var(input)); ::custom_properties::parse_non_custom_with_var(input)?;
let unparsed = Arc::new(UnparsedValue { let unparsed = Arc::new(UnparsedValue {
css: css.into_owned(), css: css.into_owned(),
first_token_type: first_token_type, first_token_type: first_token_type,

View file

@ -223,7 +223,7 @@ impl TransitionProperty {
/// Parse a transition-property value. /// Parse a transition-property value.
pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> { pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
let ident = try!(input.expect_ident()); let ident = input.expect_ident()?;
let supported = match_ignore_ascii_case! { &ident, let supported = match_ignore_ascii_case! { &ident,
"all" => Ok(Some(TransitionProperty::All)), "all" => Ok(Some(TransitionProperty::All)),
% for prop in data.longhands + data.shorthands_except_all(): % for prop in data.longhands + data.shorthands_except_all():
@ -986,8 +986,8 @@ impl Animatable for Visibility {
impl<T: Animatable + Copy> Animatable for Size2D<T> { impl<T: Animatable + Copy> Animatable for Size2D<T> {
#[inline] #[inline]
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> { fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
let width = try!(self.width.add_weighted(&other.width, self_portion, other_portion)); let width = self.width.add_weighted(&other.width, self_portion, other_portion)?;
let height = try!(self.height.add_weighted(&other.height, self_portion, other_portion)); let height = self.height.add_weighted(&other.height, self_portion, other_portion)?;
Ok(Size2D::new(width, height)) Ok(Size2D::new(width, height))
} }
@ -996,8 +996,8 @@ impl<T: Animatable + Copy> Animatable for Size2D<T> {
impl<T: Animatable + Copy> Animatable for Point2D<T> { impl<T: Animatable + Copy> Animatable for Point2D<T> {
#[inline] #[inline]
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> { fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
let x = try!(self.x.add_weighted(&other.x, self_portion, other_portion)); let x = self.x.add_weighted(&other.x, self_portion, other_portion)?;
let y = try!(self.y.add_weighted(&other.y, self_portion, other_portion)); let y = self.y.add_weighted(&other.y, self_portion, other_portion)?;
Ok(Point2D::new(x, y)) Ok(Point2D::new(x, y))
} }
@ -1016,8 +1016,8 @@ impl Animatable for BorderCornerRadius {
#[inline] #[inline]
fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> { fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> {
Ok(try!(self.0.width.compute_squared_distance(&other.0.width)) + Ok(self.0.width.compute_squared_distance(&other.0.width)? +
try!(self.0.height.compute_squared_distance(&other.0.height))) self.0.height.compute_squared_distance(&other.0.height)?)
} }
} }
@ -1487,10 +1487,8 @@ impl<H: Animatable, V: Animatable> Animatable for generic_position::Position<H,
#[inline] #[inline]
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> { fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
Ok(generic_position::Position { Ok(generic_position::Position {
horizontal: try!(self.horizontal.add_weighted(&other.horizontal, horizontal: self.horizontal.add_weighted(&other.horizontal, self_portion, other_portion)?,
self_portion, other_portion)), vertical: self.vertical.add_weighted(&other.vertical, self_portion, other_portion)?,
vertical: try!(self.vertical.add_weighted(&other.vertical,
self_portion, other_portion)),
}) })
} }
@ -1509,8 +1507,8 @@ impl<H: Animatable, V: Animatable> Animatable for generic_position::Position<H,
#[inline] #[inline]
fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> { fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> {
Ok(try!(self.horizontal.compute_squared_distance(&other.horizontal)) + Ok(self.horizontal.compute_squared_distance(&other.horizontal)? +
try!(self.vertical.compute_squared_distance(&other.vertical))) self.vertical.compute_squared_distance(&other.vertical)?)
} }
} }
@ -1523,10 +1521,10 @@ impl Animatable for ClipRect {
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64)
-> Result<Self, ()> { -> Result<Self, ()> {
Ok(ClipRect { Ok(ClipRect {
top: try!(self.top.add_weighted(&other.top, self_portion, other_portion)), top: self.top.add_weighted(&other.top, self_portion, other_portion)?,
right: try!(self.right.add_weighted(&other.right, self_portion, other_portion)), right: self.right.add_weighted(&other.right, self_portion, other_portion)?,
bottom: try!(self.bottom.add_weighted(&other.bottom, self_portion, other_portion)), bottom: self.bottom.add_weighted(&other.bottom, self_portion, other_portion)?,
left: try!(self.left.add_weighted(&other.left, self_portion, other_portion)), left: self.left.add_weighted(&other.left, self_portion, other_portion)?,
}) })
} }
@ -1537,10 +1535,12 @@ impl Animatable for ClipRect {
#[inline] #[inline]
fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> { fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> {
let list = [ try!(self.top.compute_distance(&other.top)), let list = [
try!(self.right.compute_distance(&other.right)), self.top.compute_distance(&other.top)?,
try!(self.bottom.compute_distance(&other.bottom)), self.right.compute_distance(&other.right)?,
try!(self.left.compute_distance(&other.left)) ]; self.bottom.compute_distance(&other.bottom)?,
self.left.compute_distance(&other.left)?
];
Ok(list.iter().fold(0.0f64, |sum, diff| sum + diff * diff)) Ok(list.iter().fold(0.0f64, |sum, diff| sum + diff * diff))
} }
} }
@ -1630,9 +1630,9 @@ fn add_weighted_with_initial_val<T: Animatable>(a: &T,
a_portion: f64, a_portion: f64,
b_portion: f64, b_portion: f64,
initial_val: &T) -> Result<T, ()> { initial_val: &T) -> Result<T, ()> {
let a = try!(a.add_weighted(&initial_val, 1.0, -1.0)); let a = a.add_weighted(&initial_val, 1.0, -1.0)?;
let b = try!(b.add_weighted(&initial_val, 1.0, -1.0)); let b = b.add_weighted(&initial_val, 1.0, -1.0)?;
let result = try!(a.add_weighted(&b, a_portion, b_portion)); let result = a.add_weighted(&b, a_portion, b_portion)?;
result.add_weighted(&initial_val, 1.0, 1.0) result.add_weighted(&initial_val, 1.0, 1.0)
} }
@ -1793,12 +1793,12 @@ pub struct MatrixDecomposed2D {
impl Animatable for InnerMatrix2D { impl Animatable for InnerMatrix2D {
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> { fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
Ok(InnerMatrix2D { Ok(InnerMatrix2D {
m11: try!(add_weighted_with_initial_val(&self.m11, &other.m11, m11: add_weighted_with_initial_val(&self.m11, &other.m11,
self_portion, other_portion, &1.0)), self_portion, other_portion, &1.0)?,
m12: try!(self.m12.add_weighted(&other.m12, self_portion, other_portion)), m12: self.m12.add_weighted(&other.m12, self_portion, other_portion)?,
m21: try!(self.m21.add_weighted(&other.m21, self_portion, other_portion)), m21: self.m21.add_weighted(&other.m21, self_portion, other_portion)?,
m22: try!(add_weighted_with_initial_val(&self.m22, &other.m22, m22: add_weighted_with_initial_val(&self.m22, &other.m22,
self_portion, other_portion, &1.0)), self_portion, other_portion, &1.0)?,
}) })
} }
} }
@ -1806,8 +1806,8 @@ impl Animatable for InnerMatrix2D {
impl Animatable for Translate2D { impl Animatable for Translate2D {
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> { fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
Ok(Translate2D( Ok(Translate2D(
try!(self.0.add_weighted(&other.0, self_portion, other_portion)), self.0.add_weighted(&other.0, self_portion, other_portion)?,
try!(self.1.add_weighted(&other.1, self_portion, other_portion)) self.1.add_weighted(&other.1, self_portion, other_portion)?,
)) ))
} }
} }
@ -1815,8 +1815,8 @@ impl Animatable for Translate2D {
impl Animatable for Scale2D { impl Animatable for Scale2D {
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> { fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
Ok(Scale2D( Ok(Scale2D(
try!(add_weighted_with_initial_val(&self.0, &other.0, self_portion, other_portion, &1.0)), add_weighted_with_initial_val(&self.0, &other.0, self_portion, other_portion, &1.0)?,
try!(add_weighted_with_initial_val(&self.1, &other.1, self_portion, other_portion, &1.0)) add_weighted_with_initial_val(&self.1, &other.1, self_portion, other_portion, &1.0)?,
)) ))
} }
} }
@ -1853,11 +1853,10 @@ impl Animatable for MatrixDecomposed2D {
} }
// Interpolate all values. // Interpolate all values.
let translate = try!(self.translate.add_weighted(&other.translate, let translate = self.translate.add_weighted(&other.translate, self_portion, other_portion)?;
self_portion, other_portion)); let scale = scale.add_weighted(&other.scale, self_portion, other_portion)?;
let scale = try!(scale.add_weighted(&other.scale, self_portion, other_portion)); let angle = angle.add_weighted(&other_angle, self_portion, other_portion)?;
let angle = try!(angle.add_weighted(&other_angle, self_portion, other_portion)); let matrix = self.matrix.add_weighted(&other.matrix, self_portion, other_portion)?;
let matrix = try!(self.matrix.add_weighted(&other.matrix, self_portion, other_portion));
Ok(MatrixDecomposed2D { Ok(MatrixDecomposed2D {
translate: translate, translate: translate,
@ -1875,7 +1874,7 @@ impl Animatable for ComputedMatrix {
let decomposed_to = decompose_3d_matrix(*other); let decomposed_to = decompose_3d_matrix(*other);
match (decomposed_from, decomposed_to) { match (decomposed_from, decomposed_to) {
(Ok(from), Ok(to)) => { (Ok(from), Ok(to)) => {
let sum = try!(from.add_weighted(&to, self_portion, other_portion)); let sum = from.add_weighted(&to, self_portion, other_portion)?;
Ok(ComputedMatrix::from(sum)) Ok(ComputedMatrix::from(sum))
}, },
_ => { _ => {
@ -1886,8 +1885,7 @@ impl Animatable for ComputedMatrix {
} else { } else {
let decomposed_from = MatrixDecomposed2D::from(*self); let decomposed_from = MatrixDecomposed2D::from(*self);
let decomposed_to = MatrixDecomposed2D::from(*other); let decomposed_to = MatrixDecomposed2D::from(*other);
let sum = try!(decomposed_from.add_weighted(&decomposed_to, let sum = decomposed_from.add_weighted(&decomposed_to, self_portion, other_portion)?;
self_portion, other_portion));
Ok(ComputedMatrix::from(sum)) Ok(ComputedMatrix::from(sum))
} }
} }
@ -2228,9 +2226,9 @@ fn cross(row1: [f32; 3], row2: [f32; 3]) -> [f32; 3] {
impl Animatable for Translate3D { impl Animatable for Translate3D {
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> { fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
Ok(Translate3D( Ok(Translate3D(
try!(self.0.add_weighted(&other.0, self_portion, other_portion)), self.0.add_weighted(&other.0, self_portion, other_portion)?,
try!(self.1.add_weighted(&other.1, self_portion, other_portion)), self.1.add_weighted(&other.1, self_portion, other_portion)?,
try!(self.2.add_weighted(&other.2, self_portion, other_portion)) self.2.add_weighted(&other.2, self_portion, other_portion)?,
)) ))
} }
} }
@ -2238,9 +2236,9 @@ impl Animatable for Translate3D {
impl Animatable for Scale3D { impl Animatable for Scale3D {
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> { fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
Ok(Scale3D( Ok(Scale3D(
try!(add_weighted_with_initial_val(&self.0, &other.0, self_portion, other_portion, &1.0)), add_weighted_with_initial_val(&self.0, &other.0, self_portion, other_portion, &1.0)?,
try!(add_weighted_with_initial_val(&self.1, &other.1, self_portion, other_portion, &1.0)), add_weighted_with_initial_val(&self.1, &other.1, self_portion, other_portion, &1.0)?,
try!(add_weighted_with_initial_val(&self.2, &other.2, self_portion, other_portion, &1.0)) add_weighted_with_initial_val(&self.2, &other.2, self_portion, other_portion, &1.0)?,
)) ))
} }
} }
@ -2248,9 +2246,9 @@ impl Animatable for Scale3D {
impl Animatable for Skew { impl Animatable for Skew {
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> { fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
Ok(Skew( Ok(Skew(
try!(self.0.add_weighted(&other.0, self_portion, other_portion)), self.0.add_weighted(&other.0, self_portion, other_portion)?,
try!(self.1.add_weighted(&other.1, self_portion, other_portion)), self.1.add_weighted(&other.1, self_portion, other_portion)?,
try!(self.2.add_weighted(&other.2, self_portion, other_portion)) self.2.add_weighted(&other.2, self_portion, other_portion)?,
)) ))
} }
} }
@ -2258,10 +2256,10 @@ impl Animatable for Skew {
impl Animatable for Perspective { impl Animatable for Perspective {
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> { fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
Ok(Perspective( Ok(Perspective(
try!(self.0.add_weighted(&other.0, self_portion, other_portion)), self.0.add_weighted(&other.0, self_portion, other_portion)?,
try!(self.1.add_weighted(&other.1, self_portion, other_portion)), self.1.add_weighted(&other.1, self_portion, other_portion)?,
try!(self.2.add_weighted(&other.2, self_portion, other_portion)), self.2.add_weighted(&other.2, self_portion, other_portion)?,
try!(add_weighted_with_initial_val(&self.3, &other.3, self_portion, other_portion, &1.0)) add_weighted_with_initial_val(&self.3, &other.3, self_portion, other_portion, &1.0)?,
)) ))
} }
} }
@ -2277,12 +2275,10 @@ impl Animatable for MatrixDecomposed3D {
let mut sum = *self; let mut sum = *self;
// Add translate, scale, skew and perspective components. // Add translate, scale, skew and perspective components.
sum.translate = try!(self.translate.add_weighted(&other.translate, sum.translate = self.translate.add_weighted(&other.translate, self_portion, other_portion)?;
self_portion, other_portion)); sum.scale = self.scale.add_weighted(&other.scale, self_portion, other_portion)?;
sum.scale = try!(self.scale.add_weighted(&other.scale, self_portion, other_portion)); sum.skew = self.skew.add_weighted(&other.skew, self_portion, other_portion)?;
sum.skew = try!(self.skew.add_weighted(&other.skew, self_portion, other_portion)); sum.perspective = self.perspective.add_weighted(&other.perspective, self_portion, other_portion)?;
sum.perspective = try!(self.perspective.add_weighted(&other.perspective,
self_portion, other_portion));
// Add quaternions using spherical linear interpolation (Slerp). // Add quaternions using spherical linear interpolation (Slerp).
// //
@ -2734,25 +2730,22 @@ impl Animatable for IntermediateRGBA {
#[inline] #[inline]
fn add_weighted(&self, other: &IntermediateRGBA, self_portion: f64, other_portion: f64) fn add_weighted(&self, other: &IntermediateRGBA, self_portion: f64, other_portion: f64)
-> Result<Self, ()> { -> Result<Self, ()> {
let mut alpha = try!(self.alpha.add_weighted(&other.alpha, self_portion, other_portion)); let mut alpha = self.alpha.add_weighted(&other.alpha, self_portion, other_portion)?;
if alpha <= 0. { if alpha <= 0. {
// Ideally we should return color value that only alpha component is // Ideally we should return color value that only alpha component is
// 0, but this is what current gecko does. // 0, but this is what current gecko does.
Ok(IntermediateRGBA::transparent()) Ok(IntermediateRGBA::transparent())
} else { } else {
alpha = alpha.min(1.); alpha = alpha.min(1.);
let red = try!((self.red * self.alpha) let red = (self.red * self.alpha).add_weighted(
.add_weighted(&(other.red * other.alpha), &(other.red * other.alpha), self_portion, other_portion
self_portion, other_portion)) )? * 1. / alpha;
* 1. / alpha; let green = (self.green * self.alpha).add_weighted(
let green = try!((self.green * self.alpha) &(other.green * other.alpha), self_portion, other_portion
.add_weighted(&(other.green * other.alpha), )? * 1. / alpha;
self_portion, other_portion)) let blue = (self.blue * self.alpha).add_weighted(
* 1. / alpha; &(other.blue * other.alpha), self_portion, other_portion
let blue = try!((self.blue * self.alpha) )? * 1. / alpha;
.add_weighted(&(other.blue * other.alpha),
self_portion, other_portion))
* 1. / alpha;
Ok(IntermediateRGBA::new(red, green, blue, alpha)) Ok(IntermediateRGBA::new(red, green, blue, alpha))
} }
} }
@ -3093,13 +3086,11 @@ impl Animatable for IntermediateShadow {
return Err(()); return Err(());
} }
let x = try!(self.offset_x.add_weighted(&other.offset_x, self_portion, other_portion)); let x = self.offset_x.add_weighted(&other.offset_x, self_portion, other_portion)?;
let y = try!(self.offset_y.add_weighted(&other.offset_y, self_portion, other_portion)); let y = self.offset_y.add_weighted(&other.offset_y, self_portion, other_portion)?;
let color = try!(self.color.add_weighted(&other.color, self_portion, other_portion)); let color = self.color.add_weighted(&other.color, self_portion, other_portion)?;
let blur = try!(self.blur_radius.add_weighted(&other.blur_radius, let blur = self.blur_radius.add_weighted(&other.blur_radius, self_portion, other_portion)?;
self_portion, other_portion)); let spread = self.spread_radius.add_weighted(&other.spread_radius, self_portion, other_portion)?;
let spread = try!(self.spread_radius.add_weighted(&other.spread_radius,
self_portion, other_portion));
Ok(IntermediateShadow { Ok(IntermediateShadow {
offset_x: x, offset_x: x,
@ -3121,11 +3112,12 @@ impl Animatable for IntermediateShadow {
if self.inset != other.inset { if self.inset != other.inset {
return Err(()); return Err(());
} }
let list = [ try!(self.offset_x.compute_distance(&other.offset_x)), let list = [
try!(self.offset_y.compute_distance(&other.offset_y)), self.offset_x.compute_distance(&other.offset_x)?,
try!(self.blur_radius.compute_distance(&other.blur_radius)), self.offset_y.compute_distance(&other.offset_y)?,
try!(self.color.compute_distance(&other.color)), self.blur_radius.compute_distance(&other.blur_radius)?,
try!(self.spread_radius.compute_distance(&other.spread_radius)), self.color.compute_distance(&other.color)?,
self.spread_radius.compute_distance(&other.spread_radius)?,
]; ];
Ok(list.iter().fold(0.0f64, |sum, diff| sum + diff * diff)) Ok(list.iter().fold(0.0f64, |sum, diff| sum + diff * diff))
} }
@ -3155,8 +3147,9 @@ impl Animatable for IntermediateShadowList {
for i in 0..max_len { for i in 0..max_len {
let shadow = match (self.0.get(i), other.0.get(i)) { let shadow = match (self.0.get(i), other.0.get(i)) {
(Some(shadow), Some(other)) => (Some(shadow), Some(other)) => {
try!(shadow.add_weighted(other, self_portion, other_portion)), shadow.add_weighted(other, self_portion, other_portion)?
}
(Some(shadow), None) => { (Some(shadow), None) => {
zero.inset = shadow.inset; zero.inset = shadow.inset;
shadow.add_weighted(&zero, self_portion, other_portion).unwrap() shadow.add_weighted(&zero, self_portion, other_portion).unwrap()

View file

@ -66,10 +66,10 @@ ${helpers.predefined_type("background-image", "ImageLayer",
(RepeatKeyword::Repeat, RepeatKeyword::NoRepeat) => dest.write_str("repeat-x"), (RepeatKeyword::Repeat, RepeatKeyword::NoRepeat) => dest.write_str("repeat-x"),
(RepeatKeyword::NoRepeat, RepeatKeyword::Repeat) => dest.write_str("repeat-y"), (RepeatKeyword::NoRepeat, RepeatKeyword::Repeat) => dest.write_str("repeat-y"),
(horizontal, vertical) => { (horizontal, vertical) => {
try!(horizontal.to_css(dest)); horizontal.to_css(dest)?;
if horizontal != vertical { if horizontal != vertical {
try!(dest.write_str(" ")); dest.write_str(" ")?;
try!(vertical.to_css(dest)); vertical.to_css(dest)?;
} }
Ok(()) Ok(())
}, },
@ -82,10 +82,10 @@ ${helpers.predefined_type("background-image", "ImageLayer",
SpecifiedValue::RepeatX => dest.write_str("repeat-x"), SpecifiedValue::RepeatX => dest.write_str("repeat-x"),
SpecifiedValue::RepeatY => dest.write_str("repeat-y"), SpecifiedValue::RepeatY => dest.write_str("repeat-y"),
SpecifiedValue::Other(horizontal, vertical) => { SpecifiedValue::Other(horizontal, vertical) => {
try!(horizontal.to_css(dest)); horizontal.to_css(dest)?;
if let Some(vertical) = vertical { if let Some(vertical) = vertical {
try!(dest.write_str(" ")); dest.write_str(" ")?;
try!(vertical.to_css(dest)); vertical.to_css(dest)?;
} }
Ok(()) Ok(())
} }
@ -138,7 +138,7 @@ ${helpers.predefined_type("background-image", "ImageLayer",
}).or_else(|()| { }).or_else(|()| {
let horizontal: Result<_, ParseError> = RepeatKeyword::from_ident(&ident) let horizontal: Result<_, ParseError> = RepeatKeyword::from_ident(&ident)
.map_err(|()| SelectorParseError::UnexpectedIdent(ident).into()); .map_err(|()| SelectorParseError::UnexpectedIdent(ident).into());
let horizontal = try!(horizontal); let horizontal = horizontal?;
let vertical = input.try(RepeatKeyword::parse).ok(); let vertical = input.try(RepeatKeyword::parse).ok();
Ok(SpecifiedValue::Other(horizontal, vertical)) Ok(SpecifiedValue::Other(horizontal, vertical))
}) })

View file

@ -91,10 +91,10 @@ ${helpers.gecko_keyword_conversion(Keyword('border-style',
let mut first = true; let mut first = true;
for ref color in vec { for ref color in vec {
if !first { if !first {
try!(dest.write_str(" ")); dest.write_str(" ")?;
} }
first = false; first = false;
try!(color.to_css(dest)) color.to_css(dest)?
} }
Ok(()) Ok(())
} }
@ -110,10 +110,10 @@ ${helpers.gecko_keyword_conversion(Keyword('border-style',
let mut first = true; let mut first = true;
for ref color in vec { for ref color in vec {
if !first { if !first {
try!(dest.write_str(" ")); dest.write_str(" ")?;
} }
first = false; first = false;
try!(color.to_css(dest)) color.to_css(dest)?
} }
Ok(()) Ok(())
} }
@ -240,10 +240,10 @@ ${helpers.predefined_type("border-image-outset", "LengthOrNumberRect",
impl ToCss for SpecifiedValue { impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
try!(self.0.to_css(dest)); self.0.to_css(dest)?;
if let Some(second) = self.1 { if let Some(second) = self.1 {
try!(dest.write_str(" ")); dest.write_str(" ")?;
try!(second.to_css(dest)); second.to_css(dest)?;
} }
Ok(()) Ok(())
} }
@ -274,7 +274,7 @@ ${helpers.predefined_type("border-image-outset", "LengthOrNumberRect",
pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<SpecifiedValue, ParseError<'i>> { -> Result<SpecifiedValue, ParseError<'i>> {
let first = try!(RepeatKeyword::parse(input)); let first = RepeatKeyword::parse(input)?;
let second = input.try(RepeatKeyword::parse).ok(); let second = input.try(RepeatKeyword::parse).ok();
Ok(SpecifiedValue(first, second)) Ok(SpecifiedValue(first, second))

View file

@ -567,7 +567,7 @@ ${helpers.predefined_type("animation-timing-function",
return Ok(SpecifiedValue::Infinite) return Ok(SpecifiedValue::Infinite)
} }
let number = try!(input.expect_number()); let number = input.expect_number()?;
if number < 0.0 { if number < 0.0 {
return Err(StyleParseError::UnspecifiedError.into()); return Err(StyleParseError::UnspecifiedError.into());
} }
@ -936,10 +936,10 @@ ${helpers.predefined_type("scroll-snap-coordinate",
let mut first = true; let mut first = true;
for operation in &self.0 { for operation in &self.0 {
if !first { if !first {
try!(dest.write_str(" ")); dest.write_str(" ")?;
} }
first = false; first = false;
try!(operation.to_css(dest)) operation.to_css(dest)?
} }
Ok(()) Ok(())
} }
@ -966,12 +966,12 @@ ${helpers.predefined_type("scroll-snap-coordinate",
let valid_fn = match_ignore_ascii_case! { let valid_fn = match_ignore_ascii_case! {
&name, &name,
"matrix" => { "matrix" => {
try!(input.parse_nested_block(|input| { input.parse_nested_block(|input| {
// Standard matrix parsing. // Standard matrix parsing.
if !prefixed { if !prefixed {
let values = try!(input.parse_comma_separated(|input| { let values = input.parse_comma_separated(|input| {
specified::parse_number(context, input) specified::parse_number(context, input)
})); })?;
if values.len() != 6 { if values.len() != 6 {
return Err(StyleParseError::UnspecifiedError.into()) return Err(StyleParseError::UnspecifiedError.into())
} }
@ -1018,13 +1018,13 @@ ${helpers.predefined_type("scroll-snap-coordinate",
f: lengths[1].clone(), f: lengths[1].clone(),
}); });
Ok(true) Ok(true)
})) })?
}, },
"matrix3d" => { "matrix3d" => {
try!(input.parse_nested_block(|input| { input.parse_nested_block(|input| {
// Standard matrix3d parsing. // Standard matrix3d parsing.
if !prefixed { if !prefixed {
let values = try!(input.parse_comma_separated(|i| specified::parse_number(context, i))); let values = input.parse_comma_separated(|i| specified::parse_number(context, i))?;
if values.len() != 16 { if values.len() != 16 {
return Err(StyleParseError::UnspecifiedError.into()) return Err(StyleParseError::UnspecifiedError.into())
} }
@ -1073,170 +1073,170 @@ ${helpers.predefined_type("scroll-snap-coordinate",
m44: values[12] m44: values[12]
}); });
Ok(true) Ok(true)
})) })?
}, },
"translate" => { "translate" => {
try!(input.parse_nested_block(|input| { input.parse_nested_block(|input| {
let sx = try!(specified::LengthOrPercentage::parse(context, input)); let sx = specified::LengthOrPercentage::parse(context, input)?;
if input.try(|input| input.expect_comma()).is_ok() { if input.try(|input| input.expect_comma()).is_ok() {
let sy = try!(specified::LengthOrPercentage::parse(context, input)); let sy = specified::LengthOrPercentage::parse(context, input)?;
result.push(SpecifiedOperation::Translate(sx, Some(sy))); result.push(SpecifiedOperation::Translate(sx, Some(sy)));
} else { } else {
result.push(SpecifiedOperation::Translate(sx, None)); result.push(SpecifiedOperation::Translate(sx, None));
} }
Ok(true) Ok(true)
})) })?
}, },
"translatex" => { "translatex" => {
try!(input.parse_nested_block(|input| { input.parse_nested_block(|input| {
let tx = try!(specified::LengthOrPercentage::parse(context, input)); let tx = specified::LengthOrPercentage::parse(context, input)?;
result.push(SpecifiedOperation::TranslateX(tx)); result.push(SpecifiedOperation::TranslateX(tx));
Ok(true) Ok(true)
})) })?
}, },
"translatey" => { "translatey" => {
try!(input.parse_nested_block(|input| { input.parse_nested_block(|input| {
let ty = try!(specified::LengthOrPercentage::parse(context, input)); let ty = specified::LengthOrPercentage::parse(context, input)?;
result.push(SpecifiedOperation::TranslateY(ty)); result.push(SpecifiedOperation::TranslateY(ty));
Ok(true) Ok(true)
})) })?
}, },
"translatez" => { "translatez" => {
try!(input.parse_nested_block(|input| { input.parse_nested_block(|input| {
let tz = try!(specified::Length::parse(context, input)); let tz = specified::Length::parse(context, input)?;
result.push(SpecifiedOperation::TranslateZ(tz)); result.push(SpecifiedOperation::TranslateZ(tz));
Ok(true) Ok(true)
})) })?
}, },
"translate3d" => { "translate3d" => {
try!(input.parse_nested_block(|input| { input.parse_nested_block(|input| {
let tx = try!(specified::LengthOrPercentage::parse(context, input)); let tx = specified::LengthOrPercentage::parse(context, input)?;
try!(input.expect_comma()); input.expect_comma()?;
let ty = try!(specified::LengthOrPercentage::parse(context, input)); let ty = specified::LengthOrPercentage::parse(context, input)?;
try!(input.expect_comma()); input.expect_comma()?;
let tz = try!(specified::Length::parse(context, input)); let tz = specified::Length::parse(context, input)?;
result.push(SpecifiedOperation::Translate3D(tx, ty, tz)); result.push(SpecifiedOperation::Translate3D(tx, ty, tz));
Ok(true) Ok(true)
})) })?
}, },
"scale" => { "scale" => {
try!(input.parse_nested_block(|input| { input.parse_nested_block(|input| {
let sx = try!(specified::parse_number(context, input)); let sx = specified::parse_number(context, input)?;
if input.try(|input| input.expect_comma()).is_ok() { if input.try(|input| input.expect_comma()).is_ok() {
let sy = try!(specified::parse_number(context, input)); let sy = specified::parse_number(context, input)?;
result.push(SpecifiedOperation::Scale(sx, Some(sy))); result.push(SpecifiedOperation::Scale(sx, Some(sy)));
} else { } else {
result.push(SpecifiedOperation::Scale(sx, None)); result.push(SpecifiedOperation::Scale(sx, None));
} }
Ok(true) Ok(true)
})) })?
}, },
"scalex" => { "scalex" => {
try!(input.parse_nested_block(|input| { input.parse_nested_block(|input| {
let sx = try!(specified::parse_number(context, input)); let sx = specified::parse_number(context, input)?;
result.push(SpecifiedOperation::ScaleX(sx)); result.push(SpecifiedOperation::ScaleX(sx));
Ok(true) Ok(true)
})) })?
}, },
"scaley" => { "scaley" => {
try!(input.parse_nested_block(|input| { input.parse_nested_block(|input| {
let sy = try!(specified::parse_number(context, input)); let sy = specified::parse_number(context, input)?;
result.push(SpecifiedOperation::ScaleY(sy)); result.push(SpecifiedOperation::ScaleY(sy));
Ok(true) Ok(true)
})) })?
}, },
"scalez" => { "scalez" => {
try!(input.parse_nested_block(|input| { input.parse_nested_block(|input| {
let sz = try!(specified::parse_number(context, input)); let sz = specified::parse_number(context, input)?;
result.push(SpecifiedOperation::ScaleZ(sz)); result.push(SpecifiedOperation::ScaleZ(sz));
Ok(true) Ok(true)
})) })?
}, },
"scale3d" => { "scale3d" => {
try!(input.parse_nested_block(|input| { input.parse_nested_block(|input| {
let sx = try!(specified::parse_number(context, input)); let sx = specified::parse_number(context, input)?;
try!(input.expect_comma()); input.expect_comma()?;
let sy = try!(specified::parse_number(context, input)); let sy = specified::parse_number(context, input)?;
try!(input.expect_comma()); input.expect_comma()?;
let sz = try!(specified::parse_number(context, input)); let sz = specified::parse_number(context, input)?;
result.push(SpecifiedOperation::Scale3D(sx, sy, sz)); result.push(SpecifiedOperation::Scale3D(sx, sy, sz));
Ok(true) Ok(true)
})) })?
}, },
"rotate" => { "rotate" => {
try!(input.parse_nested_block(|input| { input.parse_nested_block(|input| {
let theta = try!(specified::Angle::parse_with_unitless(context, input)); let theta = specified::Angle::parse_with_unitless(context, input)?;
result.push(SpecifiedOperation::Rotate(theta)); result.push(SpecifiedOperation::Rotate(theta));
Ok(true) Ok(true)
})) })?
}, },
"rotatex" => { "rotatex" => {
try!(input.parse_nested_block(|input| { input.parse_nested_block(|input| {
let theta = try!(specified::Angle::parse_with_unitless(context, input)); let theta = specified::Angle::parse_with_unitless(context, input)?;
result.push(SpecifiedOperation::RotateX(theta)); result.push(SpecifiedOperation::RotateX(theta));
Ok(true) Ok(true)
})) })?
}, },
"rotatey" => { "rotatey" => {
try!(input.parse_nested_block(|input| { input.parse_nested_block(|input| {
let theta = try!(specified::Angle::parse_with_unitless(context, input)); let theta = specified::Angle::parse_with_unitless(context, input)?;
result.push(SpecifiedOperation::RotateY(theta)); result.push(SpecifiedOperation::RotateY(theta));
Ok(true) Ok(true)
})) })?
}, },
"rotatez" => { "rotatez" => {
try!(input.parse_nested_block(|input| { input.parse_nested_block(|input| {
let theta = try!(specified::Angle::parse_with_unitless(context, input)); let theta = specified::Angle::parse_with_unitless(context, input)?;
result.push(SpecifiedOperation::RotateZ(theta)); result.push(SpecifiedOperation::RotateZ(theta));
Ok(true) Ok(true)
})) })?
}, },
"rotate3d" => { "rotate3d" => {
try!(input.parse_nested_block(|input| { input.parse_nested_block(|input| {
let ax = try!(specified::parse_number(context, input)); let ax = specified::parse_number(context, input)?;
try!(input.expect_comma()); input.expect_comma()?;
let ay = try!(specified::parse_number(context, input)); let ay = specified::parse_number(context, input)?;
try!(input.expect_comma()); input.expect_comma()?;
let az = try!(specified::parse_number(context, input)); let az = specified::parse_number(context, input)?;
try!(input.expect_comma()); input.expect_comma()?;
let theta = try!(specified::Angle::parse_with_unitless(context, input)); let theta = specified::Angle::parse_with_unitless(context, input)?;
// TODO(gw): Check the axis can be normalized!! // TODO(gw): Check the axis can be normalized!!
result.push(SpecifiedOperation::Rotate3D(ax, ay, az, theta)); result.push(SpecifiedOperation::Rotate3D(ax, ay, az, theta));
Ok(true) Ok(true)
})) })?
}, },
"skew" => { "skew" => {
try!(input.parse_nested_block(|input| { input.parse_nested_block(|input| {
let theta_x = try!(specified::Angle::parse_with_unitless(context, input)); let theta_x = specified::Angle::parse_with_unitless(context, input)?;
if input.try(|input| input.expect_comma()).is_ok() { if input.try(|input| input.expect_comma()).is_ok() {
let theta_y = try!(specified::Angle::parse_with_unitless(context, input)); let theta_y = specified::Angle::parse_with_unitless(context, input)?;
result.push(SpecifiedOperation::Skew(theta_x, Some(theta_y))); result.push(SpecifiedOperation::Skew(theta_x, Some(theta_y)));
} else { } else {
result.push(SpecifiedOperation::Skew(theta_x, None)); result.push(SpecifiedOperation::Skew(theta_x, None));
} }
Ok(true) Ok(true)
})) })?
}, },
"skewx" => { "skewx" => {
try!(input.parse_nested_block(|input| { input.parse_nested_block(|input| {
let theta_x = try!(specified::Angle::parse_with_unitless(context, input)); let theta_x = specified::Angle::parse_with_unitless(context, input)?;
result.push(SpecifiedOperation::SkewX(theta_x)); result.push(SpecifiedOperation::SkewX(theta_x));
Ok(true) Ok(true)
})) })?
}, },
"skewy" => { "skewy" => {
try!(input.parse_nested_block(|input| { input.parse_nested_block(|input| {
let theta_y = try!(specified::Angle::parse_with_unitless(context, input)); let theta_y = specified::Angle::parse_with_unitless(context, input)?;
result.push(SpecifiedOperation::SkewY(theta_y)); result.push(SpecifiedOperation::SkewY(theta_y));
Ok(true) Ok(true)
})) })?
}, },
"perspective" => { "perspective" => {
try!(input.parse_nested_block(|input| { input.parse_nested_block(|input| {
let d = try!(specified::Length::parse_non_negative(context, input)); let d = specified::Length::parse_non_negative(context, input)?;
result.push(SpecifiedOperation::Perspective(d)); result.push(SpecifiedOperation::Perspective(d));
Ok(true) Ok(true)
})) })?
}, },
_ => false _ => false
}; };
@ -1757,10 +1757,10 @@ ${helpers.predefined_type("transform-origin",
($ident:ident => $str:expr) => { ($ident:ident => $str:expr) => {
if self.contains($ident) { if self.contains($ident) {
if has_any { if has_any {
try!(dest.write_str(" ")); dest.write_str(" ")?;
} }
has_any = true; has_any = true;
try!(dest.write_str($str)); dest.write_str($str)?;
} }
} }
} }

View file

@ -71,18 +71,18 @@
match *self { match *self {
ContentItem::String(ref s) => s.to_css(dest), ContentItem::String(ref s) => s.to_css(dest),
ContentItem::Counter(ref s, ref counter_style) => { ContentItem::Counter(ref s, ref counter_style) => {
try!(dest.write_str("counter(")); dest.write_str("counter(")?;
try!(cssparser::serialize_identifier(&**s, dest)); cssparser::serialize_identifier(&**s, dest)?;
try!(dest.write_str(", ")); dest.write_str(", ")?;
try!(counter_style.to_css(dest)); counter_style.to_css(dest)?;
dest.write_str(")") dest.write_str(")")
} }
ContentItem::Counters(ref s, ref separator, ref counter_style) => { ContentItem::Counters(ref s, ref separator, ref counter_style) => {
try!(dest.write_str("counters(")); dest.write_str("counters(")?;
try!(cssparser::serialize_identifier(&**s, dest)); cssparser::serialize_identifier(&**s, dest)?;
try!(dest.write_str(", ")); dest.write_str(", ")?;
separator.to_css(dest)?; separator.to_css(dest)?;
try!(dest.write_str(", ")); dest.write_str(", ")?;
counter_style.to_css(dest)?; counter_style.to_css(dest)?;
dest.write_str(")") dest.write_str(")")
} }
@ -121,10 +121,10 @@
% endif % endif
T::Items(ref content) => { T::Items(ref content) => {
let mut iter = content.iter(); let mut iter = content.iter();
try!(iter.next().unwrap().to_css(dest)); iter.next().unwrap().to_css(dest)?;
for c in iter { for c in iter {
try!(dest.write_str(" ")); dest.write_str(" ")?;
try!(c.to_css(dest)); c.to_css(dest)?;
} }
Ok(()) Ok(())
} }
@ -186,14 +186,14 @@
Ok(Token::Function(name)) => { Ok(Token::Function(name)) => {
let result = match_ignore_ascii_case! { &name, let result = match_ignore_ascii_case! { &name,
"counter" => Some(input.parse_nested_block(|input| { "counter" => Some(input.parse_nested_block(|input| {
let name = try!(input.expect_ident()).into_owned(); let name = input.expect_ident()?.into_owned();
let style = parse_counter_style(context, input); let style = parse_counter_style(context, input);
Ok(ContentItem::Counter(name, style)) Ok(ContentItem::Counter(name, style))
})), })),
"counters" => Some(input.parse_nested_block(|input| { "counters" => Some(input.parse_nested_block(|input| {
let name = try!(input.expect_ident()).into_owned(); let name = input.expect_ident()?.into_owned();
try!(input.expect_comma()); input.expect_comma()?;
let separator = try!(input.expect_string()).into_owned(); let separator = input.expect_string()?.into_owned();
let style = parse_counter_style(context, input); let style = parse_counter_style(context, input);
Ok(ContentItem::Counters(name, separator, style)) Ok(ContentItem::Counters(name, separator, style))
})), })),
@ -205,7 +205,7 @@
_ => None _ => None
}; };
match result { match result {
Some(result) => content.push(try!(result)), Some(result) => content.push(result?),
None => return Err(StyleParseError::UnexpectedFunction(name).into()) None => return Err(StyleParseError::UnexpectedFunction(name).into())
} }
} }

View file

@ -159,14 +159,14 @@ ${helpers.predefined_type("clip",
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
let mut iter = self.filters.iter(); let mut iter = self.filters.iter();
if let Some(filter) = iter.next() { if let Some(filter) = iter.next() {
try!(filter.to_css(dest)); filter.to_css(dest)?;
} else { } else {
try!(dest.write_str("none")); dest.write_str("none")?;
return Ok(()) return Ok(())
} }
for filter in iter { for filter in iter {
try!(dest.write_str(" ")); dest.write_str(" ")?;
try!(filter.to_css(dest)); filter.to_css(dest)?;
} }
Ok(()) Ok(())
} }
@ -176,14 +176,14 @@ ${helpers.predefined_type("clip",
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
let mut iter = self.0.iter(); let mut iter = self.0.iter();
if let Some(filter) = iter.next() { if let Some(filter) = iter.next() {
try!(filter.to_css(dest)); filter.to_css(dest)?;
} else { } else {
try!(dest.write_str("none")); dest.write_str("none")?;
return Ok(()) return Ok(())
} }
for filter in iter { for filter in iter {
try!(dest.write_str(" ")); dest.write_str(" ")?;
try!(filter.to_css(dest)); filter.to_css(dest)?;
} }
Ok(()) Ok(())
} }
@ -193,22 +193,22 @@ ${helpers.predefined_type("clip",
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self { match *self {
computed_value::Filter::Blur(ref value) => { computed_value::Filter::Blur(ref value) => {
try!(dest.write_str("blur(")); dest.write_str("blur(")?;
try!(value.to_css(dest)); value.to_css(dest)?;
try!(dest.write_str(")")); dest.write_str(")")?;
} }
computed_value::Filter::Brightness(value) => try!(write!(dest, "brightness({})", value)), computed_value::Filter::Brightness(value) => write!(dest, "brightness({})", value)?,
computed_value::Filter::Contrast(value) => try!(write!(dest, "contrast({})", value)), computed_value::Filter::Contrast(value) => write!(dest, "contrast({})", value)?,
computed_value::Filter::Grayscale(value) => try!(write!(dest, "grayscale({})", value)), computed_value::Filter::Grayscale(value) => write!(dest, "grayscale({})", value)?,
computed_value::Filter::HueRotate(value) => { computed_value::Filter::HueRotate(value) => {
try!(dest.write_str("hue-rotate(")); dest.write_str("hue-rotate(")?;
try!(value.to_css(dest)); value.to_css(dest)?;
try!(dest.write_str(")")); dest.write_str(")")?;
} }
computed_value::Filter::Invert(value) => try!(write!(dest, "invert({})", value)), computed_value::Filter::Invert(value) => write!(dest, "invert({})", value)?,
computed_value::Filter::Opacity(value) => try!(write!(dest, "opacity({})", value)), computed_value::Filter::Opacity(value) => write!(dest, "opacity({})", value)?,
computed_value::Filter::Saturate(value) => try!(write!(dest, "saturate({})", value)), computed_value::Filter::Saturate(value) => write!(dest, "saturate({})", value)?,
computed_value::Filter::Sepia(value) => try!(write!(dest, "sepia({})", value)), computed_value::Filter::Sepia(value) => write!(dest, "sepia({})", value)?,
% if product == "gecko": % if product == "gecko":
computed_value::Filter::DropShadow(shadow) => { computed_value::Filter::DropShadow(shadow) => {
dest.write_str("drop-shadow(")?; dest.write_str("drop-shadow(")?;
@ -228,22 +228,22 @@ ${helpers.predefined_type("clip",
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self { match *self {
SpecifiedFilter::Blur(ref value) => { SpecifiedFilter::Blur(ref value) => {
try!(dest.write_str("blur(")); dest.write_str("blur(")?;
try!(value.to_css(dest)); value.to_css(dest)?;
try!(dest.write_str(")")); dest.write_str(")")?;
} }
SpecifiedFilter::Brightness(value) => try!(write!(dest, "brightness({})", value)), SpecifiedFilter::Brightness(value) => write!(dest, "brightness({})", value)?,
SpecifiedFilter::Contrast(value) => try!(write!(dest, "contrast({})", value)), SpecifiedFilter::Contrast(value) => write!(dest, "contrast({})", value)?,
SpecifiedFilter::Grayscale(value) => try!(write!(dest, "grayscale({})", value)), SpecifiedFilter::Grayscale(value) => write!(dest, "grayscale({})", value)?,
SpecifiedFilter::HueRotate(value) => { SpecifiedFilter::HueRotate(value) => {
try!(dest.write_str("hue-rotate(")); dest.write_str("hue-rotate(")?;
try!(value.to_css(dest)); value.to_css(dest)?;
try!(dest.write_str(")")); dest.write_str(")")?;
} }
SpecifiedFilter::Invert(value) => try!(write!(dest, "invert({})", value)), SpecifiedFilter::Invert(value) => write!(dest, "invert({})", value)?,
SpecifiedFilter::Opacity(value) => try!(write!(dest, "opacity({})", value)), SpecifiedFilter::Opacity(value) => write!(dest, "opacity({})", value)?,
SpecifiedFilter::Saturate(value) => try!(write!(dest, "saturate({})", value)), SpecifiedFilter::Saturate(value) => write!(dest, "saturate({})", value)?,
SpecifiedFilter::Sepia(value) => try!(write!(dest, "sepia({})", value)), SpecifiedFilter::Sepia(value) => write!(dest, "sepia({})", value)?,
% if product == "gecko": % if product == "gecko":
SpecifiedFilter::DropShadow(ref shadow) => { SpecifiedFilter::DropShadow(ref shadow) => {
dest.write_str("drop-shadow(")?; dest.write_str("drop-shadow(")?;
@ -277,7 +277,7 @@ ${helpers.predefined_type("clip",
} else } else
% endif % endif
if let Ok(function_name) = input.try(|input| input.expect_function()) { if let Ok(function_name) = input.try(|input| input.expect_function()) {
filters.push(try!(input.parse_nested_block(|input| { filters.push(input.parse_nested_block(|input| {
match_ignore_ascii_case! { &function_name, match_ignore_ascii_case! { &function_name,
"blur" => specified::Length::parse_non_negative(context, input).map(SpecifiedFilter::Blur), "blur" => specified::Length::parse_non_negative(context, input).map(SpecifiedFilter::Blur),
"brightness" => parse_factor(input).map(SpecifiedFilter::Brightness), "brightness" => parse_factor(input).map(SpecifiedFilter::Brightness),
@ -294,7 +294,7 @@ ${helpers.predefined_type("clip",
% endif % endif
_ => Err(StyleParseError::UnexpectedFunction(function_name.clone()).into()) _ => Err(StyleParseError::UnexpectedFunction(function_name.clone()).into())
} }
}))); })?);
} else if filters.is_empty() { } else if filters.is_empty() {
return Err(StyleParseError::UnspecifiedError.into()) return Err(StyleParseError::UnspecifiedError.into())
} else { } else {

View file

@ -160,7 +160,7 @@ macro_rules! impl_gecko_keyword_from_trait {
quoted: true, quoted: true,
})) }))
} }
let first_ident = try!(input.expect_ident()); let first_ident = input.expect_ident()?;
// FIXME(bholley): The fast thing to do here would be to look up the // FIXME(bholley): The fast thing to do here would be to look up the
// string (as lowercase) in the static atoms table. We don't have an // string (as lowercase) in the static atoms table. We don't have an
@ -271,10 +271,10 @@ macro_rules! impl_gecko_keyword_from_trait {
impl ToCss for T { impl ToCss for T {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
let mut iter = self.0.iter(); let mut iter = self.0.iter();
try!(iter.next().unwrap().to_css(dest)); iter.next().unwrap().to_css(dest)?;
for family in iter { for family in iter {
try!(dest.write_str(", ")); dest.write_str(", ")?;
try!(family.to_css(dest)); family.to_css(dest)?;
} }
Ok(()) Ok(())
} }
@ -1125,8 +1125,7 @@ ${helpers.single_keyword_system("font-variant-caps",
-> Result<Self, ()> { -> Result<Self, ()> {
match (*self, *other) { match (*self, *other) {
(T::Number(ref number), T::Number(ref other)) => (T::Number(ref number), T::Number(ref other)) =>
Ok(T::Number(try!(number.add_weighted(other, Ok(T::Number(number.add_weighted(other, self_portion, other_portion)?)),
self_portion, other_portion)))),
_ => Err(()), _ => Err(()),
} }
} }
@ -1161,7 +1160,7 @@ ${helpers.single_keyword_system("font-variant-caps",
return Ok(SpecifiedValue::None); return Ok(SpecifiedValue::None);
} }
Ok(SpecifiedValue::Number(try!(Number::parse_non_negative(context, input)))) Ok(SpecifiedValue::Number(Number::parse_non_negative(context, input)?))
} }
</%helpers:longhand> </%helpers:longhand>
@ -1327,10 +1326,10 @@ ${helpers.single_keyword_system("font-kerning",
($ident:ident => $str:expr) => { ($ident:ident => $str:expr) => {
if self.intersects($ident) { if self.intersects($ident) {
if has_any { if has_any {
try!(dest.write_str(" ")); dest.write_str(" ")?;
} }
has_any = true; has_any = true;
try!(dest.write_str($str)); dest.write_str($str)?;
} }
} }
} }
@ -1473,10 +1472,10 @@ macro_rules! exclusive_value {
($ident:ident => $str:expr) => { ($ident:ident => $str:expr) => {
if self.intersects($ident) { if self.intersects($ident) {
if has_any { if has_any {
try!(dest.write_str(" ")); dest.write_str(" ")?;
} }
has_any = true; has_any = true;
try!(dest.write_str($str)); dest.write_str($str)?;
} }
} }
} }
@ -1620,10 +1619,10 @@ macro_rules! exclusive_value {
($ident:ident => $str:expr) => { ($ident:ident => $str:expr) => {
if self.intersects($ident) { if self.intersects($ident) {
if has_any { if has_any {
try!(dest.write_str(" ")); dest.write_str(" ")?;
} }
has_any = true; has_any = true;
try!(dest.write_str($str)); dest.write_str($str)?;
} }
} }
} }
@ -1776,10 +1775,10 @@ macro_rules! exclusive_value {
($ident:ident => $str:expr) => { ($ident:ident => $str:expr) => {
if self.intersects($ident) { if self.intersects($ident) {
if has_any { if has_any {
try!(dest.write_str(" ")); dest.write_str(" ")?;
} }
has_any = true; has_any = true;
try!(dest.write_str($str)); dest.write_str($str)?;
} }
} }
} }

View file

@ -82,7 +82,7 @@ ${helpers.single_keyword("image-rendering",
impl ToCss for SpecifiedValue { impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
if let Some(angle) = self.angle { if let Some(angle) = self.angle {
try!(angle.to_css(dest)); angle.to_css(dest)?;
if self.flipped { if self.flipped {
dest.write_str(" flip") dest.write_str(" flip")
} else { } else {
@ -163,9 +163,9 @@ ${helpers.single_keyword("image-rendering",
match *self { match *self {
computed_value::T::FromImage => dest.write_str("from-image"), computed_value::T::FromImage => dest.write_str("from-image"),
computed_value::T::AngleWithFlipped(angle, flipped) => { computed_value::T::AngleWithFlipped(angle, flipped) => {
try!(angle.to_css(dest)); angle.to_css(dest)?;
if flipped { if flipped {
try!(dest.write_str(" flip")); dest.write_str(" flip")?;
} }
Ok(()) Ok(())
}, },

View file

@ -44,10 +44,10 @@ ${helpers.single_keyword("caption-side", "top bottom",
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64)
-> Result<Self, ()> { -> Result<Self, ()> {
Ok(T { Ok(T {
horizontal: try!(self.horizontal.add_weighted(&other.horizontal, horizontal: self.horizontal.add_weighted(&other.horizontal,
self_portion, other_portion)), self_portion, other_portion)?,
vertical: try!(self.vertical.add_weighted(&other.vertical, vertical: self.vertical.add_weighted(&other.vertical,
self_portion, other_portion)), self_portion, other_portion)?,
}) })
} }
@ -58,8 +58,8 @@ ${helpers.single_keyword("caption-side", "top bottom",
#[inline] #[inline]
fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> { fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> {
Ok(try!(self.horizontal.compute_squared_distance(&other.horizontal)) + Ok(self.horizontal.compute_squared_distance(&other.horizontal)? +
try!(self.vertical.compute_squared_distance(&other.vertical))) self.vertical.compute_squared_distance(&other.vertical)?)
} }
} }
} }
@ -83,9 +83,9 @@ ${helpers.single_keyword("caption-side", "top bottom",
fn to_css<W>(&self, dest: &mut W) -> fmt::Result fn to_css<W>(&self, dest: &mut W) -> fmt::Result
where W: fmt::Write, where W: fmt::Write,
{ {
try!(self.horizontal.to_css(dest)); self.horizontal.to_css(dest)?;
if let Some(vertical) = self.vertical.as_ref() { if let Some(vertical) = self.vertical.as_ref() {
try!(dest.write_str(" ")); dest.write_str(" ")?;
vertical.to_css(dest)?; vertical.to_css(dest)?;
} }
Ok(()) Ok(())

View file

@ -470,16 +470,16 @@ ${helpers.predefined_type("word-spacing",
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
if let Some(fill) = self.fill() { if let Some(fill) = self.fill() {
if fill { if fill {
try!(dest.write_str("filled")); dest.write_str("filled")?;
} else { } else {
try!(dest.write_str("open")); dest.write_str("open")?;
} }
} }
if let Some(shape) = self.shape() { if let Some(shape) = self.shape() {
if self.fill().is_some() { if self.fill().is_some() {
try!(dest.write_str(" ")); dest.write_str(" ")?;
} }
try!(shape.to_css(dest)); shape.to_css(dest)?;
} }
Ok(()) Ok(())
} }
@ -487,11 +487,11 @@ ${helpers.predefined_type("word-spacing",
impl ToCss for computed_value::KeywordValue { impl ToCss for computed_value::KeywordValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
if self.fill { if self.fill {
try!(dest.write_str("filled")); dest.write_str("filled")?;
} else { } else {
try!(dest.write_str("open")); dest.write_str("open")?;
} }
try!(dest.write_str(" ")); dest.write_str(" ")?;
self.shape.to_css(dest) self.shape.to_css(dest)
} }
} }
@ -643,11 +643,11 @@ ${helpers.predefined_type("word-spacing",
pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<SpecifiedValue, ParseError<'i>> { -> Result<SpecifiedValue, ParseError<'i>> {
if let Ok(horizontal) = input.try(|input| HorizontalWritingModeValue::parse(input)) { if let Ok(horizontal) = input.try(|input| HorizontalWritingModeValue::parse(input)) {
let vertical = try!(VerticalWritingModeValue::parse(input)); let vertical = VerticalWritingModeValue::parse(input)?;
Ok(SpecifiedValue(horizontal, vertical)) Ok(SpecifiedValue(horizontal, vertical))
} else { } else {
let vertical = try!(VerticalWritingModeValue::parse(input)); let vertical = VerticalWritingModeValue::parse(input)?;
let horizontal = try!(HorizontalWritingModeValue::parse(input)); let horizontal = HorizontalWritingModeValue::parse(input)?;
Ok(SpecifiedValue(horizontal, vertical)) Ok(SpecifiedValue(horizontal, vertical))
} }
} }

View file

@ -52,12 +52,12 @@
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
impl ToCss for Image { impl ToCss for Image {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
try!(self.url.to_css(dest)); self.url.to_css(dest)?;
if let Some((x, y)) = self.hotspot { if let Some((x, y)) = self.hotspot {
try!(dest.write_str(" ")); dest.write_str(" ")?;
try!(x.to_css(dest)); x.to_css(dest)?;
try!(dest.write_str(" ")); dest.write_str(" ")?;
try!(y.to_css(dest)); y.to_css(dest)?;
} }
Ok(()) Ok(())
} }
@ -67,8 +67,8 @@
impl ToCss for T { impl ToCss for T {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
for url in &self.images { for url in &self.images {
try!(url.to_css(dest)); url.to_css(dest)?;
try!(dest.write_str(", ")); dest.write_str(", ")?;
} }
self.keyword.to_css(dest) self.keyword.to_css(dest)
} }
@ -95,7 +95,7 @@
-> Result<computed_value::Keyword, ParseError<'i>> { -> Result<computed_value::Keyword, ParseError<'i>> {
use std::ascii::AsciiExt; use std::ascii::AsciiExt;
use style_traits::cursor::Cursor; use style_traits::cursor::Cursor;
let ident = try!(input.expect_ident()); let ident = input.expect_ident()?;
if ident.eq_ignore_ascii_case("auto") { if ident.eq_ignore_ascii_case("auto") {
Ok(computed_value::Keyword::Auto) Ok(computed_value::Keyword::Auto)
} else { } else {
@ -110,9 +110,9 @@
fn parse_image<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) fn parse_image<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<computed_value::Image, ParseError<'i>> { -> Result<computed_value::Image, ParseError<'i>> {
Ok(computed_value::Image { Ok(computed_value::Image {
url: try!(SpecifiedUrl::parse(context, input)), url: SpecifiedUrl::parse(context, input)?,
hotspot: match input.try(|input| input.expect_number()) { hotspot: match input.try(|input| input.expect_number()) {
Ok(number) => Some((number, try!(input.expect_number()))), Ok(number) => Some((number, input.expect_number()?)),
Err(_) => None, Err(_) => None,
}, },
}) })
@ -137,12 +137,12 @@
} }
Err(_) => break, Err(_) => break,
} }
try!(input.expect_comma()); input.expect_comma()?;
} }
Ok(computed_value::T { Ok(computed_value::T {
images: images, images: images,
keyword: try!(computed_value::Keyword::parse(context, input)), keyword: computed_value::Keyword::parse(context, input)?,
}) })
} }
</%helpers:longhand> </%helpers:longhand>

View file

@ -57,11 +57,11 @@
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
if self.sides_are_logical { if self.sides_are_logical {
assert!(self.first == Side::Clip); assert!(self.first == Side::Clip);
try!(self.second.to_css(dest)); self.second.to_css(dest)?;
} else { } else {
try!(self.first.to_css(dest)); self.first.to_css(dest)?;
try!(dest.write_str(" ")); dest.write_str(" ")?;
try!(self.second.to_css(dest)); self.second.to_css(dest)?;
} }
Ok(()) Ok(())
} }
@ -133,10 +133,10 @@
impl ToCss for SpecifiedValue { impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
try!(self.first.to_css(dest)); self.first.to_css(dest)?;
if let Some(ref second) = self.second { if let Some(ref second) = self.second {
try!(dest.write_str(" ")); dest.write_str(" ")?;
try!(second.to_css(dest)); second.to_css(dest)?;
} }
Ok(()) Ok(())
} }

View file

@ -78,7 +78,7 @@ ${helpers.single_keyword("-moz-window-shadow", "none default menu tooltip sheet"
pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<SpecifiedValue, ParseError<'i>> { -> Result<SpecifiedValue, ParseError<'i>> {
match try!(input.expect_integer()) { match input.expect_integer()? {
0 => Ok(computed_value::T(false)), 0 => Ok(computed_value::T(false)),
1 => Ok(computed_value::T(true)), 1 => Ok(computed_value::T(true)),
_ => Err(StyleParseError::UnspecifiedError.into()), _ => Err(StyleParseError::UnspecifiedError.into()),

View file

@ -234,8 +234,8 @@ pub mod shorthands {
while let Ok(_) = input.next() {} // Look for var() while let Ok(_) = input.next() {} // Look for var()
if input.seen_var_functions() { if input.seen_var_functions() {
input.reset(start); input.reset(start);
let (first_token_type, css) = try!( let (first_token_type, css) =
::custom_properties::parse_non_custom_with_var(input)); ::custom_properties::parse_non_custom_with_var(input)?;
declarations.all_shorthand = AllShorthand::WithVariables(Arc::new(UnparsedValue { declarations.all_shorthand = AllShorthand::WithVariables(Arc::new(UnparsedValue {
css: css.into_owned(), css: css.into_owned(),
first_token_type: first_token_type, first_token_type: first_token_type,
@ -1137,8 +1137,8 @@ impl HasViewportPercentage for PropertyDeclaration {
impl fmt::Debug for PropertyDeclaration { impl fmt::Debug for PropertyDeclaration {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(self.id().to_css(f)); self.id().to_css(f)?;
try!(f.write_str(": ")); f.write_str(": ")?;
self.to_css(f) self.to_css(f)
} }
} }

View file

@ -39,7 +39,7 @@
% for name in "image position_x position_y repeat size attachment origin clip".split(): % for name in "image position_x position_y repeat size attachment origin clip".split():
let mut background_${name} = background_${name}::SpecifiedValue(Vec::new()); let mut background_${name} = background_${name}::SpecifiedValue(Vec::new());
% endfor % endfor
try!(input.parse_comma_separated(|input| { input.parse_comma_separated(|input| {
// background-color can only be in the last element, so if it // background-color can only be in the last element, so if it
// is parsed anywhere before, the value is invalid. // is parsed anywhere before, the value is invalid.
if background_color.is_some() { if background_color.is_some() {
@ -62,7 +62,7 @@
// Parse background size, if applicable. // Parse background size, if applicable.
size = input.try(|input| { size = input.try(|input| {
try!(input.expect_delim('/')); input.expect_delim('/')?;
background_size::single_value::parse(context, input) background_size::single_value::parse(context, input)
}).ok(); }).ok();
@ -110,7 +110,7 @@
} else { } else {
Err(StyleParseError::UnspecifiedError.into()) Err(StyleParseError::UnspecifiedError.into())
} }
})); })?;
Ok(expanded! { Ok(expanded! {
background_color: background_color.unwrap_or(Color::transparent()), background_color: background_color.unwrap_or(Color::transparent()),
@ -148,37 +148,37 @@
% endfor % endfor
if i != 0 { if i != 0 {
try!(write!(dest, ", ")); write!(dest, ", ")?;
} }
if i == len - 1 { if i == len - 1 {
try!(self.background_color.to_css(dest)); self.background_color.to_css(dest)?;
try!(write!(dest, " ")); write!(dest, " ")?;
} }
try!(image.to_css(dest)); image.to_css(dest)?;
% for name in "repeat attachment".split(): % for name in "repeat attachment".split():
try!(write!(dest, " ")); write!(dest, " ")?;
try!(${name}.to_css(dest)); ${name}.to_css(dest)?;
% endfor % endfor
try!(write!(dest, " ")); write!(dest, " ")?;
Position { Position {
horizontal: position_x.clone(), horizontal: position_x.clone(),
vertical: position_y.clone() vertical: position_y.clone()
}.to_css(dest)?; }.to_css(dest)?;
if *size != background_size::single_value::get_initial_specified_value() { if *size != background_size::single_value::get_initial_specified_value() {
try!(write!(dest, " / ")); write!(dest, " / ")?;
try!(size.to_css(dest)); size.to_css(dest)?;
} }
if *origin != Origin::padding_box || *clip != Clip::border_box { if *origin != Origin::padding_box || *clip != Clip::border_box {
try!(write!(dest, " ")); write!(dest, " ")?;
try!(origin.to_css(dest)); origin.to_css(dest)?;
if *clip != From::from(*origin) { if *clip != From::from(*origin) {
try!(write!(dest, " ")); write!(dest, " ")?;
try!(clip.to_css(dest)); clip.to_css(dest)?;
} }
} }
} }

View file

@ -104,7 +104,7 @@ pub fn parse_border<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Longhands, ParseError<'i>> { -> Result<Longhands, ParseError<'i>> {
let (color, style, width) = try!(super::parse_border(context, input)); let (color, style, width) = super::parse_border(context, input)?;
Ok(expanded! { Ok(expanded! {
border_${to_rust_ident(side)}_color: color, border_${to_rust_ident(side)}_color: color,
border_${to_rust_ident(side)}_style: style, border_${to_rust_ident(side)}_style: style,
@ -146,7 +146,7 @@ pub fn parse_border<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
use properties::longhands::{border_image_outset, border_image_repeat, border_image_slice}; use properties::longhands::{border_image_outset, border_image_repeat, border_image_slice};
use properties::longhands::{border_image_source, border_image_width}; use properties::longhands::{border_image_source, border_image_width};
let (color, style, width) = try!(super::parse_border(context, input)); let (color, style, width) = super::parse_border(context, input)?;
Ok(expanded! { Ok(expanded! {
% for side in PHYSICAL_SIDES: % for side in PHYSICAL_SIDES:
border_${side}_color: color.clone(), border_${side}_color: color.clone(),
@ -214,7 +214,7 @@ pub fn parse_border<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Longhands, ParseError<'i>> { -> Result<Longhands, ParseError<'i>> {
let radii = try!(BorderRadius::parse(context, input)); let radii = BorderRadius::parse(context, input)?;
Ok(expanded! { Ok(expanded! {
border_top_left_radius: radii.top_left, border_top_left_radius: radii.top_left,
border_top_right_radius: radii.top_right, border_top_right_radius: radii.top_right,
@ -262,7 +262,7 @@ pub fn parse_border<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
slice = Some(value); slice = Some(value);
// Parse border image width and outset, if applicable. // Parse border image width and outset, if applicable.
let maybe_width_outset: Result<_, ParseError> = input.try(|input| { let maybe_width_outset: Result<_, ParseError> = input.try(|input| {
try!(input.expect_delim('/')); input.expect_delim('/')?;
// Parse border image width, if applicable. // Parse border image width, if applicable.
let w = input.try(|input| let w = input.try(|input|
@ -270,7 +270,7 @@ pub fn parse_border<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
// Parse border image outset if applicable. // Parse border image outset if applicable.
let o = input.try(|input| { let o = input.try(|input| {
try!(input.expect_delim('/')); input.expect_delim('/')?;
border_image_outset::parse(context, input) border_image_outset::parse(context, input)
}).ok(); }).ok();
if w.is_none() && o.is_none() { if w.is_none() && o.is_none() {
@ -313,7 +313,7 @@ pub fn parse_border<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
Err(StyleParseError::UnspecifiedError.into()) Err(StyleParseError::UnspecifiedError.into())
} }
}); });
try!(result); result?;
Ok(expanded! { Ok(expanded! {
% for name in "outset repeat slice source width".split(): % for name in "outset repeat slice source width".split():

View file

@ -135,7 +135,7 @@ macro_rules! try_parse_one {
% endfor % endfor
if input.try(|input| input.expect_ident_matching("none")).is_err() { if input.try(|input| input.expect_ident_matching("none")).is_err() {
let results = try!(input.parse_comma_separated(|i| parse_one_transition(context, i))); let results = input.parse_comma_separated(|i| parse_one_transition(context, i))?;
for result in results { for result in results {
% for prop in "property duration timing_function delay".split(): % for prop in "property duration timing_function delay".split():
${prop}s.push(result.transition_${prop}); ${prop}s.push(result.transition_${prop});
@ -257,7 +257,7 @@ macro_rules! try_parse_one {
let mut ${prop}s = vec![]; let mut ${prop}s = vec![];
% endfor % endfor
let results = try!(input.parse_comma_separated(|i| parse_one_animation(context, i))); let results = input.parse_comma_separated(|i| parse_one_animation(context, i))?;
for result in results.into_iter() { for result in results.into_iter() {
% for prop in props: % for prop in props:
${prop}s.push(result.animation_${prop}); ${prop}s.push(result.animation_${prop});
@ -289,7 +289,7 @@ macro_rules! try_parse_one {
for i in 0..len { for i in 0..len {
if i != 0 { if i != 0 {
try!(write!(dest, ", ")); write!(dest, ", ")?;
} }
% for name in props[1:]: % for name in props[1:]:
@ -310,7 +310,7 @@ macro_rules! try_parse_one {
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Longhands, ParseError<'i>> { -> Result<Longhands, ParseError<'i>> {
let result = try!(scroll_snap_type_x::parse(context, input)); let result = scroll_snap_type_x::parse(context, input)?;
Ok(expanded! { Ok(expanded! {
scroll_snap_type_x: result, scroll_snap_type_x: result,
scroll_snap_type_y: result, scroll_snap_type_y: result,

View file

@ -89,7 +89,7 @@
continue continue
} }
} }
size = Some(try!(font_size::parse(context, input))); size = Some(font_size::parse(context, input)?);
break break
} }
#[inline] #[inline]
@ -101,7 +101,7 @@
return Err(StyleParseError::UnspecifiedError.into()) return Err(StyleParseError::UnspecifiedError.into())
} }
let line_height = if input.try(|input| input.expect_delim('/')).is_ok() { let line_height = if input.try(|input| input.expect_delim('/')).is_ok() {
Some(try!(LineHeight::parse(context, input))) Some(LineHeight::parse(context, input)?)
} else { } else {
None None
}; };

View file

@ -41,7 +41,7 @@
let mut mask_${name} = mask_${name}::SpecifiedValue(Vec::new()); let mut mask_${name} = mask_${name}::SpecifiedValue(Vec::new());
% endfor % endfor
try!(input.parse_comma_separated(|input| { input.parse_comma_separated(|input| {
% for name in "image mode position size repeat origin clip composite".split(): % for name in "image mode position size repeat origin clip composite".split():
let mut ${name} = None; let mut ${name} = None;
% endfor % endfor
@ -59,7 +59,7 @@
// Parse mask size, if applicable. // Parse mask size, if applicable.
size = input.try(|input| { size = input.try(|input| {
try!(input.expect_delim('/')); input.expect_delim('/')?;
mask_size::single_value::parse(context, input) mask_size::single_value::parse(context, input)
}).ok(); }).ok();
@ -106,7 +106,7 @@
} else { } else {
Err(StyleParseError::UnspecifiedError.into()) Err(StyleParseError::UnspecifiedError.into())
} }
})); })?;
Ok(expanded! { Ok(expanded! {
% for name in "image mode position_x position_y size repeat origin clip composite".split(): % for name in "image mode position_x position_y size repeat origin clip composite".split():

View file

@ -66,7 +66,7 @@
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Longhands, ParseError<'i>> { -> Result<Longhands, ParseError<'i>> {
let radii = try!(BorderRadius::parse(context, input)); let radii = BorderRadius::parse(context, input)?;
Ok(expanded! { Ok(expanded! {
_moz_outline_radius_topleft: radii.top_left, _moz_outline_radius_topleft: radii.top_left,
_moz_outline_radius_topright: radii.top_right, _moz_outline_radius_topright: radii.top_right,

View file

@ -50,7 +50,7 @@
fn parse_flexibility<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) fn parse_flexibility<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<(Number, Option<Number>),ParseError<'i>> { -> Result<(Number, Option<Number>),ParseError<'i>> {
let grow = try!(Number::parse_non_negative(context, input)); let grow = Number::parse_non_negative(context, input)?;
let shrink = input.try(|i| Number::parse_non_negative(context, i)).ok(); let shrink = input.try(|i| Number::parse_non_negative(context, i)).ok();
Ok((grow, shrink)) Ok((grow, shrink))
} }

View file

@ -154,20 +154,20 @@ impl Expression {
/// Only supports width and width ranges for now. /// Only supports width and width ranges for now.
pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Self, ParseError<'i>> { -> Result<Self, ParseError<'i>> {
try!(input.expect_parenthesis_block()); input.expect_parenthesis_block()?;
input.parse_nested_block(|input| { input.parse_nested_block(|input| {
let name = try!(input.expect_ident()); let name = input.expect_ident()?;
try!(input.expect_colon()); input.expect_colon()?;
// TODO: Handle other media features // TODO: Handle other media features
Ok(Expression(match_ignore_ascii_case! { &name, Ok(Expression(match_ignore_ascii_case! { &name,
"min-width" => { "min-width" => {
ExpressionKind::Width(Range::Min(try!(specified::Length::parse_non_negative(context, input)))) ExpressionKind::Width(Range::Min(specified::Length::parse_non_negative(context, input)?))
}, },
"max-width" => { "max-width" => {
ExpressionKind::Width(Range::Max(try!(specified::Length::parse_non_negative(context, input)))) ExpressionKind::Width(Range::Max(specified::Length::parse_non_negative(context, input)?))
}, },
"width" => { "width" => {
ExpressionKind::Width(Range::Eq(try!(specified::Length::parse_non_negative(context, input)))) ExpressionKind::Width(Range::Eq(specified::Length::parse_non_negative(context, input)?))
}, },
_ => return Err(SelectorParseError::UnexpectedIdent(name.clone()).into()) _ => return Err(SelectorParseError::UnexpectedIdent(name.clone()).into())
})) }))
@ -195,14 +195,14 @@ impl ToCss for Expression {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result fn to_css<W>(&self, dest: &mut W) -> fmt::Result
where W: fmt::Write, where W: fmt::Write,
{ {
try!(write!(dest, "(")); write!(dest, "(")?;
let (mm, l) = match self.0 { let (mm, l) = match self.0 {
ExpressionKind::Width(Range::Min(ref l)) => ("min-", l), ExpressionKind::Width(Range::Min(ref l)) => ("min-", l),
ExpressionKind::Width(Range::Max(ref l)) => ("max-", l), ExpressionKind::Width(Range::Max(ref l)) => ("max-", l),
ExpressionKind::Width(Range::Eq(ref l)) => ("", l), ExpressionKind::Width(Range::Eq(ref l)) => ("", l),
}; };
try!(write!(dest, "{}width: ", mm)); write!(dest, "{}width: ", mm)?;
try!(l.to_css(dest)); l.to_css(dest)?;
write!(dest, ")") write!(dest, ")")
} }
} }

View file

@ -162,14 +162,14 @@ impl fmt::Display for ServoRestyleDamage {
for &(damage, damage_str) in &to_iter { for &(damage, damage_str) in &to_iter {
if self.contains(damage) { if self.contains(damage) {
if !first_elem { try!(write!(f, " | ")); } if !first_elem { write!(f, " | ")?; }
try!(write!(f, "{}", damage_str)); write!(f, "{}", damage_str)?;
first_elem = false; first_elem = false;
} }
} }
if first_elem { if first_elem {
try!(write!(f, "NoDamage")); write!(f, "NoDamage")?;
} }
Ok(()) Ok(())

View file

@ -30,12 +30,12 @@ pub struct DocumentRule {
impl ToCssWithGuard for DocumentRule { impl ToCssWithGuard for DocumentRule {
fn to_css<W>(&self, guard: &SharedRwLockReadGuard, dest: &mut W) -> fmt::Result fn to_css<W>(&self, guard: &SharedRwLockReadGuard, dest: &mut W) -> fmt::Result
where W: fmt::Write { where W: fmt::Write {
try!(dest.write_str("@-moz-document ")); dest.write_str("@-moz-document ")?;
try!(self.condition.to_css(dest)); self.condition.to_css(dest)?;
try!(dest.write_str(" {")); dest.write_str(" {")?;
for rule in self.rules.read_with(guard).0.iter() { for rule in self.rules.read_with(guard).0.iter() {
try!(dest.write_str(" ")); dest.write_str(" ")?;
try!(rule.to_css(guard, dest)); rule.to_css(guard, dest)?;
} }
dest.write_str(" }") dest.write_str(" }")
} }

View file

@ -128,7 +128,7 @@ impl KeyframePercentage {
} else if input.try(|input| input.expect_ident_matching("to")).is_ok() { } else if input.try(|input| input.expect_ident_matching("to")).is_ok() {
KeyframePercentage::new(1.) KeyframePercentage::new(1.)
} else { } else {
let percentage = try!(input.expect_percentage()); let percentage = input.expect_percentage()?;
if percentage >= 0. && percentage <= 1. { if percentage >= 0. && percentage <= 1. {
KeyframePercentage::new(percentage) KeyframePercentage::new(percentage)
} else { } else {
@ -193,9 +193,9 @@ impl ToCssWithGuard for Keyframe {
fn to_css<W>(&self, guard: &SharedRwLockReadGuard, dest: &mut W) -> fmt::Result fn to_css<W>(&self, guard: &SharedRwLockReadGuard, dest: &mut W) -> fmt::Result
where W: fmt::Write { where W: fmt::Write {
self.selector.to_css(dest)?; self.selector.to_css(dest)?;
try!(dest.write_str(" { ")); dest.write_str(" { ")?;
try!(self.block.read_with(guard).to_css(dest)); self.block.read_with(guard).to_css(dest)?;
try!(dest.write_str(" }")); dest.write_str(" }")?;
Ok(()) Ok(())
} }
} }
@ -524,7 +524,7 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for KeyframeDeclarationParser<'a, 'b> {
fn parse_value<'t>(&mut self, name: CompactCowStr<'i>, input: &mut Parser<'i, 't>) fn parse_value<'t>(&mut self, name: CompactCowStr<'i>, input: &mut Parser<'i, 't>)
-> Result<(), ParseError<'i>> { -> Result<(), ParseError<'i>> {
let id = try!(PropertyId::parse(name.into())); let id = PropertyId::parse(name.into())?;
match PropertyDeclaration::parse_into(self.declarations, id, self.context, input) { match PropertyDeclaration::parse_into(self.declarations, id, self.context, input) {
Ok(()) => { Ok(()) => {
// In case there is still unparsed text in the declaration, we should roll back. // In case there is still unparsed text in the declaration, we should roll back.

View file

@ -452,7 +452,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
AtRulePrelude::Viewport => { AtRulePrelude::Viewport => {
let context = ParserContext::new_with_rule_type(self.context, Some(CssRuleType::Viewport)); let context = ParserContext::new_with_rule_type(self.context, Some(CssRuleType::Viewport));
Ok(CssRule::Viewport(Arc::new(self.shared_lock.wrap( Ok(CssRule::Viewport(Arc::new(self.shared_lock.wrap(
try!(ViewportRule::parse(&context, input)))))) ViewportRule::parse(&context, input)?))))
} }
AtRulePrelude::Keyframes(name, prefix, location) => { AtRulePrelude::Keyframes(name, prefix, location) => {
let context = ParserContext::new_with_rule_type(self.context, Some(CssRuleType::Keyframes)); let context = ParserContext::new_with_rule_type(self.context, Some(CssRuleType::Keyframes));

View file

@ -103,9 +103,9 @@ macro_rules! declare_viewport_descriptor_inner {
match *self { match *self {
$( $(
ViewportDescriptor::$assigned_variant(ref val) => { ViewportDescriptor::$assigned_variant(ref val) => {
try!(dest.write_str($assigned_variant_name)); dest.write_str($assigned_variant_name)?;
try!(dest.write_str(": ")); dest.write_str(": ")?;
try!(val.to_css(dest)); val.to_css(dest)?;
}, },
)* )*
} }
@ -254,9 +254,9 @@ impl ViewportDescriptorDeclaration {
impl ToCss for ViewportDescriptorDeclaration { impl ToCss for ViewportDescriptorDeclaration {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
try!(self.descriptor.to_css(dest)); self.descriptor.to_css(dest)?;
if self.important { if self.important {
try!(dest.write_str(" !important")); dest.write_str(" !important")?;
} }
dest.write_str(";") dest.write_str(";")
} }
@ -264,7 +264,7 @@ impl ToCss for ViewportDescriptorDeclaration {
fn parse_shorthand<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) fn parse_shorthand<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<(ViewportLength, ViewportLength), ParseError<'i>> { -> Result<(ViewportLength, ViewportLength), ParseError<'i>> {
let min = try!(ViewportLength::parse(context, input)); let min = ViewportLength::parse(context, input)?;
match input.try(|i| ViewportLength::parse(context, i)) { match input.try(|i| ViewportLength::parse(context, i)) {
Err(_) => Ok((min.clone(), min)), Err(_) => Ok((min.clone(), min)),
Ok(max) => Ok((min, max)) Ok(max) => Ok((min, max))
@ -301,7 +301,7 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for ViewportRuleParser<'a, 'b> {
Ok(vec![declaration!($declaration($parse))]) Ok(vec![declaration!($declaration($parse))])
}; };
(shorthand -> [$min:ident, $max:ident]) => {{ (shorthand -> [$min:ident, $max:ident]) => {{
let shorthand = try!(parse_shorthand(self.context, input)); let shorthand = parse_shorthand(self.context, input)?;
let important = input.try(parse_important).is_ok(); let important = input.try(parse_important).is_ok();
Ok(vec![declaration!($min(value: shorthand.0, important: important)), Ok(vec![declaration!($min(value: shorthand.0, important: important)),
@ -515,12 +515,12 @@ impl ToCssWithGuard for ViewportRule {
// Serialization of ViewportRule is not specced. // Serialization of ViewportRule is not specced.
fn to_css<W>(&self, _guard: &SharedRwLockReadGuard, dest: &mut W) -> fmt::Result fn to_css<W>(&self, _guard: &SharedRwLockReadGuard, dest: &mut W) -> fmt::Result
where W: fmt::Write { where W: fmt::Write {
try!(dest.write_str("@viewport { ")); dest.write_str("@viewport { ")?;
let mut iter = self.declarations.iter(); let mut iter = self.declarations.iter();
try!(iter.next().unwrap().to_css(dest)); iter.next().unwrap().to_css(dest)?;
for declaration in iter { for declaration in iter {
try!(dest.write_str(" ")); dest.write_str(" ")?;
try!(declaration.to_css(dest)); declaration.to_css(dest)?;
} }
dest.write_str(" }") dest.write_str(" }")
} }

View file

@ -521,32 +521,32 @@ pub struct ClipRect {
impl ToCss for ClipRect { impl ToCss for ClipRect {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
try!(dest.write_str("rect(")); dest.write_str("rect(")?;
if let Some(top) = self.top { if let Some(top) = self.top {
try!(top.to_css(dest)); top.to_css(dest)?;
try!(dest.write_str(", ")); dest.write_str(", ")?;
} else { } else {
try!(dest.write_str("auto, ")); dest.write_str("auto, ")?;
} }
if let Some(right) = self.right { if let Some(right) = self.right {
try!(right.to_css(dest)); right.to_css(dest)?;
try!(dest.write_str(", ")); dest.write_str(", ")?;
} else { } else {
try!(dest.write_str("auto, ")); dest.write_str("auto, ")?;
} }
if let Some(bottom) = self.bottom { if let Some(bottom) = self.bottom {
try!(bottom.to_css(dest)); bottom.to_css(dest)?;
try!(dest.write_str(", ")); dest.write_str(", ")?;
} else { } else {
try!(dest.write_str("auto, ")); dest.write_str("auto, ")?;
} }
if let Some(left) = self.left { if let Some(left) = self.left {
try!(left.to_css(dest)); left.to_css(dest)?;
} else { } else {
try!(dest.write_str("auto")); dest.write_str("auto")?;
} }
dest.write_str(")") dest.write_str(")")
} }

View file

@ -148,7 +148,7 @@ impl<T: Parse> Parse for FontSettingTag<T> {
use byteorder::{ReadBytesExt, BigEndian}; use byteorder::{ReadBytesExt, BigEndian};
use std::io::Cursor; use std::io::Cursor;
let tag = try!(input.expect_string()); let tag = input.expect_string()?;
// allowed strings of length 4 containing chars: <U+20, U+7E> // allowed strings of length 4 containing chars: <U+20, U+7E>
if tag.len() != 4 || if tag.len() != 4 ||

View file

@ -94,7 +94,7 @@ impl ToCss for CalcLengthOrPercentage {
macro_rules! first_value_check { macro_rules! first_value_check {
() => { () => {
if !first_value { if !first_value {
try!(dest.write_str(" + ")); dest.write_str(" + ")?;
} else { } else {
first_value = false; first_value = false;
} }
@ -106,14 +106,14 @@ impl ToCss for CalcLengthOrPercentage {
$( $(
if let Some(val) = self.$val { if let Some(val) = self.$val {
first_value_check!(); first_value_check!();
try!(val.to_css(dest)); val.to_css(dest)?;
try!(dest.write_str(stringify!($val))); dest.write_str(stringify!($val))?;
} }
)* )*
}; };
} }
try!(dest.write_str("calc(")); dest.write_str("calc(")?;
serialize!(ch, em, ex, rem, vh, vmax, vmin, vw); serialize!(ch, em, ex, rem, vh, vmax, vmin, vw);
@ -124,7 +124,7 @@ impl ToCss for CalcLengthOrPercentage {
if let Some(val) = self.absolute { if let Some(val) = self.absolute {
first_value_check!(); first_value_check!();
try!(val.to_css(dest)); val.to_css(dest)?;
} }
if let Some(val) = self.percentage { if let Some(val) = self.percentage {
@ -149,7 +149,7 @@ impl CalcNode {
expected_unit: CalcUnit) expected_unit: CalcUnit)
-> Result<Self, ParseError<'i>> -> Result<Self, ParseError<'i>>
{ {
match (try!(input.next()), expected_unit) { match (input.next()?, expected_unit) {
(Token::Number { value, .. }, _) => Ok(CalcNode::Number(value)), (Token::Number { value, .. }, _) => Ok(CalcNode::Number(value)),
(Token::Dimension { value, ref unit, .. }, CalcUnit::Length) | (Token::Dimension { value, ref unit, .. }, CalcUnit::Length) |
(Token::Dimension { value, ref unit, .. }, CalcUnit::LengthOrPercentage) => { (Token::Dimension { value, ref unit, .. }, CalcUnit::LengthOrPercentage) => {

View file

@ -152,7 +152,7 @@ impl Parse for Gradient {
Radial, Radial,
} }
let func = try!(input.expect_function()); let func = input.expect_function()?;
let result = match_ignore_ascii_case! { &func, let result = match_ignore_ascii_case! { &func,
"linear-gradient" => { "linear-gradient" => {
Some((Shape::Linear, false, CompatMode::Modern)) Some((Shape::Linear, false, CompatMode::Modern))
@ -655,7 +655,7 @@ impl ShapeExtent {
fn parse_with_compat_mode<'i, 't>(input: &mut Parser<'i, 't>, fn parse_with_compat_mode<'i, 't>(input: &mut Parser<'i, 't>,
compat_mode: CompatMode) compat_mode: CompatMode)
-> Result<Self, ParseError<'i>> { -> Result<Self, ParseError<'i>> {
match try!(Self::parse(input)) { match Self::parse(input)? {
ShapeExtent::Contain | ShapeExtent::Cover if compat_mode == CompatMode::Modern => ShapeExtent::Contain | ShapeExtent::Cover if compat_mode == CompatMode::Modern =>
Err(StyleParseError::UnspecifiedError.into()), Err(StyleParseError::UnspecifiedError.into()),
keyword => Ok(keyword), keyword => Ok(keyword),
@ -667,7 +667,7 @@ impl GradientItem {
fn parse_comma_separated<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) fn parse_comma_separated<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Vec<Self>, ParseError<'i>> { -> Result<Vec<Self>, ParseError<'i>> {
let mut seen_stop = false; let mut seen_stop = false;
let items = try!(input.parse_comma_separated(|input| { let items = input.parse_comma_separated(|input| {
if seen_stop { if seen_stop {
if let Ok(hint) = input.try(|i| LengthOrPercentage::parse(context, i)) { if let Ok(hint) = input.try(|i| LengthOrPercentage::parse(context, i)) {
seen_stop = false; seen_stop = false;
@ -676,7 +676,7 @@ impl GradientItem {
} }
seen_stop = true; seen_stop = true;
ColorStop::parse(context, input).map(GenericGradientItem::ColorStop) ColorStop::parse(context, input).map(GenericGradientItem::ColorStop)
})); })?;
if !seen_stop || items.len() < 2 { if !seen_stop || items.len() < 2 {
return Err(StyleParseError::UnspecifiedError.into()); return Err(StyleParseError::UnspecifiedError.into());
} }
@ -688,7 +688,7 @@ impl Parse for ColorStop {
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Self, ParseError<'i>> { -> Result<Self, ParseError<'i>> {
Ok(ColorStop { Ok(ColorStop {
color: try!(RGBAColor::parse(context, input)), color: RGBAColor::parse(context, input)?,
position: input.try(|i| LengthOrPercentage::parse(context, i)).ok(), position: input.try(|i| LengthOrPercentage::parse(context, i)).ok(),
}) })
} }

View file

@ -609,7 +609,7 @@ impl Length {
num_context: AllowedLengthType, num_context: AllowedLengthType,
allow_quirks: AllowQuirks) allow_quirks: AllowQuirks)
-> Result<Length, ParseError<'i>> { -> Result<Length, ParseError<'i>> {
let token = try!(input.next()); let token = input.next()?;
match token { match token {
Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => { Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => {
Length::parse_dimension(context, value, unit) Length::parse_dimension(context, value, unit)
@ -721,7 +721,7 @@ impl Percentage {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
num_context: AllowedNumericType) num_context: AllowedNumericType)
-> Result<Self, ParseError<'i>> { -> Result<Self, ParseError<'i>> {
match try!(input.next()) { match input.next()? {
Token::Percentage { unit_value, .. } if num_context.is_ok(context.parsing_mode, unit_value) => { Token::Percentage { unit_value, .. } if num_context.is_ok(context.parsing_mode, unit_value) => {
Ok(Percentage(unit_value)) Ok(Percentage(unit_value))
} }
@ -804,7 +804,7 @@ impl LengthOrPercentage {
allow_quirks: AllowQuirks) allow_quirks: AllowQuirks)
-> Result<LengthOrPercentage, ParseError<'i>> -> Result<LengthOrPercentage, ParseError<'i>>
{ {
let token = try!(input.next()); let token = input.next()?;
match token { match token {
Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => { Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => {
NoCalcLength::parse_dimension(context, value, unit).map(LengthOrPercentage::Length) NoCalcLength::parse_dimension(context, value, unit).map(LengthOrPercentage::Length)
@ -822,9 +822,9 @@ impl LengthOrPercentage {
} }
} }
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {
let calc = try!(input.parse_nested_block(|i| { let calc = input.parse_nested_block(|i| {
CalcNode::parse_length_or_percentage(context, i, num_context) CalcNode::parse_length_or_percentage(context, i, num_context)
})); })?;
return Ok(LengthOrPercentage::Calc(Box::new(calc))) return Ok(LengthOrPercentage::Calc(Box::new(calc)))
} }
_ => Err(()) _ => Err(())
@ -940,7 +940,7 @@ impl LengthOrPercentageOrAuto {
num_context: AllowedLengthType, num_context: AllowedLengthType,
allow_quirks: AllowQuirks) allow_quirks: AllowQuirks)
-> Result<Self, ParseError<'i>> { -> Result<Self, ParseError<'i>> {
let token = try!(input.next()); let token = input.next()?;
match token { match token {
Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => { Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => {
NoCalcLength::parse_dimension(context, value, unit).map(LengthOrPercentageOrAuto::Length) NoCalcLength::parse_dimension(context, value, unit).map(LengthOrPercentageOrAuto::Length)
@ -962,9 +962,9 @@ impl LengthOrPercentageOrAuto {
Ok(LengthOrPercentageOrAuto::Auto) Ok(LengthOrPercentageOrAuto::Auto)
} }
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {
let calc = try!(input.parse_nested_block(|i| { let calc = input.parse_nested_block(|i| {
CalcNode::parse_length_or_percentage(context, i, num_context) CalcNode::parse_length_or_percentage(context, i, num_context)
})); })?;
Ok(LengthOrPercentageOrAuto::Calc(Box::new(calc))) Ok(LengthOrPercentageOrAuto::Calc(Box::new(calc)))
} }
_ => Err(()) _ => Err(())
@ -1039,7 +1039,7 @@ impl LengthOrPercentageOrNone {
allow_quirks: AllowQuirks) allow_quirks: AllowQuirks)
-> Result<LengthOrPercentageOrNone, ParseError<'i>> -> Result<LengthOrPercentageOrNone, ParseError<'i>>
{ {
let token = try!(input.next()); let token = input.next()?;
match token { match token {
Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => { Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => {
NoCalcLength::parse_dimension(context, value, unit).map(LengthOrPercentageOrNone::Length) NoCalcLength::parse_dimension(context, value, unit).map(LengthOrPercentageOrNone::Length)
@ -1057,9 +1057,9 @@ impl LengthOrPercentageOrNone {
)) ))
} }
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {
let calc = try!(input.parse_nested_block(|i| { let calc = input.parse_nested_block(|i| {
CalcNode::parse_length_or_percentage(context, i, num_context) CalcNode::parse_length_or_percentage(context, i, num_context)
})); })?;
Ok(LengthOrPercentageOrNone::Calc(Box::new(calc))) Ok(LengthOrPercentageOrNone::Calc(Box::new(calc)))
} }
Token::Ident(ref value) if value.eq_ignore_ascii_case("none") => Token::Ident(ref value) if value.eq_ignore_ascii_case("none") =>

View file

@ -81,7 +81,7 @@ pub use ::gecko::url::*;
impl Parse for SpecifiedUrl { impl Parse for SpecifiedUrl {
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> { fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
let url = try!(input.expect_url()); let url = input.expect_url()?;
Self::parse_from_string(url.into_owned(), context) Self::parse_from_string(url.into_owned(), context)
} }
} }
@ -97,12 +97,12 @@ no_viewport_percentage!(SpecifiedUrl);
/// Parse an `<integer>` value, handling `calc()` correctly. /// Parse an `<integer>` value, handling `calc()` correctly.
pub fn parse_integer<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_integer<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Integer, ParseError<'i>> { -> Result<Integer, ParseError<'i>> {
match try!(input.next()) { match input.next()? {
Token::Number { int_value: Some(v), .. } => Ok(Integer::new(v)), Token::Number { int_value: Some(v), .. } => Ok(Integer::new(v)),
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {
let result = try!(input.parse_nested_block(|i| { let result = input.parse_nested_block(|i| {
CalcNode::parse_integer(context, i) CalcNode::parse_integer(context, i)
})); })?;
Ok(Integer::from_calc(result)) Ok(Integer::from_calc(result))
} }
@ -122,7 +122,7 @@ pub fn parse_number_with_clamping_mode<'i, 't>(context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
clamping_mode: AllowedNumericType) clamping_mode: AllowedNumericType)
-> Result<Number, ParseError<'i>> { -> Result<Number, ParseError<'i>> {
match try!(input.next()) { match input.next()? {
Token::Number { value, .. } if clamping_mode.is_ok(context.parsing_mode, value) => { Token::Number { value, .. } if clamping_mode.is_ok(context.parsing_mode, value) => {
Ok(Number { Ok(Number {
value: value.min(f32::MAX).max(f32::MIN), value: value.min(f32::MAX).max(f32::MIN),
@ -130,9 +130,9 @@ pub fn parse_number_with_clamping_mode<'i, 't>(context: &ParserContext,
}) })
}, },
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {
let result = try!(input.parse_nested_block(|i| { let result = input.parse_nested_block(|i| {
CalcNode::parse_number(context, i) CalcNode::parse_number(context, i)
})); })?;
Ok(Number { Ok(Number {
value: result.min(f32::MAX).max(f32::MIN), value: result.min(f32::MAX).max(f32::MIN),
@ -227,7 +227,7 @@ impl Angle {
impl Parse for Angle { impl Parse for Angle {
/// Parses an angle according to CSS-VALUES § 6.1. /// Parses an angle according to CSS-VALUES § 6.1.
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> { fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
let token = try!(input.next()); let token = input.next()?;
match token { match token {
Token::Dimension { value, ref unit, .. } => { Token::Dimension { value, ref unit, .. } => {
Angle::parse_dimension(value, unit, /* from_calc = */ false) Angle::parse_dimension(value, unit, /* from_calc = */ false)
@ -267,7 +267,7 @@ impl Angle {
/// https://github.com/w3c/csswg-drafts/issues/1162 is resolved. /// https://github.com/w3c/csswg-drafts/issues/1162 is resolved.
pub fn parse_with_unitless<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_with_unitless<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Self, ParseError<'i>> { -> Result<Self, ParseError<'i>> {
let token = try!(input.next()); let token = input.next()?;
match token { match token {
Token::Dimension { value, ref unit, .. } => { Token::Dimension { value, ref unit, .. } => {
Angle::parse_dimension(value, unit, /* from_calc = */ false) Angle::parse_dimension(value, unit, /* from_calc = */ false)
@ -773,7 +773,7 @@ impl Shadow {
if !lengths_parsed { if !lengths_parsed {
if let Ok(value) = input.try(|i| Length::parse(context, i)) { if let Ok(value) = input.try(|i| Length::parse(context, i)) {
lengths[0] = value; lengths[0] = value;
lengths[1] = try!(Length::parse(context, input)); lengths[1] = Length::parse(context, input)?;
if let Ok(value) = input.try(|i| Length::parse_non_negative(context, i)) { if let Ok(value) = input.try(|i| Length::parse_non_negative(context, i)) {
lengths[2] = value; lengths[2] = value;
if !disable_spread_and_inset { if !disable_spread_and_inset {
@ -888,36 +888,36 @@ pub struct ClipRect {
impl ToCss for ClipRect { impl ToCss for ClipRect {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
try!(dest.write_str("rect(")); dest.write_str("rect(")?;
if let Some(ref top) = self.top { if let Some(ref top) = self.top {
try!(top.to_css(dest)); top.to_css(dest)?;
try!(dest.write_str(", ")); dest.write_str(", ")?;
} else { } else {
try!(dest.write_str("auto, ")); dest.write_str("auto, ")?;
} }
if let Some(ref right) = self.right { if let Some(ref right) = self.right {
try!(right.to_css(dest)); right.to_css(dest)?;
try!(dest.write_str(", ")); dest.write_str(", ")?;
} else { } else {
try!(dest.write_str("auto, ")); dest.write_str("auto, ")?;
} }
if let Some(ref bottom) = self.bottom { if let Some(ref bottom) = self.bottom {
try!(bottom.to_css(dest)); bottom.to_css(dest)?;
try!(dest.write_str(", ")); dest.write_str(", ")?;
} else { } else {
try!(dest.write_str("auto, ")); dest.write_str("auto, ")?;
} }
if let Some(ref left) = self.left { if let Some(ref left) = self.left {
try!(left.to_css(dest)); left.to_css(dest)?;
} else { } else {
try!(dest.write_str("auto")); dest.write_str("auto")?;
} }
try!(dest.write_str(")")); dest.write_str(")")?;
Ok(()) Ok(())
} }
} }
@ -967,27 +967,27 @@ impl ClipRect {
} }
} }
let func = try!(input.expect_function()); let func = input.expect_function()?;
if !func.eq_ignore_ascii_case("rect") { if !func.eq_ignore_ascii_case("rect") {
return Err(StyleParseError::UnexpectedFunction(func).into()) return Err(StyleParseError::UnexpectedFunction(func).into())
} }
input.parse_nested_block(|input| { input.parse_nested_block(|input| {
let top = try!(parse_argument(context, input, allow_quirks)); let top = parse_argument(context, input, allow_quirks)?;
let right; let right;
let bottom; let bottom;
let left; let left;
if input.try(|input| input.expect_comma()).is_ok() { if input.try(|input| input.expect_comma()).is_ok() {
right = try!(parse_argument(context, input, allow_quirks)); right = parse_argument(context, input, allow_quirks)?;
try!(input.expect_comma()); input.expect_comma()?;
bottom = try!(parse_argument(context, input, allow_quirks)); bottom = parse_argument(context, input, allow_quirks)?;
try!(input.expect_comma()); input.expect_comma()?;
left = try!(parse_argument(context, input, allow_quirks)); left = parse_argument(context, input, allow_quirks)?;
} else { } else {
right = try!(parse_argument(context, input, allow_quirks)); right = parse_argument(context, input, allow_quirks)?;
bottom = try!(parse_argument(context, input, allow_quirks)); bottom = parse_argument(context, input, allow_quirks)?;
left = try!(parse_argument(context, input, allow_quirks)); left = parse_argument(context, input, allow_quirks)?;
} }
Ok(ClipRect { Ok(ClipRect {
top: top, top: top,