mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Untry style
This commit is contained in:
parent
4c5f7bfaa3
commit
a5bb55790f
45 changed files with 518 additions and 527 deletions
|
@ -81,7 +81,7 @@ pub use ::gecko::url::*;
|
|||
|
||||
impl Parse for SpecifiedUrl {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -97,12 +97,12 @@ no_viewport_percentage!(SpecifiedUrl);
|
|||
/// Parse an `<integer>` value, handling `calc()` correctly.
|
||||
pub fn parse_integer<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<Integer, ParseError<'i>> {
|
||||
match try!(input.next()) {
|
||||
match input.next()? {
|
||||
Token::Number { int_value: Some(v), .. } => Ok(Integer::new(v)),
|
||||
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)
|
||||
}));
|
||||
})?;
|
||||
|
||||
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>,
|
||||
clamping_mode: AllowedNumericType)
|
||||
-> Result<Number, ParseError<'i>> {
|
||||
match try!(input.next()) {
|
||||
match input.next()? {
|
||||
Token::Number { value, .. } if clamping_mode.is_ok(context.parsing_mode, value) => {
|
||||
Ok(Number {
|
||||
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") => {
|
||||
let result = try!(input.parse_nested_block(|i| {
|
||||
let result = input.parse_nested_block(|i| {
|
||||
CalcNode::parse_number(context, i)
|
||||
}));
|
||||
})?;
|
||||
|
||||
Ok(Number {
|
||||
value: result.min(f32::MAX).max(f32::MIN),
|
||||
|
@ -227,7 +227,7 @@ impl Angle {
|
|||
impl Parse for Angle {
|
||||
/// Parses an angle according to CSS-VALUES § 6.1.
|
||||
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 {
|
||||
Token::Dimension { value, ref unit, .. } => {
|
||||
Angle::parse_dimension(value, unit, /* from_calc = */ false)
|
||||
|
@ -267,7 +267,7 @@ impl Angle {
|
|||
/// https://github.com/w3c/csswg-drafts/issues/1162 is resolved.
|
||||
pub fn parse_with_unitless<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<Self, ParseError<'i>> {
|
||||
let token = try!(input.next());
|
||||
let token = input.next()?;
|
||||
match token {
|
||||
Token::Dimension { value, ref unit, .. } => {
|
||||
Angle::parse_dimension(value, unit, /* from_calc = */ false)
|
||||
|
@ -773,7 +773,7 @@ impl Shadow {
|
|||
if !lengths_parsed {
|
||||
if let Ok(value) = input.try(|i| Length::parse(context, i)) {
|
||||
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)) {
|
||||
lengths[2] = value;
|
||||
if !disable_spread_and_inset {
|
||||
|
@ -888,36 +888,36 @@ pub struct ClipRect {
|
|||
|
||||
impl ToCss for ClipRect {
|
||||
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 {
|
||||
try!(top.to_css(dest));
|
||||
try!(dest.write_str(", "));
|
||||
top.to_css(dest)?;
|
||||
dest.write_str(", ")?;
|
||||
} else {
|
||||
try!(dest.write_str("auto, "));
|
||||
dest.write_str("auto, ")?;
|
||||
}
|
||||
|
||||
if let Some(ref right) = self.right {
|
||||
try!(right.to_css(dest));
|
||||
try!(dest.write_str(", "));
|
||||
right.to_css(dest)?;
|
||||
dest.write_str(", ")?;
|
||||
} else {
|
||||
try!(dest.write_str("auto, "));
|
||||
dest.write_str("auto, ")?;
|
||||
}
|
||||
|
||||
if let Some(ref bottom) = self.bottom {
|
||||
try!(bottom.to_css(dest));
|
||||
try!(dest.write_str(", "));
|
||||
bottom.to_css(dest)?;
|
||||
dest.write_str(", ")?;
|
||||
} else {
|
||||
try!(dest.write_str("auto, "));
|
||||
dest.write_str("auto, ")?;
|
||||
}
|
||||
|
||||
if let Some(ref left) = self.left {
|
||||
try!(left.to_css(dest));
|
||||
left.to_css(dest)?;
|
||||
} else {
|
||||
try!(dest.write_str("auto"));
|
||||
dest.write_str("auto")?;
|
||||
}
|
||||
|
||||
try!(dest.write_str(")"));
|
||||
dest.write_str(")")?;
|
||||
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") {
|
||||
return Err(StyleParseError::UnexpectedFunction(func).into())
|
||||
}
|
||||
|
||||
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 bottom;
|
||||
let left;
|
||||
|
||||
if input.try(|input| input.expect_comma()).is_ok() {
|
||||
right = try!(parse_argument(context, input, allow_quirks));
|
||||
try!(input.expect_comma());
|
||||
bottom = try!(parse_argument(context, input, allow_quirks));
|
||||
try!(input.expect_comma());
|
||||
left = try!(parse_argument(context, input, allow_quirks));
|
||||
right = parse_argument(context, input, allow_quirks)?;
|
||||
input.expect_comma()?;
|
||||
bottom = parse_argument(context, input, allow_quirks)?;
|
||||
input.expect_comma()?;
|
||||
left = parse_argument(context, input, allow_quirks)?;
|
||||
} else {
|
||||
right = try!(parse_argument(context, input, allow_quirks));
|
||||
bottom = try!(parse_argument(context, input, allow_quirks));
|
||||
left = try!(parse_argument(context, input, allow_quirks));
|
||||
right = parse_argument(context, input, allow_quirks)?;
|
||||
bottom = parse_argument(context, input, allow_quirks)?;
|
||||
left = parse_argument(context, input, allow_quirks)?;
|
||||
}
|
||||
Ok(ClipRect {
|
||||
top: top,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue