diff --git a/components/style/counter_style/mod.rs b/components/style/counter_style/mod.rs index 9c4be49bb918..ecdc8828ec1b 100644 --- a/components/style/counter_style/mod.rs +++ b/components/style/counter_style/mod.rs @@ -369,7 +369,7 @@ impl Parse for System { "symbolic" => Ok(System::Symbolic), "additive" => Ok(System::Additive), "fixed" => { - let first_symbol_value = input.try(|i| Integer::parse(context, i)).ok(); + let first_symbol_value = input.try_parse(|i| Integer::parse(context, i)).ok(); Ok(System::Fixed { first_symbol_value }) }, "extends" => { @@ -458,7 +458,7 @@ impl Parse for Negative { ) -> Result> { Ok(Negative( Symbol::parse(context, input)?, - input.try(|input| Symbol::parse(context, input)).ok(), + input.try_parse(|input| Symbol::parse(context, input)).ok(), )) } } @@ -494,7 +494,7 @@ impl Parse for CounterRanges { input: &mut Parser<'i, 't>, ) -> Result> { if input - .try(|input| input.expect_ident_matching("auto")) + .try_parse(|input| input.expect_ident_matching("auto")) .is_ok() { return Ok(CounterRanges(Default::default())); @@ -519,7 +519,7 @@ fn parse_bound<'i, 't>( context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(integer) = input.try(|input| Integer::parse(context, input)) { + if let Ok(integer) = input.try_parse(|input| Integer::parse(context, input)) { return Ok(CounterBound::Integer(integer)); } input.expect_ident_matching("infinite")?; @@ -535,7 +535,7 @@ impl Parse for Pad { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - let pad_with = input.try(|input| Symbol::parse(context, input)); + let pad_with = input.try_parse(|input| Symbol::parse(context, input)); let min_length = Integer::parse_non_negative(context, input)?; let pad_with = pad_with.or_else(|_| Symbol::parse(context, input))?; Ok(Pad(min_length, pad_with)) @@ -568,7 +568,7 @@ impl Parse for Symbols { input: &mut Parser<'i, 't>, ) -> Result> { let mut symbols = Vec::new(); - while let Ok(s) = input.try(|input| Symbol::parse(context, input)) { + while let Ok(s) = input.try_parse(|input| Symbol::parse(context, input)) { symbols.push(s); } if symbols.is_empty() { @@ -618,7 +618,7 @@ impl Parse for AdditiveTuple { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - let symbol = input.try(|input| Symbol::parse(context, input)); + let symbol = input.try_parse(|input| Symbol::parse(context, input)); let weight = Integer::parse_non_negative(context, input)?; let symbol = symbol.or_else(|_| Symbol::parse(context, input))?; Ok(Self { weight, symbol }) @@ -648,7 +648,7 @@ impl Parse for SpeakAs { input: &mut Parser<'i, 't>, ) -> Result> { let mut is_spell_out = false; - let result = input.try(|input| { + let result = input.try_parse(|input| { let ident = input.expect_ident().map_err(|_| ())?; match_ignore_ascii_case! { &*ident, "auto" => Ok(SpeakAs::Auto), diff --git a/components/style/custom_properties.rs b/components/style/custom_properties.rs index d0af57886db0..23e25b5a155b 100644 --- a/components/style/custom_properties.rs +++ b/components/style/custom_properties.rs @@ -489,7 +489,7 @@ fn parse_var_function<'i, 't>( let name = parse_name(&name).map_err(|()| { input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(name.clone())) })?; - if input.try(|input| input.expect_comma()).is_ok() { + if input.try_parse(|input| input.expect_comma()).is_ok() { parse_fallback(input)?; } if let Some(refs) = references { @@ -505,7 +505,7 @@ fn parse_env_function<'i, 't>( // TODO(emilio): This should be per spec, but no other // browser does that, see https://github.com/w3c/csswg-drafts/issues/3262. input.expect_ident()?; - if input.try(|input| input.expect_comma()).is_ok() { + if input.try_parse(|input| input.expect_comma()).is_ok() { parse_fallback(input)?; } if let Some(references) = references { diff --git a/components/style/font_face.rs b/components/style/font_face.rs index 21e2946d6a6d..3ddd6b69a858 100644 --- a/components/style/font_face.rs +++ b/components/style/font_face.rs @@ -122,7 +122,7 @@ macro_rules! impl_range { ) -> Result> { let first = $component::parse(context, input)?; let second = input - .try(|input| $component::parse(context, input)) + .try_parse(|input| $component::parse(context, input)) .unwrap_or_else(|_| first.clone()); Ok($range(first, second)) } @@ -236,7 +236,7 @@ impl Parse for FontStyle { GenericFontStyle::Italic => FontStyle::Italic, GenericFontStyle::Oblique(angle) => { let second_angle = input - .try(|input| SpecifiedFontStyle::parse_angle(context, input)) + .try_parse(|input| SpecifiedFontStyle::parse_angle(context, input)) .unwrap_or_else(|_| angle.clone()); FontStyle::Oblique(angle, second_angle) @@ -383,7 +383,7 @@ impl Parse for Source { input: &mut Parser<'i, 't>, ) -> Result> { if input - .try(|input| input.expect_function_matching("local")) + .try_parse(|input| input.expect_function_matching("local")) .is_ok() { return input @@ -395,7 +395,7 @@ impl Parse for Source { // Parsing optional format() let format_hints = if input - .try(|input| input.expect_function_matching("format")) + .try_parse(|input| input.expect_function_matching("format")) .is_ok() { input.parse_nested_block(|input| { diff --git a/components/style/media_queries/media_condition.rs b/components/style/media_queries/media_condition.rs index 19e201058192..f735704556e2 100644 --- a/components/style/media_queries/media_condition.rs +++ b/components/style/media_queries/media_condition.rs @@ -114,7 +114,7 @@ impl MediaCondition { // ParenthesisBlock. let first_condition = Self::parse_paren_block(context, input)?; - let operator = match input.try(Operator::parse) { + let operator = match input.try_parse(Operator::parse) { Ok(op) => op, Err(..) => return Ok(first_condition), }; @@ -133,7 +133,7 @@ impl MediaCondition { }; loop { - if input.try(|i| i.expect_ident_matching(delim)).is_err() { + if input.try_parse(|i| i.expect_ident_matching(delim)).is_err() { return Ok(MediaCondition::Operation( conditions.into_boxed_slice(), operator, @@ -159,7 +159,7 @@ impl MediaCondition { ) -> Result> { input.parse_nested_block(|input| { // Base case. - if let Ok(inner) = input.try(|i| Self::parse(context, i)) { + if let Ok(inner) = input.try_parse(|i| Self::parse(context, i)) { return Ok(MediaCondition::InParens(Box::new(inner))); } let expr = MediaFeatureExpression::parse_in_parenthesis_block(context, input)?; diff --git a/components/style/media_queries/media_feature_expression.rs b/components/style/media_queries/media_feature_expression.rs index 9e2fdd2d47b0..61e62f4ab707 100644 --- a/components/style/media_queries/media_feature_expression.rs +++ b/components/style/media_queries/media_feature_expression.rs @@ -200,14 +200,14 @@ fn consume_operation_or_colon(input: &mut Parser) -> Result, () Ok(Some(match first_delim { '=' => Operator::Equal, '>' => { - if input.try(|i| i.expect_delim('=')).is_ok() { + if input.try_parse(|i| i.expect_delim('=')).is_ok() { Operator::GreaterThanEqual } else { Operator::GreaterThan } }, '<' => { - if input.try(|i| i.expect_delim('=')).is_ok() { + if input.try_parse(|i| i.expect_delim('=')).is_ok() { Operator::LessThanEqual } else { Operator::LessThan @@ -314,7 +314,7 @@ impl MediaFeatureExpression { )); } - let operator = input.try(consume_operation_or_colon); + let operator = input.try_parse(consume_operation_or_colon); let operator = match operator { Err(..) => { // If there's no colon, this is a media query of the diff --git a/components/style/media_queries/media_query.rs b/components/style/media_queries/media_query.rs index 1768053dbce7..83e34c5037fe 100644 --- a/components/style/media_queries/media_query.rs +++ b/components/style/media_queries/media_query.rs @@ -125,8 +125,8 @@ impl MediaQuery { input: &mut Parser<'i, 't>, ) -> Result> { let (qualifier, explicit_media_type) = input - .try(|input| -> Result<_, ()> { - let qualifier = input.try(Qualifier::parse).ok(); + .try_parse(|input| -> Result<_, ()> { + let qualifier = input.try_parse(Qualifier::parse).ok(); let ident = input.expect_ident().map_err(|_| ())?; let media_type = MediaQueryType::parse(&ident)?; Ok((qualifier, Some(media_type))) @@ -135,7 +135,7 @@ impl MediaQuery { let condition = if explicit_media_type.is_none() { Some(MediaCondition::parse(context, input)?) - } else if input.try(|i| i.expect_ident_matching("and")).is_ok() { + } else if input.try_parse(|i| i.expect_ident_matching("and")).is_ok() { Some(MediaCondition::parse_disallow_or(context, input)?) } else { None diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index cc2cb20a3c65..5dc5d207f36b 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -1357,7 +1357,7 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for PropertyDeclarationParser<'a, 'b> { input.parse_until_before(Delimiter::Bang, |input| { PropertyDeclaration::parse_into(self.declarations, id, self.context, input) })?; - let importance = match input.try(parse_important) { + let importance = match input.try_parse(parse_important) { Ok(()) => Importance::Important, Err(_) => Importance::Normal, }; diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index 9baab22cb45d..505cd0c08563 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -354,7 +354,7 @@ use style_traits::Separator; % if allow_empty: - if input.try(|input| input.expect_ident_matching("none")).is_ok() { + if input.try_parse(|input| input.expect_ident_matching("none")).is_ok() { return Ok(SpecifiedValue(Default::default())) } % endif @@ -994,7 +994,7 @@ let first = parse_one(context, input)?; let second = - input.try(|input| parse_one(context, input)).unwrap_or_else(|_| first.clone()); + input.try_parse(|input| parse_one(context, input)).unwrap_or_else(|_| first.clone()); Ok(expanded! { ${to_rust_ident(first_property)}: first, ${to_rust_ident(second_property)}: second, diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index b9cd617027ba..12904fe1ca42 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1655,7 +1655,7 @@ impl UnparsedValue { let mut input = ParserInput::new(&css); let mut input = Parser::new(&mut input); input.skip_whitespace(); // Unnecessary for correctness, but may help try() rewind less. - if let Ok(keyword) = input.try(CSSWideKeyword::parse) { + if let Ok(keyword) = input.try_parse(CSSWideKeyword::parse) { return PropertyDeclaration::css_wide_keyword(longhand_id, keyword); } @@ -2380,7 +2380,7 @@ impl PropertyDeclaration { // FIXME: fully implement https://github.com/w3c/csswg-drafts/issues/774 // before adding skip_whitespace here. // This probably affects some test results. - let value = match input.try(CSSWideKeyword::parse) { + let value = match input.try_parse(CSSWideKeyword::parse) { Ok(keyword) => CustomDeclarationValue::CSSWideKeyword(keyword), Err(()) => CustomDeclarationValue::Value( crate::custom_properties::SpecifiedValue::parse(input)? @@ -2395,7 +2395,7 @@ impl PropertyDeclaration { PropertyId::LonghandAlias(id, _) | PropertyId::Longhand(id) => { input.skip_whitespace(); // Unnecessary for correctness, but may help try() rewind less. - input.try(CSSWideKeyword::parse).map(|keyword| { + input.try_parse(CSSWideKeyword::parse).map(|keyword| { PropertyDeclaration::css_wide_keyword(id, keyword) }).or_else(|()| { input.look_for_var_or_env_functions(); @@ -2425,7 +2425,7 @@ impl PropertyDeclaration { PropertyId::ShorthandAlias(id, _) | PropertyId::Shorthand(id) => { input.skip_whitespace(); // Unnecessary for correctness, but may help try() rewind less. - if let Ok(keyword) = input.try(CSSWideKeyword::parse) { + if let Ok(keyword) = input.try_parse(CSSWideKeyword::parse) { if id == ShorthandId::All { declarations.all_shorthand = AllShorthand::CSSWideKeyword(keyword) } else { diff --git a/components/style/properties/shorthands/background.mako.rs b/components/style/properties/shorthands/background.mako.rs index ba9391cb8e8e..dc28b6f60763 100644 --- a/components/style/properties/shorthands/background.mako.rs +++ b/components/style/properties/shorthands/background.mako.rs @@ -59,19 +59,19 @@ % endfor loop { if background_color.is_none() { - if let Ok(value) = input.try(|i| Color::parse(context, i)) { + if let Ok(value) = input.try_parse(|i| Color::parse(context, i)) { background_color = Some(value); continue } } if position.is_none() { - if let Ok(value) = input.try(|input| { + if let Ok(value) = input.try_parse(|input| { Position::parse_three_value_quirky(context, input, AllowQuirks::No) }) { position = Some(value); // Parse background size, if applicable. - size = input.try(|input| { + size = input.try_parse(|input| { input.expect_delim('/')?; background_size::single_value::parse(context, input) }).ok(); @@ -81,7 +81,7 @@ } % for name in "image repeat attachment origin clip".split(): if ${name}.is_none() { - if let Ok(value) = input.try(|input| background_${name}::single_value + if let Ok(value) = input.try_parse(|input| background_${name}::single_value ::parse(context, input)) { ${name} = Some(value); continue diff --git a/components/style/properties/shorthands/border.mako.rs b/components/style/properties/shorthands/border.mako.rs index e5122153db79..7419ad902179 100644 --- a/components/style/properties/shorthands/border.mako.rs +++ b/components/style/properties/shorthands/border.mako.rs @@ -71,20 +71,20 @@ pub fn parse_border<'i, 't>( let mut any = false; loop { if width.is_none() { - if let Ok(value) = input.try(|i| BorderSideWidth::parse(context, i)) { + if let Ok(value) = input.try_parse(|i| BorderSideWidth::parse(context, i)) { width = Some(value); any = true; } } if style.is_none() { - if let Ok(value) = input.try(BorderStyle::parse) { + if let Ok(value) = input.try_parse(BorderStyle::parse) { style = Some(value); any = true; continue } } if color.is_none() { - if let Ok(value) = input.try(|i| Color::parse(context, i)) { + if let Ok(value) = input.try_parse(|i| Color::parse(context, i)) { color = Some(value); any = true; continue @@ -301,24 +301,24 @@ pub fn parse_border<'i, 't>( let mut border_image_${name} = border_image_${name}::get_initial_specified_value(); % endfor - let result: Result<_, ParseError> = input.try(|input| { + let result: Result<_, ParseError> = input.try_parse(|input| { % for name in "outset repeat slice source width".split(): let mut ${name} = None; % endfor loop { if slice.is_none() { - if let Ok(value) = input.try(|input| border_image_slice::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| border_image_slice::parse(context, input)) { slice = Some(value); // 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_parse(|input| { input.expect_delim('/')?; // Parse border image width, if applicable. - let w = input.try(|input| + let w = input.try_parse(|input| border_image_width::parse(context, input)).ok(); // Parse border image outset if applicable. - let o = input.try(|input| { + let o = input.try_parse(|input| { input.expect_delim('/')?; border_image_outset::parse(context, input) }).ok(); @@ -339,7 +339,7 @@ pub fn parse_border<'i, 't>( } % for name in "source repeat".split(): if ${name}.is_none() { - if let Ok(value) = input.try(|input| border_image_${name}::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| border_image_${name}::parse(context, input)) { ${name} = Some(value); continue } @@ -407,7 +407,7 @@ pub fn parse_border<'i, 't>( ) -> Result> { let start_value = border_${axis}_start_${prop}::parse(context, input)?; let end_value = - input.try(|input| border_${axis}_start_${prop}::parse(context, input)) + input.try_parse(|input| border_${axis}_start_${prop}::parse(context, input)) .unwrap_or_else(|_| start_value.clone()); Ok(expanded! { diff --git a/components/style/properties/shorthands/box.mako.rs b/components/style/properties/shorthands/box.mako.rs index c5cc80829c7a..e1b94e52ac3b 100644 --- a/components/style/properties/shorthands/box.mako.rs +++ b/components/style/properties/shorthands/box.mako.rs @@ -31,7 +31,7 @@ ${helpers.two_properties_shorthand( macro_rules! try_parse_one { ($context: expr, $input: expr, $var: ident, $prop_module: ident) => { if $var.is_none() { - if let Ok(value) = $input.try(|i| { + if let Ok(value) = $input.try_parse(|i| { $prop_module::single_value::parse($context, i) }) { $var = Some(value); @@ -85,12 +85,12 @@ macro_rules! try_parse_one { // Must check 'transition-property' after 'transition-timing-function' since // 'transition-property' accepts any keyword. if property.is_none() { - if let Ok(value) = input.try(|i| TransitionProperty::parse(context, i)) { + if let Ok(value) = input.try_parse(|i| TransitionProperty::parse(context, i)) { property = Some(Some(value)); continue; } - if input.try(|i| i.expect_ident_matching("none")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() { // 'none' is not a valid value for , // so it's not acceptable in the function above. property = Some(None); @@ -389,13 +389,13 @@ ${helpers.two_properties_shorthand( let mut offset_rotate = None; loop { if offset_distance.is_none() { - if let Ok(value) = input.try(|i| LengthPercentage::parse(context, i)) { + if let Ok(value) = input.try_parse(|i| LengthPercentage::parse(context, i)) { offset_distance = Some(value); } } if offset_rotate.is_none() { - if let Ok(value) = input.try(|i| OffsetRotate::parse(context, i)) { + if let Ok(value) = input.try_parse(|i| OffsetRotate::parse(context, i)) { offset_rotate = Some(value); continue; } @@ -403,7 +403,7 @@ ${helpers.two_properties_shorthand( break; } - let offset_anchor = input.try(|i| { + let offset_anchor = input.try_parse(|i| { i.expect_delim('/')?; PositionOrAuto::parse(context, i) }).ok(); @@ -454,7 +454,7 @@ ${helpers.two_properties_shorthand( context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - let zoom = match input.try(|input| NumberOrPercentage::parse(context, input)) { + let zoom = match input.try_parse(|input| NumberOrPercentage::parse(context, input)) { Ok(number_or_percent) => number_or_percent.to_number(), Err(..) => { input.expect_ident_matching("normal")?; diff --git a/components/style/properties/shorthands/column.mako.rs b/components/style/properties/shorthands/column.mako.rs index d5e385faa4c1..e7c775dff042 100644 --- a/components/style/properties/shorthands/column.mako.rs +++ b/components/style/properties/shorthands/column.mako.rs @@ -22,21 +22,21 @@ let mut autos = 0; loop { - if input.try(|input| input.expect_ident_matching("auto")).is_ok() { + if input.try_parse(|input| input.expect_ident_matching("auto")).is_ok() { // Leave the options to None, 'auto' is the initial value. autos += 1; continue } if column_count.is_none() { - if let Ok(value) = input.try(|input| column_count::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| column_count::parse(context, input)) { column_count = Some(value); continue } } if column_width.is_none() { - if let Ok(value) = input.try(|input| column_width::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| column_width::parse(context, input)) { column_width = Some(value); continue } @@ -80,7 +80,7 @@ loop { % for name in "width style color".split(): if column_rule_${name}.is_none() { - if let Ok(value) = input.try(|input| + if let Ok(value) = input.try_parse(|input| column_rule_${name}::parse(context, input)) { column_rule_${name} = Some(value); any = true; diff --git a/components/style/properties/shorthands/font.mako.rs b/components/style/properties/shorthands/font.mako.rs index 1feed1138755..176164c4b1e6 100644 --- a/components/style/properties/shorthands/font.mako.rs +++ b/components/style/properties/shorthands/font.mako.rs @@ -65,7 +65,7 @@ let mut stretch = None; let size; % if engine == "gecko": - if let Ok(sys) = input.try(SystemFont::parse) { + if let Ok(sys) = input.try_parse(SystemFont::parse) { return Ok(expanded! { % for name in SYSTEM_FONT_LONGHANDS: % if name == "font_size": @@ -83,30 +83,30 @@ // Special-case 'normal' because it is valid in each of // font-style, font-weight, font-variant and font-stretch. // Leaves the values to None, 'normal' is the initial value for each of them. - if input.try(|input| input.expect_ident_matching("normal")).is_ok() { + if input.try_parse(|input| input.expect_ident_matching("normal")).is_ok() { nb_normals += 1; continue; } if style.is_none() { - if let Ok(value) = input.try(|input| font_style::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| font_style::parse(context, input)) { style = Some(value); continue } } if weight.is_none() { - if let Ok(value) = input.try(|input| font_weight::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| font_weight::parse(context, input)) { weight = Some(value); continue } } if variant_caps.is_none() { - if let Ok(value) = input.try(|input| font_variant_caps::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| font_variant_caps::parse(context, input)) { variant_caps = Some(value); continue } } if stretch.is_none() { - if let Ok(value) = input.try(FontStretchKeyword::parse) { + if let Ok(value) = input.try_parse(FontStretchKeyword::parse) { stretch = Some(FontStretch::Keyword(value)); continue } @@ -122,7 +122,7 @@ } }; - let line_height = if input.try(|input| input.expect_delim('/')).is_ok() { + let line_height = if input.try_parse(|input| input.expect_delim('/')).is_ok() { Some(LineHeight::parse(context, input)?) } else { None @@ -325,9 +325,9 @@ let mut ${prop} = None; % endfor - if input.try(|input| input.expect_ident_matching("normal")).is_ok() { + if input.try_parse(|input| input.expect_ident_matching("normal")).is_ok() { // Leave the values to None, 'normal' is the initial value for all the sub properties. - } else if input.try(|input| input.expect_ident_matching("none")).is_ok() { + } else if input.try_parse(|input| input.expect_ident_matching("none")).is_ok() { // The 'none' value sets 'font-variant-ligatures' to 'none' and resets all other sub properties // to their initial value. % if engine == "gecko": @@ -336,13 +336,13 @@ } else { let mut has_custom_value: bool = false; loop { - if input.try(|input| input.expect_ident_matching("normal")).is_ok() || - input.try(|input| input.expect_ident_matching("none")).is_ok() { + if input.try_parse(|input| input.expect_ident_matching("normal")).is_ok() || + input.try_parse(|input| input.expect_ident_matching("none")).is_ok() { return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)) } % for prop in sub_properties: if ${prop}.is_none() { - if let Ok(value) = input.try(|i| font_variant_${prop}::parse(context, i)) { + if let Ok(value) = input.try_parse(|i| font_variant_${prop}::parse(context, i)) { has_custom_value = true; ${prop} = Some(value); continue diff --git a/components/style/properties/shorthands/inherited_text.mako.rs b/components/style/properties/shorthands/inherited_text.mako.rs index b9a0c008bac7..9eb278da05ca 100644 --- a/components/style/properties/shorthands/inherited_text.mako.rs +++ b/components/style/properties/shorthands/inherited_text.mako.rs @@ -22,13 +22,13 @@ loop { if color.is_none() { - if let Ok(value) = input.try(|input| text_emphasis_color::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| text_emphasis_color::parse(context, input)) { color = Some(value); continue } } if style.is_none() { - if let Ok(value) = input.try(|input| text_emphasis_style::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| text_emphasis_style::parse(context, input)) { style = Some(value); continue } @@ -64,14 +64,14 @@ let mut width = None; loop { if color.is_none() { - if let Ok(value) = input.try(|input| _webkit_text_stroke_color::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| _webkit_text_stroke_color::parse(context, input)) { color = Some(value); continue } } if width.is_none() { - if let Ok(value) = input.try(|input| _webkit_text_stroke_width::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| _webkit_text_stroke_width::parse(context, input)) { width = Some(value); continue } diff --git a/components/style/properties/shorthands/list.mako.rs b/components/style/properties/shorthands/list.mako.rs index 8e842cd153e1..0b5a24df98fe 100644 --- a/components/style/properties/shorthands/list.mako.rs +++ b/components/style/properties/shorthands/list.mako.rs @@ -21,7 +21,7 @@ let mut nones = 0u8; let (mut image, mut position, mut list_style_type, mut any) = (None, None, None, false); loop { - if input.try(|input| input.expect_ident_matching("none")).is_ok() { + if input.try_parse(|input| input.expect_ident_matching("none")).is_ok() { nones = nones + 1; if nones > 2 { return Err(input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent("none".into()))) @@ -31,7 +31,7 @@ } if image.is_none() { - if let Ok(value) = input.try(|input| list_style_image::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| list_style_image::parse(context, input)) { image = Some(value); any = true; continue @@ -39,7 +39,7 @@ } if position.is_none() { - if let Ok(value) = input.try(|input| list_style_position::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| list_style_position::parse(context, input)) { position = Some(value); any = true; continue @@ -50,7 +50,7 @@ // arbitrary identifier for custom counter style, and thus may // affect values of list-style-position. if list_style_type.is_none() { - if let Ok(value) = input.try(|input| list_style_type::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| list_style_type::parse(context, input)) { list_style_type = Some(value); any = true; continue diff --git a/components/style/properties/shorthands/outline.mako.rs b/components/style/properties/shorthands/outline.mako.rs index d667aa9ffb12..c6ba47303a78 100644 --- a/components/style/properties/shorthands/outline.mako.rs +++ b/components/style/properties/shorthands/outline.mako.rs @@ -24,21 +24,21 @@ let mut any = false; loop { if color.is_none() { - if let Ok(value) = input.try(|i| specified::Color::parse(context, i)) { + if let Ok(value) = input.try_parse(|i| specified::Color::parse(context, i)) { color = Some(value); any = true; continue } } if style.is_none() { - if let Ok(value) = input.try(|input| outline_style::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| outline_style::parse(context, input)) { style = Some(value); any = true; continue } } if width.is_none() { - if let Ok(value) = input.try(|input| outline_width::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| outline_width::parse(context, input)) { width = Some(value); any = true; continue diff --git a/components/style/properties/shorthands/position.mako.rs b/components/style/properties/shorthands/position.mako.rs index ff9b5cd57909..0dacdc4c7cf1 100644 --- a/components/style/properties/shorthands/position.mako.rs +++ b/components/style/properties/shorthands/position.mako.rs @@ -21,13 +21,13 @@ let mut wrap = None; loop { if direction.is_none() { - if let Ok(value) = input.try(|input| flex_direction::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| flex_direction::parse(context, input)) { direction = Some(value); continue } } if wrap.is_none() { - if let Ok(value) = input.try(|input| flex_wrap::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| flex_wrap::parse(context, input)) { wrap = Some(value); continue } @@ -61,7 +61,7 @@ input: &mut Parser<'i, 't>, ) -> Result<(NonNegativeNumber, Option),ParseError<'i>> { let grow = NonNegativeNumber::parse(context, input)?; - let shrink = input.try(|i| NonNegativeNumber::parse(context, i)).ok(); + let shrink = input.try_parse(|i| NonNegativeNumber::parse(context, i)).ok(); Ok((grow, shrink)) } @@ -73,7 +73,7 @@ let mut shrink = None; let mut basis = None; - if input.try(|input| input.expect_ident_matching("none")).is_ok() { + if input.try_parse(|input| input.expect_ident_matching("none")).is_ok() { return Ok(expanded! { flex_grow: NonNegativeNumber::new(0.0), flex_shrink: NonNegativeNumber::new(0.0), @@ -82,14 +82,14 @@ } loop { if grow.is_none() { - if let Ok((flex_grow, flex_shrink)) = input.try(|i| parse_flexibility(context, i)) { + if let Ok((flex_grow, flex_shrink)) = input.try_parse(|i| parse_flexibility(context, i)) { grow = Some(flex_grow); shrink = flex_shrink; continue } } if basis.is_none() { - if let Ok(value) = input.try(|input| FlexBasis::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| FlexBasis::parse(context, input)) { basis = Some(value); continue } @@ -124,7 +124,7 @@ pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { let r_gap = row_gap::parse(context, input)?; - let c_gap = input.try(|input| column_gap::parse(context, input)).unwrap_or(r_gap.clone()); + let c_gap = input.try_parse(|input| column_gap::parse(context, input)).unwrap_or(r_gap.clone()); Ok(expanded! { row_gap: r_gap, @@ -164,8 +164,8 @@ context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - let start = input.try(|i| GridLine::parse(context, i))?; - let end = if input.try(|i| i.expect_delim('/')).is_ok() { + let start = input.try_parse(|i| GridLine::parse(context, i))?; + let end = if input.try_parse(|i| i.expect_delim('/')).is_ok() { GridLine::parse(context, input)? } else { let mut line = GridLine::auto(); @@ -226,12 +226,12 @@ this } - let row_start = input.try(|i| GridLine::parse(context, i))?; - let (column_start, row_end, column_end) = if input.try(|i| i.expect_delim('/')).is_ok() { + let row_start = input.try_parse(|i| GridLine::parse(context, i))?; + let (column_start, row_end, column_end) = if input.try_parse(|i| i.expect_delim('/')).is_ok() { let column_start = GridLine::parse(context, input)?; - let (row_end, column_end) = if input.try(|i| i.expect_delim('/')).is_ok() { + let (row_end, column_end) = if input.try_parse(|i| i.expect_delim('/')).is_ok() { let row_end = GridLine::parse(context, input)?; - let column_end = if input.try(|i| i.expect_delim('/')).is_ok() { + let column_end = if input.try_parse(|i| i.expect_delim('/')).is_ok() { GridLine::parse(context, input)? } else { // grid-column-end has not been given line_with_ident_from(&column_start) @@ -324,8 +324,8 @@ } %> % for keyword, rust_type in keywords.items(): - if let Ok(x) = input.try(|i| { - if i.try(|i| i.expect_ident_matching("${keyword}")).is_ok() { + if let Ok(x) = input.try_parse(|i| { + if i.try_parse(|i| i.expect_ident_matching("${keyword}")).is_ok() { if !i.is_exhausted() { return Err(()); } @@ -337,20 +337,20 @@ } % endfor - let first_line_names = input.try(parse_line_names).unwrap_or_default(); - if let Ok(string) = input.try(|i| i.expect_string().map(|s| s.as_ref().to_owned().into())) { + let first_line_names = input.try_parse(parse_line_names).unwrap_or_default(); + if let Ok(string) = input.try_parse(|i| i.expect_string().map(|s| s.as_ref().to_owned().into())) { let mut strings = vec![]; let mut values = vec![]; let mut line_names = vec![]; line_names.push(first_line_names); strings.push(string); loop { - let size = input.try(|i| TrackSize::parse(context, i)).unwrap_or_default(); + let size = input.try_parse(|i| TrackSize::parse(context, i)).unwrap_or_default(); values.push(TrackListValue::TrackSize(size)); - let mut names = input.try(parse_line_names).unwrap_or_default(); - let more_names = input.try(parse_line_names); + let mut names = input.try_parse(parse_line_names).unwrap_or_default(); + let more_names = input.try_parse(parse_line_names); - match input.try(|i| i.expect_string().map(|s| s.as_ref().to_owned().into())) { + match input.try_parse(|i| i.expect_string().map(|s| s.as_ref().to_owned().into())) { Ok(string) => { strings.push(string); if let Ok(v) = more_names { @@ -387,7 +387,7 @@ auto_repeat_index: std::usize::MAX, }; - let template_cols = if input.try(|i| i.expect_delim('/')).is_ok() { + let template_cols = if input.try_parse(|i| i.expect_delim('/')).is_ok() { let value = GridTemplateComponent::parse_without_none(context, input)?; if let GenericGridTemplateComponent::TrackList(ref list) = value { if !list.is_explicit() { @@ -572,13 +572,13 @@ let mut dense = GridAutoFlow::empty(); for _ in 0..2 { - if input.try(|i| i.expect_ident_matching("auto-flow")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("auto-flow")).is_ok() { track = if is_row { Some(GridAutoFlow::ROW) } else { Some(GridAutoFlow::COLUMN) }; - } else if input.try(|i| i.expect_ident_matching("dense")).is_ok() { + } else if input.try_parse(|i| i.expect_ident_matching("dense")).is_ok() { dense = GridAutoFlow::DENSE } else { break @@ -592,18 +592,18 @@ } } - if let Ok((rows, cols, areas)) = input.try(|i| super::grid_template::parse_grid_template(context, i)) { + if let Ok((rows, cols, areas)) = input.try_parse(|i| super::grid_template::parse_grid_template(context, i)) { temp_rows = rows; temp_cols = cols; temp_areas = areas; - } else if let Ok(rows) = input.try(|i| GridTemplateComponent::parse(context, i)) { + } else if let Ok(rows) = input.try_parse(|i| GridTemplateComponent::parse(context, i)) { temp_rows = rows; input.expect_delim('/')?; flow = parse_auto_flow(input, false)?; auto_cols = grid_auto_columns::parse(context, input).unwrap_or_default(); } else { flow = parse_auto_flow(input, true)?; - auto_rows = input.try(|i| grid_auto_rows::parse(context, i)).unwrap_or_default(); + auto_rows = input.try_parse(|i| grid_auto_rows::parse(context, i)).unwrap_or_default(); input.expect_delim('/')?; temp_cols = GridTemplateComponent::parse(context, input)?; } @@ -710,7 +710,7 @@ let align_content = ContentDistribution::parse(input, AxisDirection::Block)?; - let justify_content = input.try(|input| { + let justify_content = input.try_parse(|input| { ContentDistribution::parse(input, AxisDirection::Inline) }); @@ -763,7 +763,7 @@ input: &mut Parser<'i, 't>, ) -> Result> { let align = SelfAlignment::parse(input, AxisDirection::Block)?; - let justify = input.try(|input| SelfAlignment::parse(input, AxisDirection::Inline)); + let justify = input.try_parse(|input| SelfAlignment::parse(input, AxisDirection::Inline)); let justify = match justify { Ok(v) => v, @@ -812,7 +812,7 @@ ) -> Result> { let align = AlignItems::parse(context, input)?; let justify = - input.try(|input| JustifyItems::parse(context, input)) + input.try_parse(|input| JustifyItems::parse(context, input)) .unwrap_or_else(|_| JustifyItems::from(align)); Ok(expanded! { diff --git a/components/style/properties/shorthands/svg.mako.rs b/components/style/properties/shorthands/svg.mako.rs index 6610968f24db..99461a514872 100644 --- a/components/style/properties/shorthands/svg.mako.rs +++ b/components/style/properties/shorthands/svg.mako.rs @@ -55,18 +55,18 @@ % endfor loop { if image.is_none() { - if let Ok(value) = input.try(|input| mask_image::single_value + if let Ok(value) = input.try_parse(|input| mask_image::single_value ::parse(context, input)) { image = Some(value); continue } } if position.is_none() { - if let Ok(value) = input.try(|input| Position::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| Position::parse(context, input)) { position = Some(value); // Parse mask size, if applicable. - size = input.try(|input| { + size = input.try_parse(|input| { input.expect_delim('/')?; mask_size::single_value::parse(context, input) }).ok(); @@ -76,7 +76,7 @@ } % for name in "repeat origin clip composite mode".split(): if ${name}.is_none() { - if let Ok(value) = input.try(|input| mask_${name}::single_value + if let Ok(value) = input.try_parse(|input| mask_${name}::single_value ::parse(context, input)) { ${name} = Some(value); continue diff --git a/components/style/properties/shorthands/text.mako.rs b/components/style/properties/shorthands/text.mako.rs index defbfaaf3c05..5c7d9c7655c9 100644 --- a/components/style/properties/shorthands/text.mako.rs +++ b/components/style/properties/shorthands/text.mako.rs @@ -35,7 +35,7 @@ macro_rules! parse_component { ($value:ident, $module:ident) => ( if $value.is_none() { - if let Ok(value) = input.try(|input| $module::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| $module::parse(context, input)) { $value = Some(value); any = true; continue; diff --git a/components/style/stylesheets/document_rule.rs b/components/style/stylesheets/document_rule.rs index 35c6b443fe21..2f8c5bc48d73 100644 --- a/components/style/stylesheets/document_rule.rs +++ b/components/style/stylesheets/document_rule.rs @@ -135,7 +135,7 @@ impl DocumentMatchingFunction { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(url) = input.try(|input| CssUrl::parse(context, input)) { + if let Ok(url) = input.try_parse(|input| CssUrl::parse(context, input)) { return Ok(DocumentMatchingFunction::Url(url)); } diff --git a/components/style/stylesheets/rule_parser.rs b/components/style/stylesheets/rule_parser.rs index 74425afafcd8..0b01a5f7bdd8 100644 --- a/components/style/stylesheets/rule_parser.rs +++ b/components/style/stylesheets/rule_parser.rs @@ -218,7 +218,7 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> { return Err(input.new_custom_error(StyleParseErrorKind::UnexpectedNamespaceRule)) } - let prefix = input.try(|i| i.expect_ident_cloned()) + let prefix = input.try_parse(|i| i.expect_ident_cloned()) .map(|s| Prefix::from(s.as_ref())).ok(); let maybe_namespace = match input.expect_url_or_string() { Ok(url_or_string) => url_or_string, diff --git a/components/style/stylesheets/supports_rule.rs b/components/style/stylesheets/supports_rule.rs index 6a522bcdb743..d0aaa0a03d8f 100644 --- a/components/style/stylesheets/supports_rule.rs +++ b/components/style/stylesheets/supports_rule.rs @@ -103,7 +103,7 @@ impl SupportsCondition { /// /// pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result> { - if input.try(|i| i.expect_ident_matching("not")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("not")).is_ok() { let inner = SupportsCondition::parse_in_parens(input)?; return Ok(SupportsCondition::Not(Box::new(inner))); } @@ -129,7 +129,7 @@ impl SupportsCondition { loop { conditions.push(SupportsCondition::parse_in_parens(input)?); if input - .try(|input| input.expect_ident_matching(keyword)) + .try_parse(|input| input.expect_ident_matching(keyword)) .is_err() { // Did not find the expected keyword. @@ -175,20 +175,20 @@ impl SupportsCondition { fn parse_in_parens<'i, 't>(input: &mut Parser<'i, 't>) -> Result> { // Whitespace is normally taken care of in `Parser::next`, // but we want to not include it in `pos` for the SupportsCondition::FutureSyntax cases. - while input.try(Parser::expect_whitespace).is_ok() {} + while input.try_parse(Parser::expect_whitespace).is_ok() {} let pos = input.position(); let location = input.current_source_location(); match *input.next()? { Token::ParenthesisBlock => { - let nested = - input.try(|input| input.parse_nested_block(parse_condition_or_declaration)); + let nested = input + .try_parse(|input| input.parse_nested_block(parse_condition_or_declaration)); if nested.is_ok() { return nested; } }, Token::Function(ref ident) => { let ident = ident.clone(); - let nested = input.try(|input| { + let nested = input.try_parse(|input| { input.parse_nested_block(|input| { SupportsCondition::parse_functional(&ident, input) }) @@ -239,7 +239,7 @@ fn eval_moz_bool_pref(_: &CStr, _: &ParserContext) -> bool { pub fn parse_condition_or_declaration<'i, 't>( input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(condition) = input.try(SupportsCondition::parse) { + if let Ok(condition) = input.try_parse(SupportsCondition::parse) { Ok(SupportsCondition::Parenthesized(Box::new(condition))) } else { Declaration::parse(input).map(SupportsCondition::Declaration) @@ -414,7 +414,7 @@ impl Declaration { PropertyDeclaration::parse_into(&mut declarations, id, &context, input) .map_err(|_| input.new_custom_error(())) })?; - let _ = input.try(parse_important); + let _ = input.try_parse(parse_important); Ok(()) }) .is_ok() diff --git a/components/style/stylesheets/viewport_rule.rs b/components/style/stylesheets/viewport_rule.rs index cd875eefb691..a6ad967b34cd 100644 --- a/components/style/stylesheets/viewport_rule.rs +++ b/components/style/stylesheets/viewport_rule.rs @@ -267,7 +267,7 @@ fn parse_shorthand<'i, 't>( input: &mut Parser<'i, 't>, ) -> Result<(ViewportLength, ViewportLength), ParseError<'i>> { let min = ViewportLength::parse(context, input)?; - match input.try(|i| ViewportLength::parse(context, i)) { + match input.try_parse(|i| ViewportLength::parse(context, i)) { Err(_) => Ok((min.clone(), min)), Ok(max) => Ok((min, max)), } @@ -293,7 +293,7 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for ViewportRuleParser<'a, 'b> { ($declaration:ident($parse:expr)) => { declaration!($declaration { value: $parse(input)?, - important: input.try(parse_important).is_ok(), + important: input.try_parse(parse_important).is_ok(), }) }; ($declaration:ident { value: $value:expr, important: $important:expr, }) => { @@ -311,7 +311,7 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for ViewportRuleParser<'a, 'b> { }; (shorthand -> [$min:ident, $max:ident]) => {{ let shorthand = parse_shorthand(self.context, input)?; - let important = input.try(parse_important).is_ok(); + let important = input.try_parse(parse_important).is_ok(); Ok(vec![ declaration!($min { diff --git a/components/style/values/computed/font.rs b/components/style/values/computed/font.rs index 57ca8e97a863..d0b14b7e3fa8 100644 --- a/components/style/values/computed/font.rs +++ b/components/style/values/computed/font.rs @@ -358,7 +358,7 @@ pub enum GenericFontFamily { impl SingleFontFamily { /// Parse a font-family value. pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result> { - if let Ok(value) = input.try(|i| i.expect_string_cloned()) { + if let Ok(value) = input.try_parse(|i| i.expect_string_cloned()) { return Ok(SingleFontFamily::FamilyName(FamilyName { name: Atom::from(&*value), syntax: FontFamilyNameSyntax::Quoted, @@ -393,7 +393,7 @@ impl SingleFontFamily { value.push(' '); value.push_str(&ident); } - while let Ok(ident) = input.try(|i| i.expect_ident_cloned()) { + while let Ok(ident) = input.try_parse(|i| i.expect_ident_cloned()) { serialize_quoted = serialize_quoted || ident.contains(' '); value.push(' '); value.push_str(&ident); diff --git a/components/style/values/generics/font.rs b/components/style/values/generics/font.rs index 237e862d4aa5..e19c796d17bd 100644 --- a/components/style/values/generics/font.rs +++ b/components/style/values/generics/font.rs @@ -107,7 +107,10 @@ impl Parse for FontSettings { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if input.try(|i| i.expect_ident_matching("normal")).is_ok() { + if input + .try_parse(|i| i.expect_ident_matching("normal")) + .is_ok() + { return Ok(Self::normal()); } diff --git a/components/style/values/generics/grid.rs b/components/style/values/generics/grid.rs index a0970a6fbc09..7995bf044a3b 100644 --- a/components/style/values/generics/grid.rs +++ b/components/style/values/generics/grid.rs @@ -131,7 +131,7 @@ impl Parse for GridLine { input: &mut Parser<'i, 't>, ) -> Result> { let mut grid_line = Self::auto(); - if input.try(|i| i.expect_ident_matching("auto")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("auto")).is_ok() { return Ok(grid_line); } @@ -144,7 +144,7 @@ impl Parse for GridLine { for _ in 0..3 { // Maximum possible entities for let location = input.current_source_location(); - if input.try(|i| i.expect_ident_matching("span")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("span")).is_ok() { if grid_line.is_span { return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError)); } @@ -154,7 +154,7 @@ impl Parse for GridLine { } grid_line.is_span = true; - } else if let Ok(i) = input.try(|i| specified::Integer::parse(context, i)) { + } else if let Ok(i) = input.try_parse(|i| specified::Integer::parse(context, i)) { // FIXME(emilio): Probably shouldn't reject if it's calc()... let value = i.value(); if value == 0 || val_before_span || !grid_line.line_num.is_zero() { @@ -165,7 +165,7 @@ impl Parse for GridLine { MIN_GRID_LINE, cmp::min(value, MAX_GRID_LINE), )); - } else if let Ok(name) = input.try(|i| i.expect_ident_cloned()) { + } else if let Ok(name) = input.try_parse(|i| i.expect_ident_cloned()) { if val_before_span || grid_line.ident != atom!("") { return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError)); } @@ -432,7 +432,7 @@ impl Parse for RepeatCount { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(mut i) = input.try(|i| specified::Integer::parse_positive(context, i)) { + if let Ok(mut i) = input.try_parse(|i| specified::Integer::parse_positive(context, i)) { if i.value() > MAX_GRID_LINE { i = specified::Integer::new(MAX_GRID_LINE); } @@ -671,14 +671,14 @@ impl Parse for LineNameList { let mut fill_data = None; loop { - let repeat_parse_result = input.try(|input| { + let repeat_parse_result = input.try_parse(|input| { input.expect_function_matching("repeat")?; input.parse_nested_block(|input| { let count = RepeatCount::parse(context, input)?; input.expect_comma()?; let mut names_list = vec![]; names_list.push(parse_line_names(input)?); // there should be at least one - while let Ok(names) = input.try(parse_line_names) { + while let Ok(names) = input.try_parse(parse_line_names) { names_list.push(names); } Ok((names_list, count)) @@ -703,7 +703,7 @@ impl Parse for LineNameList { }, _ => return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)), } - } else if let Ok(names) = input.try(parse_line_names) { + } else if let Ok(names) = input.try_parse(parse_line_names) { line_names.push(names); } else { break; diff --git a/components/style/values/generics/length.rs b/components/style/values/generics/length.rs index bed574861cb1..3ac358e78178 100644 --- a/components/style/values/generics/length.rs +++ b/components/style/values/generics/length.rs @@ -59,7 +59,7 @@ impl LengthPercentageOrAuto { &mut Parser<'i, 't>, ) -> Result>, ) -> Result> { - if input.try(|i| i.expect_ident_matching("auto")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("auto")).is_ok() { return Ok(LengthPercentageOrAuto::Auto); } diff --git a/components/style/values/generics/mod.rs b/components/style/values/generics/mod.rs index 6689405b2b1f..09a99432e178 100644 --- a/components/style/values/generics/mod.rs +++ b/components/style/values/generics/mod.rs @@ -101,13 +101,13 @@ impl Parse for CounterStyle { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(name) = input.try(|i| parse_counter_style_name(i)) { + if let Ok(name) = input.try_parse(|i| parse_counter_style_name(i)) { return Ok(CounterStyle::Name(name)); } input.expect_function_matching("symbols")?; input.parse_nested_block(|input| { let symbols_type = input - .try(SymbolsType::parse) + .try_parse(SymbolsType::parse) .unwrap_or(SymbolsType::Symbolic); let symbols = Symbols::parse(context, input)?; // There must be at least two symbols for alphabetic or diff --git a/components/style/values/generics/rect.rs b/components/style/values/generics/rect.rs index 5164bd774635..dee21459a770 100644 --- a/components/style/values/generics/rect.rs +++ b/components/style/values/generics/rect.rs @@ -55,7 +55,7 @@ where Parse: Fn(&ParserContext, &mut Parser<'i, 't>) -> Result>, { let first = parse(context, input)?; - let second = if let Ok(second) = input.try(|i| parse(context, i)) { + let second = if let Ok(second) = input.try_parse(|i| parse(context, i)) { second } else { // @@ -66,13 +66,13 @@ where first, )); }; - let third = if let Ok(third) = input.try(|i| parse(context, i)) { + let third = if let Ok(third) = input.try_parse(|i| parse(context, i)) { third } else { // return Ok(Self::new(first.clone(), second.clone(), first, second)); }; - let fourth = if let Ok(fourth) = input.try(|i| parse(context, i)) { + let fourth = if let Ok(fourth) = input.try_parse(|i| parse(context, i)) { fourth } else { // diff --git a/components/style/values/generics/size.rs b/components/style/values/generics/size.rs index fa129bee4754..e00eef28b93d 100644 --- a/components/style/values/generics/size.rs +++ b/components/style/values/generics/size.rs @@ -63,7 +63,7 @@ impl Size2D { { let first = parse_one(context, input)?; let second = input - .try(|i| parse_one(context, i)) + .try_parse(|i| parse_one(context, i)) .unwrap_or_else(|_| first.clone()); Ok(Self::new(first, second)) } diff --git a/components/style/values/generics/svg.rs b/components/style/values/generics/svg.rs index 2b04d36db78e..26a33228e862 100644 --- a/components/style/values/generics/svg.rs +++ b/components/style/values/generics/svg.rs @@ -129,7 +129,7 @@ impl Parse for SVGPaint { }); } let fallback = input - .try(|i| SVGPaintFallback::parse(context, i)) + .try_parse(|i| SVGPaintFallback::parse(context, i)) .unwrap_or(SVGPaintFallback::Unset); Ok(SVGPaint { kind, fallback }) } diff --git a/components/style/values/generics/text.rs b/components/style/values/generics/text.rs index ceeb59a3d0ce..0062f3047019 100644 --- a/components/style/values/generics/text.rs +++ b/components/style/values/generics/text.rs @@ -63,7 +63,10 @@ impl Spacing { where F: FnOnce(&ParserContext, &mut Parser<'i, 't>) -> Result>, { - if input.try(|i| i.expect_ident_matching("normal")).is_ok() { + if input + .try_parse(|i| i.expect_ident_matching("normal")) + .is_ok() + { return Ok(Spacing::Normal); } parse(context, input).map(Spacing::Value) diff --git a/components/style/values/specified/align.rs b/components/style/values/specified/align.rs index 51b5e625672d..ebb6f6383402 100644 --- a/components/style/values/specified/align.rs +++ b/components/style/values/specified/align.rs @@ -194,25 +194,28 @@ impl ContentDistribution { // when this function is updated. // Try to parse normal first - if input.try(|i| i.expect_ident_matching("normal")).is_ok() { + if input + .try_parse(|i| i.expect_ident_matching("normal")) + .is_ok() + { return Ok(ContentDistribution::normal()); } // Parse , but only on the block axis. if axis == AxisDirection::Block { - if let Ok(value) = input.try(parse_baseline) { + if let Ok(value) = input.try_parse(parse_baseline) { return Ok(ContentDistribution::new(value)); } } // - if let Ok(value) = input.try(parse_content_distribution) { + if let Ok(value) = input.try_parse(parse_content_distribution) { return Ok(ContentDistribution::new(value)); } // ? let overflow_position = input - .try(parse_overflow_position) + .try_parse(parse_overflow_position) .unwrap_or(AlignFlags::empty()); let content_position = try_match_ident_ignore_ascii_case! { input, @@ -426,18 +429,18 @@ impl SelfAlignment { // // It's weird that this accepts , but not // justify-content... - if let Ok(value) = input.try(parse_baseline) { + if let Ok(value) = input.try_parse(parse_baseline) { return Ok(SelfAlignment(value)); } // auto | normal | stretch - if let Ok(value) = input.try(parse_auto_normal_stretch) { + if let Ok(value) = input.try_parse(parse_auto_normal_stretch) { return Ok(SelfAlignment(value)); } // ? let overflow_position = input - .try(parse_overflow_position) + .try_parse(parse_overflow_position) .unwrap_or(AlignFlags::empty()); let self_position = parse_self_position(input, axis)?; Ok(SelfAlignment(overflow_position | self_position)) @@ -564,17 +567,17 @@ impl Parse for AlignItems { // this function is updated. // - if let Ok(baseline) = input.try(parse_baseline) { + if let Ok(baseline) = input.try_parse(parse_baseline) { return Ok(AlignItems(baseline)); } // normal | stretch - if let Ok(value) = input.try(parse_normal_stretch) { + if let Ok(value) = input.try_parse(parse_normal_stretch) { return Ok(AlignItems(value)); } // ? let overflow = input - .try(parse_overflow_position) + .try_parse(parse_overflow_position) .unwrap_or(AlignFlags::empty()); let self_position = parse_self_position(input, AxisDirection::Block)?; Ok(AlignItems(self_position | overflow)) @@ -623,23 +626,23 @@ impl Parse for JustifyItems { // // It's weird that this accepts , but not // justify-content... - if let Ok(baseline) = input.try(parse_baseline) { + if let Ok(baseline) = input.try_parse(parse_baseline) { return Ok(JustifyItems(baseline)); } // normal | stretch - if let Ok(value) = input.try(parse_normal_stretch) { + if let Ok(value) = input.try_parse(parse_normal_stretch) { return Ok(JustifyItems(value)); } // legacy | [ legacy && [ left | right | center ] ] - if let Ok(value) = input.try(parse_legacy) { + if let Ok(value) = input.try_parse(parse_legacy) { return Ok(JustifyItems(value)); } // ? let overflow = input - .try(parse_overflow_position) + .try_parse(parse_overflow_position) .unwrap_or(AlignFlags::empty()); let self_position = parse_self_position(input, AxisDirection::Inline)?; Ok(JustifyItems(overflow | self_position)) @@ -795,7 +798,7 @@ fn parse_legacy<'i, 't>(input: &mut Parser<'i, 't>) -> Result { - let flags = input.try(parse_left_right_center) + let flags = input.try_parse(parse_left_right_center) .unwrap_or(AlignFlags::empty()); return Ok(AlignFlags::LEGACY | flags) diff --git a/components/style/values/specified/background.rs b/components/style/values/specified/background.rs index e7cb98a6ae96..29f6d6b352f0 100644 --- a/components/style/values/specified/background.rs +++ b/components/style/values/specified/background.rs @@ -22,9 +22,10 @@ impl Parse for BackgroundSize { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(width) = input.try(|i| NonNegativeLengthPercentageOrAuto::parse(context, i)) { + if let Ok(width) = input.try_parse(|i| NonNegativeLengthPercentageOrAuto::parse(context, i)) + { let height = input - .try(|i| NonNegativeLengthPercentageOrAuto::parse(context, i)) + .try_parse(|i| NonNegativeLengthPercentageOrAuto::parse(context, i)) .unwrap_or(NonNegativeLengthPercentageOrAuto::auto()); return Ok(GenericBackgroundSize::ExplicitSize { width, height }); } @@ -136,7 +137,7 @@ impl Parse for BackgroundRepeat { }, }; - let vertical = input.try(BackgroundRepeatKeyword::parse).ok(); + let vertical = input.try_parse(BackgroundRepeatKeyword::parse).ok(); Ok(BackgroundRepeat(horizontal, vertical.unwrap_or(horizontal))) } } diff --git a/components/style/values/specified/basic_shape.rs b/components/style/values/specified/basic_shape.rs index 135ac85d3306..37aaae2ec2a2 100644 --- a/components/style/values/specified/basic_shape.rs +++ b/components/style/values/specified/basic_shape.rs @@ -83,7 +83,7 @@ where return false; // already parsed this component } - *component = input.try(|i| U::parse(context, i)).ok(); + *component = input.try_parse(|i| U::parse(context, i)).ok(); component.is_some() } @@ -112,17 +112,17 @@ impl Parse for ClipPath { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if input.try(|i| i.expect_ident_matching("none")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() { return Ok(ClipPath::None); } if is_clip_path_path_enabled(context) { - if let Ok(p) = input.try(|i| Path::parse(context, i)) { + if let Ok(p) = input.try_parse(|i| Path::parse(context, i)) { return Ok(ClipPath::Path(p)); } } - if let Ok(url) = input.try(|i| SpecifiedUrl::parse(context, i)) { + if let Ok(url) = input.try_parse(|i| SpecifiedUrl::parse(context, i)) { return Ok(ClipPath::Url(url)); } @@ -138,11 +138,11 @@ impl Parse for ShapeOutside { ) -> Result> { // Need to parse this here so that `Image::parse_with_cors_anonymous` // doesn't parse it. - if input.try(|i| i.expect_ident_matching("none")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() { return Ok(ShapeOutside::None); } - if let Ok(image) = input.try(|i| Image::parse_with_cors_anonymous(context, i)) { + if let Ok(image) = input.try_parse(|i| Image::parse_with_cors_anonymous(context, i)) { debug_assert_ne!(image, Image::None); return Ok(ShapeOutside::Image(image)); } @@ -189,7 +189,10 @@ impl InsetRect { input: &mut Parser<'i, 't>, ) -> Result> { let rect = Rect::parse_with(context, input, LengthPercentage::parse)?; - let round = if input.try(|i| i.expect_ident_matching("round")).is_ok() { + let round = if input + .try_parse(|i| i.expect_ident_matching("round")) + .is_ok() + { BorderRadius::parse(context, input)? } else { BorderRadius::zero() @@ -214,9 +217,9 @@ impl Circle { input: &mut Parser<'i, 't>, ) -> Result> { let radius = input - .try(|i| ShapeRadius::parse(context, i)) + .try_parse(|i| ShapeRadius::parse(context, i)) .unwrap_or_default(); - let position = if input.try(|i| i.expect_ident_matching("at")).is_ok() { + let position = if input.try_parse(|i| i.expect_ident_matching("at")).is_ok() { Position::parse(context, input)? } else { Position::center() @@ -242,14 +245,14 @@ impl Ellipse { input: &mut Parser<'i, 't>, ) -> Result> { let (a, b) = input - .try(|i| -> Result<_, ParseError> { + .try_parse(|i| -> Result<_, ParseError> { Ok(( ShapeRadius::parse(context, i)?, ShapeRadius::parse(context, i)?, )) }) .unwrap_or_default(); - let position = if input.try(|i| i.expect_ident_matching("at")).is_ok() { + let position = if input.try_parse(|i| i.expect_ident_matching("at")).is_ok() { Position::parse(context, input)? } else { Position::center() @@ -280,7 +283,7 @@ impl Polygon { input: &mut Parser<'i, 't>, ) -> Result> { let fill = input - .try(|i| -> Result<_, ParseError> { + .try_parse(|i| -> Result<_, ParseError> { let fill = FillRule::parse(i)?; i.expect_comma()?; // only eat the comma if there is something before it Ok(fill) @@ -317,7 +320,7 @@ impl Path { input: &mut Parser<'i, 't>, ) -> Result> { let fill = input - .try(|i| -> Result<_, ParseError> { + .try_parse(|i| -> Result<_, ParseError> { let fill = FillRule::parse(i)?; i.expect_comma()?; Ok(fill) diff --git a/components/style/values/specified/border.rs b/components/style/values/specified/border.rs index 28be8177cf48..817a5aadddbf 100644 --- a/components/style/values/specified/border.rs +++ b/components/style/values/specified/border.rs @@ -121,7 +121,8 @@ impl BorderSideWidth { input: &mut Parser<'i, 't>, allow_quirks: AllowQuirks, ) -> Result> { - if let Ok(length) = input.try(|i| NonNegativeLength::parse_quirky(context, i, allow_quirks)) + if let Ok(length) = + input.try_parse(|i| NonNegativeLength::parse_quirky(context, i, allow_quirks)) { return Ok(BorderSideWidth::Length(length)); } @@ -178,10 +179,10 @@ impl Parse for BorderImageSlice { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - let mut fill = input.try(|i| i.expect_ident_matching("fill")).is_ok(); + let mut fill = input.try_parse(|i| i.expect_ident_matching("fill")).is_ok(); let offsets = Rect::parse_with(context, input, NonNegativeNumberOrPercentage::parse)?; if !fill { - fill = input.try(|i| i.expect_ident_matching("fill")).is_ok(); + fill = input.try_parse(|i| i.expect_ident_matching("fill")).is_ok(); } Ok(GenericBorderImageSlice { offsets, fill }) } @@ -193,7 +194,7 @@ impl Parse for BorderRadius { input: &mut Parser<'i, 't>, ) -> Result> { let widths = Rect::parse_with(context, input, NonNegativeLengthPercentage::parse)?; - let heights = if input.try(|i| i.expect_delim('/')).is_ok() { + let heights = if input.try_parse(|i| i.expect_delim('/')).is_ok() { Rect::parse_with(context, input, NonNegativeLengthPercentage::parse)? } else { widths.clone() @@ -301,7 +302,7 @@ impl Parse for BorderImageRepeat { input: &mut Parser<'i, 't>, ) -> Result> { let horizontal = BorderImageRepeatKeyword::parse(input)?; - let vertical = input.try(BorderImageRepeatKeyword::parse).ok(); + let vertical = input.try_parse(BorderImageRepeatKeyword::parse).ok(); Ok(BorderImageRepeat( horizontal, vertical.unwrap_or(horizontal), diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs index 212ea92f10b6..676262500f09 100644 --- a/components/style/values/specified/box.rs +++ b/components/style/values/specified/box.rs @@ -530,30 +530,30 @@ impl Parse for Display { input: &mut Parser<'i, 't>, ) -> Result> { // Parse all combinations of ? and `list-item`? first. - let mut got_list_item = input.try(parse_list_item).is_ok(); + let mut got_list_item = input.try_parse(parse_list_item).is_ok(); let mut inside = if got_list_item { - input.try(parse_display_inside_for_list_item) + input.try_parse(parse_display_inside_for_list_item) } else { - input.try(parse_display_inside) + input.try_parse(parse_display_inside) }; // = ? && [ flow | flow-root ]? && list-item // https://drafts.csswg.org/css-display/#typedef-display-listitem if !got_list_item && is_valid_inside_for_list_item(&inside) { - got_list_item = input.try(parse_list_item).is_ok(); + got_list_item = input.try_parse(parse_list_item).is_ok(); } - let outside = input.try(parse_display_outside); + let outside = input.try_parse(parse_display_outside); if outside.is_ok() { if !got_list_item && (inside.is_err() || is_valid_inside_for_list_item(&inside)) { - got_list_item = input.try(parse_list_item).is_ok(); + got_list_item = input.try_parse(parse_list_item).is_ok(); } if inside.is_err() { inside = if got_list_item { - input.try(parse_display_inside_for_list_item) + input.try_parse(parse_display_inside_for_list_item) } else { - input.try(parse_display_inside) + input.try_parse(parse_display_inside) }; if !got_list_item && is_valid_inside_for_list_item(&inside) { - got_list_item = input.try(parse_list_item).is_ok(); + got_list_item = input.try_parse(parse_list_item).is_ok(); } } } @@ -677,7 +677,8 @@ impl Parse for VerticalAlign { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(lp) = input.try(|i| LengthPercentage::parse_quirky(context, i, AllowQuirks::Yes)) + if let Ok(lp) = + input.try_parse(|i| LengthPercentage::parse_quirky(context, i, AllowQuirks::Yes)) { return Ok(GenericVerticalAlign::Length(lp)); } @@ -697,7 +698,7 @@ impl Parse for AnimationIterationCount { input: &mut ::cssparser::Parser<'i, 't>, ) -> Result> { if input - .try(|input| input.expect_ident_matching("infinite")) + .try_parse(|input| input.expect_ident_matching("infinite")) .is_ok() { return Ok(GenericAnimationIterationCount::Infinite); @@ -761,7 +762,7 @@ impl Parse for AnimationName { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(name) = input.try(|input| KeyframesName::parse(context, input)) { + if let Ok(name) = input.try_parse(|input| KeyframesName::parse(context, input)) { return Ok(AnimationName(Some(name))); } @@ -860,7 +861,7 @@ impl Parse for ScrollSnapType { input: &mut Parser<'i, 't>, ) -> Result> { if input - .try(|input| input.expect_ident_matching("none")) + .try_parse(|input| input.expect_ident_matching("none")) .is_ok() { return Ok(ScrollSnapType::none()); @@ -868,7 +869,7 @@ impl Parse for ScrollSnapType { let axis = ScrollSnapAxis::parse(input)?; let strictness = input - .try(ScrollSnapStrictness::parse) + .try_parse(ScrollSnapStrictness::parse) .unwrap_or(ScrollSnapStrictness::Proximity); Ok(Self { axis, strictness }) } @@ -955,7 +956,9 @@ impl Parse for ScrollSnapAlign { input: &mut Parser<'i, 't>, ) -> Result> { let block = ScrollSnapAlignKeyword::parse(input)?; - let inline = input.try(ScrollSnapAlignKeyword::parse).unwrap_or(block); + let inline = input + .try_parse(ScrollSnapAlignKeyword::parse) + .unwrap_or(block); Ok(ScrollSnapAlign { block, inline }) } } @@ -1150,7 +1153,7 @@ impl Parse for WillChange { input: &mut Parser<'i, 't>, ) -> Result> { if input - .try(|input| input.expect_ident_matching("auto")) + .try_parse(|input| input.expect_ident_matching("auto")) .is_ok() { return Ok(Self::default()); @@ -1238,14 +1241,14 @@ impl Parse for TouchAction { "none" => Ok(TouchAction::NONE), "manipulation" => Ok(TouchAction::MANIPULATION), "pan-x" => { - if input.try(|i| i.expect_ident_matching("pan-y")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("pan-y")).is_ok() { Ok(TouchAction::PAN_X | TouchAction::PAN_Y) } else { Ok(TouchAction::PAN_X) } }, "pan-y" => { - if input.try(|i| i.expect_ident_matching("pan-x")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("pan-x")).is_ok() { Ok(TouchAction::PAN_X | TouchAction::PAN_Y) } else { Ok(TouchAction::PAN_Y) @@ -1323,7 +1326,7 @@ impl Parse for Contain { input: &mut Parser<'i, 't>, ) -> Result> { let mut result = Contain::empty(); - while let Ok(name) = input.try(|i| i.expect_ident_cloned()) { + while let Ok(name) = input.try_parse(|i| i.expect_ident_cloned()) { let flag = match_ignore_ascii_case! { &name, "size" => Some(Contain::SIZE), "layout" => Some(Contain::LAYOUT), diff --git a/components/style/values/specified/color.rs b/components/style/values/specified/color.rs index e697f2523c92..3be551d27a43 100644 --- a/components/style/values/specified/color.rs +++ b/components/style/values/specified/color.rs @@ -356,7 +356,7 @@ impl Parse for Color { input.reset(&start); let compontent_parser = ColorComponentParser(&*context); - match input.try(|i| CSSParserColor::parse_with(&compontent_parser, i)) { + match input.try_parse(|i| CSSParserColor::parse_with(&compontent_parser, i)) { Ok(value) => Ok(match value { CSSParserColor::CurrentColor => Color::CurrentColor, CSSParserColor::RGBA(rgba) => Color::Numeric { @@ -367,7 +367,7 @@ impl Parse for Color { Err(e) => { #[cfg(feature = "gecko")] { - if let Ok(system) = input.try(|i| SystemColor::parse(context, i)) { + if let Ok(system) = input.try_parse(|i| SystemColor::parse(context, i)) { return Ok(Color::System(system)); } } @@ -451,7 +451,7 @@ impl Color { input: &mut Parser<'i, 't>, allow_quirks: AllowQuirks, ) -> Result> { - input.try(|i| Self::parse(context, i)).or_else(|e| { + input.try_parse(|i| Self::parse(context, i)).or_else(|e| { if !allow_quirks.allowed(context.quirks_mode) { return Err(e); } diff --git a/components/style/values/specified/counters.rs b/components/style/values/specified/counters.rs index 0ecc79fb041e..ac097c91a9bc 100644 --- a/components/style/values/specified/counters.rs +++ b/components/style/values/specified/counters.rs @@ -50,7 +50,7 @@ fn parse_counters<'i, 't>( default_value: i32, ) -> Result>, ParseError<'i>> { if input - .try(|input| input.expect_ident_matching("none")) + .try_parse(|input| input.expect_ident_matching("none")) .is_ok() { return Ok(vec![]); @@ -69,7 +69,7 @@ fn parse_counters<'i, 't>( }; let value = input - .try(|input| Integer::parse(context, input)) + .try_parse(|input| Integer::parse(context, input)) .unwrap_or(Integer::new(default_value)); counters.push(CounterPair { name, value }); } @@ -91,7 +91,7 @@ impl Content { #[cfg(feature = "servo")] fn parse_counter_style(_: &ParserContext, input: &mut Parser) -> ListStyleType { input - .try(|input| { + .try_parse(|input| { input.expect_comma()?; ListStyleType::parse(input) }) @@ -101,7 +101,7 @@ impl Content { #[cfg(feature = "gecko")] fn parse_counter_style(context: &ParserContext, input: &mut Parser) -> CounterStyle { input - .try(|input| { + .try_parse(|input| { input.expect_comma()?; CounterStyle::parse(context, input) }) @@ -119,13 +119,13 @@ impl Parse for Content { input: &mut Parser<'i, 't>, ) -> Result> { if input - .try(|input| input.expect_ident_matching("normal")) + .try_parse(|input| input.expect_ident_matching("normal")) .is_ok() { return Ok(generics::Content::Normal); } if input - .try(|input| input.expect_ident_matching("none")) + .try_parse(|input| input.expect_ident_matching("none")) .is_ok() { return Ok(generics::Content::None); @@ -136,7 +136,7 @@ impl Parse for Content { loop { #[cfg(any(feature = "gecko", feature = "servo-layout-2020"))] { - if let Ok(url) = input.try(|i| SpecifiedImageUrl::parse(context, i)) { + if let Ok(url) = input.try_parse(|i| SpecifiedImageUrl::parse(context, i)) { content.push(generics::ContentItem::Url(url)); continue; } diff --git a/components/style/values/specified/easing.rs b/components/style/values/specified/easing.rs index 2344e846ea34..26b921ebdc47 100644 --- a/components/style/values/specified/easing.rs +++ b/components/style/values/specified/easing.rs @@ -21,10 +21,10 @@ impl Parse for TimingFunction { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(keyword) = input.try(TimingKeyword::parse) { + if let Ok(keyword) = input.try_parse(TimingKeyword::parse) { return Ok(GenericTimingFunction::Keyword(keyword)); } - if let Ok(ident) = input.try(|i| i.expect_ident_cloned()) { + if let Ok(ident) = input.try_parse(|i| i.expect_ident_cloned()) { let position = match_ignore_ascii_case! { &ident, "step-start" => StepPosition::Start, "step-end" => StepPosition::End, @@ -57,7 +57,7 @@ impl Parse for TimingFunction { }, "steps" => { let steps = Integer::parse_positive(context, i)?; - let position = i.try(|i| { + let position = i.try_parse(|i| { i.expect_comma()?; StepPosition::parse(context, i) }).unwrap_or(StepPosition::End); diff --git a/components/style/values/specified/effects.rs b/components/style/values/specified/effects.rs index c10445fa62fb..87578b127e65 100644 --- a/components/style/values/specified/effects.rs +++ b/components/style/values/specified/effects.rs @@ -141,7 +141,7 @@ impl Parse for BoxShadow { loop { if !inset { if input - .try(|input| input.expect_ident_matching("inset")) + .try_parse(|input| input.expect_ident_matching("inset")) .is_ok() { inset = true; @@ -156,7 +156,7 @@ impl Parse for BoxShadow { .try::<_, _, ParseError>(|i| Length::parse_non_negative(context, i)) { Ok(blur) => { - let spread = i.try(|i| Length::parse(context, i)).ok(); + let spread = i.try_parse(|i| Length::parse(context, i)).ok(); (Some(blur.into()), spread) }, Err(_) => (None, None), @@ -169,7 +169,7 @@ impl Parse for BoxShadow { } } if color.is_none() { - if let Ok(value) = input.try(|i| Color::parse(context, i)) { + if let Ok(value) = input.try_parse(|i| Color::parse(context, i)) { color = Some(value); continue; } @@ -226,7 +226,7 @@ impl Parse for Filter { ) -> Result> { #[cfg(feature = "gecko")] { - if let Ok(url) = input.try(|i| SpecifiedUrl::parse(context, i)) { + if let Ok(url) = input.try_parse(|i| SpecifiedUrl::parse(context, i)) { return Ok(GenericFilter::Url(url)); } } @@ -242,22 +242,22 @@ impl Parse for Filter { input.parse_nested_block(|i| { match_ignore_ascii_case! { &*function, "blur" => Ok(GenericFilter::Blur( - i.try(|i| NonNegativeLength::parse(context, i)) + i.try_parse(|i| NonNegativeLength::parse(context, i)) .unwrap_or(Zero::zero()), )), "brightness" => Ok(GenericFilter::Brightness( - i.try(|i| NonNegativeFactor::parse(context, i)) + i.try_parse(|i| NonNegativeFactor::parse(context, i)) .unwrap_or(NonNegativeFactor::one()), )), "contrast" => Ok(GenericFilter::Contrast( - i.try(|i| NonNegativeFactor::parse(context, i)) + i.try_parse(|i| NonNegativeFactor::parse(context, i)) .unwrap_or(NonNegativeFactor::one()), )), "grayscale" => { // Values of amount over 100% are allowed but UAs must clamp the values to 1. // https://drafts.fxtf.org/filter-effects/#funcdef-filter-grayscale Ok(GenericFilter::Grayscale( - i.try(|i| ZeroToOneFactor::parse(context, i)) + i.try_parse(|i| ZeroToOneFactor::parse(context, i)) .unwrap_or(ZeroToOneFactor::one()), )) }, @@ -265,7 +265,7 @@ impl Parse for Filter { // We allow unitless zero here, see: // https://github.com/w3c/fxtf-drafts/issues/228 Ok(GenericFilter::HueRotate( - i.try(|i| Angle::parse_with_unitless(context, i)) + i.try_parse(|i| Angle::parse_with_unitless(context, i)) .unwrap_or(Zero::zero()), )) }, @@ -273,7 +273,7 @@ impl Parse for Filter { // Values of amount over 100% are allowed but UAs must clamp the values to 1. // https://drafts.fxtf.org/filter-effects/#funcdef-filter-invert Ok(GenericFilter::Invert( - i.try(|i| ZeroToOneFactor::parse(context, i)) + i.try_parse(|i| ZeroToOneFactor::parse(context, i)) .unwrap_or(ZeroToOneFactor::one()), )) }, @@ -281,19 +281,19 @@ impl Parse for Filter { // Values of amount over 100% are allowed but UAs must clamp the values to 1. // https://drafts.fxtf.org/filter-effects/#funcdef-filter-opacity Ok(GenericFilter::Opacity( - i.try(|i| ZeroToOneFactor::parse(context, i)) + i.try_parse(|i| ZeroToOneFactor::parse(context, i)) .unwrap_or(ZeroToOneFactor::one()), )) }, "saturate" => Ok(GenericFilter::Saturate( - i.try(|i| NonNegativeFactor::parse(context, i)) + i.try_parse(|i| NonNegativeFactor::parse(context, i)) .unwrap_or(NonNegativeFactor::one()), )), "sepia" => { // Values of amount over 100% are allowed but UAs must clamp the values to 1. // https://drafts.fxtf.org/filter-effects/#funcdef-filter-sepia Ok(GenericFilter::Sepia( - i.try(|i| ZeroToOneFactor::parse(context, i)) + i.try_parse(|i| ZeroToOneFactor::parse(context, i)) .unwrap_or(ZeroToOneFactor::one()), )) }, @@ -312,12 +312,14 @@ impl Parse for SimpleShadow { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - let color = input.try(|i| Color::parse(context, i)).ok(); + let color = input.try_parse(|i| Color::parse(context, i)).ok(); let horizontal = Length::parse(context, input)?; let vertical = Length::parse(context, input)?; - let blur = input.try(|i| Length::parse_non_negative(context, i)).ok(); + let blur = input + .try_parse(|i| Length::parse_non_negative(context, i)) + .ok(); let blur = blur.map(NonNegative::); - let color = color.or_else(|| input.try(|i| Color::parse(context, i)).ok()); + let color = color.or_else(|| input.try_parse(|i| Color::parse(context, i)).ok()); Ok(SimpleShadow { color, diff --git a/components/style/values/specified/font.rs b/components/style/values/specified/font.rs index 39233dfc5723..8ab48bfaf211 100644 --- a/components/style/values/specified/font.rs +++ b/components/style/values/specified/font.rs @@ -171,7 +171,7 @@ impl Parse for AbsoluteFontWeight { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(number) = input.try(|input| Number::parse(context, input)) { + if let Ok(number) = input.try_parse(|input| Number::parse(context, input)) { // We could add another AllowedNumericType value, but it doesn't // seem worth it just for a single property with such a weird range, // so we do the clamping here manually. @@ -223,7 +223,7 @@ impl Parse for SpecifiedFontStyle { "normal" => generics::FontStyle::Normal, "italic" => generics::FontStyle::Italic, "oblique" => { - let angle = input.try(|input| Self::parse_angle(context, input)) + let angle = input.try_parse(|input| Self::parse_angle(context, input)) .unwrap_or_else(|_| Self::default_angle()); generics::FontStyle::Oblique(angle) @@ -453,7 +453,9 @@ impl Parse for FontStretch { // // Values less than 0% are not allowed and are treated as parse // errors. - if let Ok(percentage) = input.try(|input| Percentage::parse_non_negative(context, input)) { + if let Ok(percentage) = + input.try_parse(|input| Percentage::parse_non_negative(context, input)) + { return Ok(FontStretch::Stretch(percentage)); } @@ -996,13 +998,13 @@ impl FontSize { input: &mut Parser<'i, 't>, allow_quirks: AllowQuirks, ) -> Result> { - if let Ok(lp) = - input.try(|i| LengthPercentage::parse_non_negative_quirky(context, i, allow_quirks)) + if let Ok(lp) = input + .try_parse(|i| LengthPercentage::parse_non_negative_quirky(context, i, allow_quirks)) { return Ok(FontSize::Length(lp)); } - if let Ok(kw) = input.try(FontSizeKeyword::parse) { + if let Ok(kw) = input.try_parse(FontSizeKeyword::parse) { return Ok(FontSize::Keyword(KeywordInfo::new(kw))); } @@ -1155,7 +1157,7 @@ impl Parse for FontVariantAlternates { input: &mut Parser<'i, 't>, ) -> Result> { if input - .try(|input| input.expect_ident_matching("normal")) + .try_parse(|input| input.expect_ident_matching("normal")) .is_ok() { return Ok(FontVariantAlternates::Value(Default::default())); @@ -1171,7 +1173,7 @@ impl Parse for FontVariantAlternates { parsed_alternates |= $flag; ) ); - while let Ok(_) = input.try(|input| match *input.next()? { + while let Ok(_) = input.try_parse(|input| match *input.next()? { Token::Ident(ref value) if value.eq_ignore_ascii_case("historical-forms") => { check_if_parsed!(input, VariantAlternatesParsingFlags::HISTORICAL_FORMS); alternates.push(VariantAlternates::HistoricalForms); @@ -1386,13 +1388,13 @@ impl Parse for FontVariantEastAsian { let mut result = VariantEastAsian::empty(); if input - .try(|input| input.expect_ident_matching("normal")) + .try_parse(|input| input.expect_ident_matching("normal")) .is_ok() { return Ok(FontVariantEastAsian::Value(result)); } - while let Ok(flag) = input.try(|input| { + while let Ok(flag) = input.try_parse(|input| { Ok( match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?, "jis78" => @@ -1610,19 +1612,19 @@ impl Parse for FontVariantLigatures { let mut result = VariantLigatures::empty(); if input - .try(|input| input.expect_ident_matching("normal")) + .try_parse(|input| input.expect_ident_matching("normal")) .is_ok() { return Ok(FontVariantLigatures::Value(result)); } if input - .try(|input| input.expect_ident_matching("none")) + .try_parse(|input| input.expect_ident_matching("none")) .is_ok() { return Ok(FontVariantLigatures::Value(VariantLigatures::NONE)); } - while let Ok(flag) = input.try(|input| { + while let Ok(flag) = input.try_parse(|input| { Ok( match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?, "common-ligatures" => @@ -1819,13 +1821,13 @@ impl Parse for FontVariantNumeric { let mut result = VariantNumeric::empty(); if input - .try(|input| input.expect_ident_matching("normal")) + .try_parse(|input| input.expect_ident_matching("normal")) .is_ok() { return Ok(FontVariantNumeric::Value(result)); } - while let Ok(flag) = input.try(|input| { + while let Ok(flag) = input.try_parse(|input| { Ok( match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?, "ordinal" => @@ -1969,14 +1971,14 @@ impl Parse for FontSynthesis { "none" => Ok(result), "weight" => { result.weight = true; - if input.try(|input| input.expect_ident_matching("style")).is_ok() { + if input.try_parse(|input| input.expect_ident_matching("style")).is_ok() { result.style = true; } Ok(result) }, "style" => { result.style = true; - if input.try(|input| input.expect_ident_matching("weight")).is_ok() { + if input.try_parse(|input| input.expect_ident_matching("weight")).is_ok() { result.weight = true; } Ok(result) @@ -2096,7 +2098,7 @@ impl Parse for FontLanguageOverride { input: &mut Parser<'i, 't>, ) -> Result> { if input - .try(|input| input.expect_ident_matching("normal")) + .try_parse(|input| input.expect_ident_matching("normal")) .is_ok() { return Ok(FontLanguageOverride::Normal); @@ -2163,7 +2165,7 @@ fn parse_one_feature_value<'i, 't>( context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(integer) = input.try(|i| Integer::parse_non_negative(context, i)) { + if let Ok(integer) = input.try_parse(|i| Integer::parse_non_negative(context, i)) { return Ok(integer); } @@ -2181,7 +2183,7 @@ impl Parse for FeatureTagValue { ) -> Result> { let tag = FontTag::parse(context, input)?; let value = input - .try(|i| parse_one_feature_value(context, i)) + .try_parse(|i| parse_one_feature_value(context, i)) .unwrap_or_else(|_| Integer::new(1)); Ok(Self { tag, value }) @@ -2318,7 +2320,7 @@ impl Parse for MozScriptLevel { input: &mut Parser<'i, 't>, ) -> Result> { // We don't bother to handle calc here. - if let Ok(i) = input.try(|i| i.expect_integer()) { + if let Ok(i) = input.try_parse(|i| i.expect_integer()) { return Ok(MozScriptLevel::Relative(i)); } input.expect_ident_matching("auto")?; diff --git a/components/style/values/specified/grid.rs b/components/style/values/specified/grid.rs index 9c6bf385d31c..cfcba5dca357 100644 --- a/components/style/values/specified/grid.rs +++ b/components/style/values/specified/grid.rs @@ -52,11 +52,11 @@ impl Parse for TrackBreadth { // NonNegativeLengthPercentage instead. // // Though it seems these cannot be animated so it's ~ok. - if let Ok(lp) = input.try(|i| LengthPercentage::parse_non_negative(context, i)) { + if let Ok(lp) = input.try_parse(|i| LengthPercentage::parse_non_negative(context, i)) { return Ok(TrackBreadth::Breadth(lp)); } - if let Ok(f) = input.try(parse_flex) { + if let Ok(f) = input.try_parse(parse_flex) { return Ok(TrackBreadth::Fr(f)); } @@ -69,14 +69,17 @@ impl Parse for TrackSize { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(b) = input.try(|i| TrackBreadth::parse(context, i)) { + if let Ok(b) = input.try_parse(|i| TrackBreadth::parse(context, i)) { return Ok(TrackSize::Breadth(b)); } - if input.try(|i| i.expect_function_matching("minmax")).is_ok() { + if input + .try_parse(|i| i.expect_function_matching("minmax")) + .is_ok() + { return input.parse_nested_block(|input| { let inflexible_breadth = - match input.try(|i| LengthPercentage::parse_non_negative(context, i)) { + match input.try_parse(|i| LengthPercentage::parse_non_negative(context, i)) { Ok(lp) => TrackBreadth::Breadth(lp), Err(..) => TrackBreadth::parse_keyword(input)?, }; @@ -119,7 +122,7 @@ pub fn parse_line_names<'i, 't>( input.expect_square_bracket_block()?; input.parse_nested_block(|input| { let mut values = vec![]; - while let Ok((loc, ident)) = input.try(|i| -> Result<_, CssParseError<()>> { + while let Ok((loc, ident)) = input.try_parse(|i| -> Result<_, CssParseError<()>> { Ok((i.current_source_location(), i.expect_ident_cloned()?)) }) { let ident = CustomIdent::from_ident(loc, &ident, &["span", "auto"])?; @@ -150,7 +153,7 @@ impl TrackRepeat { input: &mut Parser<'i, 't>, ) -> Result<(Self, RepeatType), ParseError<'i>> { input - .try(|i| i.expect_function_matching("repeat").map_err(|e| e.into())) + .try_parse(|i| i.expect_function_matching("repeat").map_err(|e| e.into())) .and_then(|_| { input.parse_nested_block(|input| { let count = RepeatCount::parse(context, input)?; @@ -169,8 +172,8 @@ impl TrackRepeat { let mut current_names; loop { - current_names = input.try(parse_line_names).unwrap_or_default(); - if let Ok(track_size) = input.try(|i| TrackSize::parse(context, i)) { + current_names = input.try_parse(parse_line_names).unwrap_or_default(); + if let Ok(track_size) = input.try_parse(|i| TrackSize::parse(context, i)) { if !track_size.is_fixed() { if is_auto { // should be for @@ -224,8 +227,9 @@ impl Parse for TrackList { // assume that everything is . This flag is useful when we encounter let mut at_least_one_not_fixed = false; loop { - current_names.extend_from_slice(&mut input.try(parse_line_names).unwrap_or_default()); - if let Ok(track_size) = input.try(|i| TrackSize::parse(context, i)) { + current_names + .extend_from_slice(&mut input.try_parse(parse_line_names).unwrap_or_default()); + if let Ok(track_size) = input.try_parse(|i| TrackSize::parse(context, i)) { if !track_size.is_fixed() { at_least_one_not_fixed = true; if auto_repeat_index.is_some() { @@ -238,7 +242,7 @@ impl Parse for TrackList { names.push(vec.into()); values.push(TrackListValue::TrackSize(track_size)); } else if let Ok((repeat, type_)) = - input.try(|i| TrackRepeat::parse_with_repeat_type(context, i)) + input.try_parse(|i| TrackRepeat::parse_with_repeat_type(context, i)) { match type_ { RepeatType::Normal => { @@ -312,7 +316,7 @@ impl Parse for GridTemplateComponent { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if input.try(|i| i.expect_ident_matching("none")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() { return Ok(GridTemplateComponent::None); } @@ -327,12 +331,15 @@ impl GridTemplateComponent { input: &mut Parser<'i, 't>, ) -> Result> { if allow_grid_template_subgrids() { - if let Ok(t) = input.try(|i| LineNameList::parse(context, i)) { + if let Ok(t) = input.try_parse(|i| LineNameList::parse(context, i)) { return Ok(GridTemplateComponent::Subgrid(Box::new(t))); } } if allow_grid_template_masonry() { - if input.try(|i| i.expect_ident_matching("masonry")).is_ok() { + if input + .try_parse(|i| i.expect_ident_matching("masonry")) + .is_ok() + { return Ok(GridTemplateComponent::Masonry); } } diff --git a/components/style/values/specified/image.rs b/components/style/values/specified/image.rs index 59250c45a6f2..088a4ace687e 100644 --- a/components/style/values/specified/image.rs +++ b/components/style/values/specified/image.rs @@ -132,24 +132,24 @@ impl Parse for Image { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if input.try(|i| i.expect_ident_matching("none")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() { return Ok(generic::Image::None); } - if let Ok(url) = input.try(|input| SpecifiedImageUrl::parse(context, input)) { + if let Ok(url) = input.try_parse(|input| SpecifiedImageUrl::parse(context, input)) { return Ok(generic::Image::Url(url)); } - if let Ok(gradient) = input.try(|i| Gradient::parse(context, i)) { + if let Ok(gradient) = input.try_parse(|i| Gradient::parse(context, i)) { return Ok(generic::Image::Gradient(Box::new(gradient))); } #[cfg(feature = "servo-layout-2013")] { - if let Ok(paint_worklet) = input.try(|i| PaintWorklet::parse(context, i)) { + if let Ok(paint_worklet) = input.try_parse(|i| PaintWorklet::parse(context, i)) { return Ok(generic::Image::PaintWorklet(paint_worklet)); } } #[cfg(feature = "gecko")] { - if let Ok(image_rect) = input.try(|input| MozImageRect::parse(context, input)) { + if let Ok(image_rect) = input.try_parse(|input| MozImageRect::parse(context, input)) { return Ok(generic::Image::Rect(Box::new(image_rect))); } Ok(generic::Image::Element(Image::parse_element(input)?)) @@ -171,7 +171,7 @@ impl Image { /// Parses a `-moz-element(# )`. #[cfg(feature = "gecko")] fn parse_element<'i, 't>(input: &mut Parser<'i, 't>) -> Result> { - input.try(|i| i.expect_function_matching("-moz-element"))?; + input.try_parse(|i| i.expect_function_matching("-moz-element"))?; let location = input.current_source_location(); input.parse_nested_block(|i| match *i.next()? { Token::IDHash(ref id) => Ok(Atom::from(id.as_ref())), @@ -189,7 +189,7 @@ impl Image { input: &mut Parser<'i, 't>, ) -> Result> { if let Ok(url) = - input.try(|input| SpecifiedImageUrl::parse_with_cors_anonymous(context, input)) + input.try_parse(|input| SpecifiedImageUrl::parse_with_cors_anonymous(context, input)) { return Ok(generic::Image::Url(url)); } @@ -332,7 +332,7 @@ impl Gradient { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - input.try(|i| { + input.try_parse(|i| { let x = Component::parse(context, i)?; let y = Component::parse(context, i)?; @@ -450,7 +450,7 @@ impl Gradient { reverse_stops: bool, ) -> Result> { let mut items = input - .try(|i| { + .try_parse(|i| { i.expect_comma()?; i.parse_comma_separated(|i| { let function = i.expect_function()?.clone(); @@ -551,18 +551,19 @@ impl Gradient { repeating: bool, mut compat_mode: GradientCompatMode, ) -> Result> { - let direction = - if let Ok(d) = input.try(|i| LineDirection::parse(context, i, &mut compat_mode)) { - input.expect_comma()?; - d - } else { - match compat_mode { - GradientCompatMode::Modern => { - LineDirection::Vertical(VerticalPositionKeyword::Bottom) - }, - _ => LineDirection::Vertical(VerticalPositionKeyword::Top), - } - }; + let direction = if let Ok(d) = + input.try_parse(|i| LineDirection::parse(context, i, &mut compat_mode)) + { + input.expect_comma()?; + d + } else { + match compat_mode { + GradientCompatMode::Modern => { + LineDirection::Vertical(VerticalPositionKeyword::Bottom) + }, + _ => LineDirection::Vertical(VerticalPositionKeyword::Top), + } + }; let items = Gradient::parse_stops(context, input)?; Ok(Gradient::Linear { @@ -582,16 +583,16 @@ impl Gradient { ) -> Result> { let (shape, position) = match compat_mode { GradientCompatMode::Modern => { - let shape = input.try(|i| EndingShape::parse(context, i, compat_mode)); - let position = input.try(|i| { + let shape = input.try_parse(|i| EndingShape::parse(context, i, compat_mode)); + let position = input.try_parse(|i| { i.expect_ident_matching("at")?; Position::parse(context, i) }); (shape, position.ok()) }, _ => { - let position = input.try(|i| Position::parse(context, i)); - let shape = input.try(|i| { + let position = input.try_parse(|i| Position::parse(context, i)); + let shape = input.try_parse(|i| { if position.is_ok() { i.expect_comma()?; } @@ -626,13 +627,13 @@ impl Gradient { input: &mut Parser<'i, 't>, repeating: bool, ) -> Result> { - let angle = input.try(|i| { + let angle = input.try_parse(|i| { i.expect_ident_matching("from")?; // Spec allows unitless zero start angles // https://drafts.csswg.org/css-images-4/#valdef-conic-gradient-angle Angle::parse_with_unitless(context, i) }); - let position = input.try(|i| { + let position = input.try_parse(|i| { i.expect_ident_matching("at")?; Position::parse(context, i) }); @@ -713,12 +714,12 @@ impl LineDirection { ) -> Result> { // Gradients allow unitless zero angles as an exception, see: // https://github.com/w3c/csswg-drafts/issues/1162 - if let Ok(angle) = input.try(|i| Angle::parse_with_unitless(context, i)) { + if let Ok(angle) = input.try_parse(|i| Angle::parse_with_unitless(context, i)) { return Ok(LineDirection::Angle(angle)); } - input.try(|i| { - let to_ident = i.try(|i| i.expect_ident_matching("to")); + input.try_parse(|i| { + let to_ident = i.try_parse(|i| i.expect_ident_matching("to")); match *compat_mode { // `to` keyword is mandatory in modern syntax. GradientCompatMode::Modern => to_ident?, @@ -738,14 +739,14 @@ impl LineDirection { _ => {}, } - if let Ok(x) = i.try(HorizontalPositionKeyword::parse) { - if let Ok(y) = i.try(VerticalPositionKeyword::parse) { + if let Ok(x) = i.try_parse(HorizontalPositionKeyword::parse) { + if let Ok(y) = i.try_parse(VerticalPositionKeyword::parse) { return Ok(LineDirection::Corner(x, y)); } return Ok(LineDirection::Horizontal(x)); } let y = VerticalPositionKeyword::parse(i)?; - if let Ok(x) = i.try(HorizontalPositionKeyword::parse) { + if let Ok(x) = i.try_parse(HorizontalPositionKeyword::parse) { return Ok(LineDirection::Corner(x, y)); } Ok(LineDirection::Vertical(y)) @@ -759,19 +760,28 @@ impl EndingShape { input: &mut Parser<'i, 't>, compat_mode: GradientCompatMode, ) -> Result> { - if let Ok(extent) = input.try(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode)) { - if input.try(|i| i.expect_ident_matching("circle")).is_ok() { + if let Ok(extent) = input.try_parse(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode)) + { + if input + .try_parse(|i| i.expect_ident_matching("circle")) + .is_ok() + { return Ok(generic::EndingShape::Circle(Circle::Extent(extent))); } - let _ = input.try(|i| i.expect_ident_matching("ellipse")); + let _ = input.try_parse(|i| i.expect_ident_matching("ellipse")); return Ok(generic::EndingShape::Ellipse(Ellipse::Extent(extent))); } - if input.try(|i| i.expect_ident_matching("circle")).is_ok() { - if let Ok(extent) = input.try(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode)) { + if input + .try_parse(|i| i.expect_ident_matching("circle")) + .is_ok() + { + if let Ok(extent) = + input.try_parse(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode)) + { return Ok(generic::EndingShape::Circle(Circle::Extent(extent))); } if compat_mode == GradientCompatMode::Modern { - if let Ok(length) = input.try(|i| NonNegativeLength::parse(context, i)) { + if let Ok(length) = input.try_parse(|i| NonNegativeLength::parse(context, i)) { return Ok(generic::EndingShape::Circle(Circle::Radius(length))); } } @@ -779,12 +789,17 @@ impl EndingShape { ShapeExtent::FarthestCorner, ))); } - if input.try(|i| i.expect_ident_matching("ellipse")).is_ok() { - if let Ok(extent) = input.try(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode)) { + if input + .try_parse(|i| i.expect_ident_matching("ellipse")) + .is_ok() + { + if let Ok(extent) = + input.try_parse(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode)) + { return Ok(generic::EndingShape::Ellipse(Ellipse::Extent(extent))); } if compat_mode == GradientCompatMode::Modern { - let pair: Result<_, ParseError> = input.try(|i| { + let pair: Result<_, ParseError> = input.try_parse(|i| { let x = NonNegativeLengthPercentage::parse(context, i)?; let y = NonNegativeLengthPercentage::parse(context, i)?; Ok((x, y)) @@ -797,10 +812,10 @@ impl EndingShape { ShapeExtent::FarthestCorner, ))); } - if let Ok(length) = input.try(|i| NonNegativeLength::parse(context, i)) { - if let Ok(y) = input.try(|i| NonNegativeLengthPercentage::parse(context, i)) { + if let Ok(length) = input.try_parse(|i| NonNegativeLength::parse(context, i)) { + if let Ok(y) = input.try_parse(|i| NonNegativeLengthPercentage::parse(context, i)) { if compat_mode == GradientCompatMode::Modern { - let _ = input.try(|i| i.expect_ident_matching("ellipse")); + let _ = input.try_parse(|i| i.expect_ident_matching("ellipse")); } return Ok(generic::EndingShape::Ellipse(Ellipse::Radii( NonNegative(LengthPercentage::from(length.0)), @@ -808,7 +823,7 @@ impl EndingShape { ))); } if compat_mode == GradientCompatMode::Modern { - let y = input.try(|i| { + let y = input.try_parse(|i| { i.expect_ident_matching("ellipse")?; NonNegativeLengthPercentage::parse(context, i) }); @@ -818,16 +833,16 @@ impl EndingShape { y, ))); } - let _ = input.try(|i| i.expect_ident_matching("circle")); + let _ = input.try_parse(|i| i.expect_ident_matching("circle")); } return Ok(generic::EndingShape::Circle(Circle::Radius(length))); } - input.try(|i| { + input.try_parse(|i| { let x = Percentage::parse_non_negative(context, i)?; - let y = if let Ok(y) = i.try(|i| NonNegativeLengthPercentage::parse(context, i)) { + let y = if let Ok(y) = i.try_parse(|i| NonNegativeLengthPercentage::parse(context, i)) { if compat_mode == GradientCompatMode::Modern { - let _ = i.try(|i| i.expect_ident_matching("ellipse")); + let _ = i.try_parse(|i| i.expect_ident_matching("ellipse")); } y } else { @@ -875,7 +890,7 @@ impl generic::GradientItem { loop { input.parse_until_before(Delimiter::Comma, |input| { if seen_stop { - if let Ok(hint) = input.try(|i| parse_position(context, i)) { + if let Ok(hint) = input.try_parse(|i| parse_position(context, i)) { seen_stop = false; items.push(generic::GradientItem::InterpolationHint(hint)); return Ok(()); @@ -884,7 +899,7 @@ impl generic::GradientItem { let stop = generic::ColorStop::parse(context, input, parse_position)?; - if let Ok(multi_position) = input.try(|i| parse_position(context, i)) { + if let Ok(multi_position) = input.try_parse(|i| parse_position(context, i)) { let stop_color = stop.color.clone(); items.push(stop.into_item()); items.push( @@ -927,7 +942,7 @@ impl generic::ColorStop { ) -> Result> { Ok(generic::ColorStop { color: Color::parse(context, input)?, - position: input.try(|i| parse_position(context, i)).ok(), + position: input.try_parse(|i| parse_position(context, i)).ok(), }) } } @@ -941,7 +956,7 @@ impl Parse for PaintWorklet { input.parse_nested_block(|input| { let name = Atom::from(&**input.expect_ident()?); let arguments = input - .try(|input| { + .try_parse(|input| { input.expect_comma()?; input.parse_comma_separated(|input| SpecifiedValue::parse(input)) }) @@ -965,7 +980,7 @@ impl Parse for MozImageRect { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - input.try(|i| i.expect_function_matching("-moz-image-rect"))?; + input.try_parse(|i| i.expect_function_matching("-moz-image-rect"))?; input.parse_nested_block(|i| { let string = i.expect_url_or_string()?; let url = SpecifiedImageUrl::parse_from_string( diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index 0b1bf0b68a71..bf81a4d5e3d2 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -1226,12 +1226,12 @@ impl Size { ) -> Result> { #[cfg(feature = "gecko")] { - if let Ok(l) = input.try(computed::ExtremumLength::parse) { + if let Ok(l) = input.try_parse(computed::ExtremumLength::parse) { return Ok(GenericSize::ExtremumLength(l)); } } - if input.try(|i| i.expect_ident_matching("auto")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("auto")).is_ok() { return Ok(GenericSize::Auto); } @@ -1267,12 +1267,12 @@ impl MaxSize { ) -> Result> { #[cfg(feature = "gecko")] { - if let Ok(l) = input.try(computed::ExtremumLength::parse) { + if let Ok(l) = input.try_parse(computed::ExtremumLength::parse) { return Ok(GenericMaxSize::ExtremumLength(l)); } } - if input.try(|i| i.expect_ident_matching("none")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() { return Ok(GenericMaxSize::None); } diff --git a/components/style/values/specified/list.rs b/components/style/values/specified/list.rs index 1c93f8e8a589..5d31c0b34d24 100644 --- a/components/style/values/specified/list.rs +++ b/components/style/values/specified/list.rs @@ -75,10 +75,10 @@ impl Parse for ListStyleType { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(style) = input.try(|i| CounterStyle::parse(context, i)) { + if let Ok(style) = input.try_parse(|i| CounterStyle::parse(context, i)) { return Ok(ListStyleType::CounterStyle(style)); } - if input.try(|i| i.expect_ident_matching("none")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() { return Ok(ListStyleType::None); } Ok(ListStyleType::String( @@ -155,14 +155,14 @@ impl Parse for Quotes { input: &mut Parser<'i, 't>, ) -> Result> { if input - .try(|input| input.expect_ident_matching("auto")) + .try_parse(|input| input.expect_ident_matching("auto")) .is_ok() { return Ok(Quotes::Auto); } if input - .try(|input| input.expect_ident_matching("none")) + .try_parse(|input| input.expect_ident_matching("none")) .is_ok() { return Ok(Quotes::QuoteList(QuoteList::default())); diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 9d90ffab1b0f..8ddca48d599f 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -50,7 +50,7 @@ pub use self::effects::{BoxShadow, Filter, SimpleShadow}; pub use self::flex::FlexBasis; pub use self::font::{FontFamily, FontLanguageOverride, FontStyle}; pub use self::font::{FontFeatureSettings, FontVariantLigatures, FontVariantNumeric}; -pub use self::font::{FontSize, FontSizeAdjust, FontStretch, FontSynthesis, FontSizeKeyword}; +pub use self::font::{FontSize, FontSizeAdjust, FontSizeKeyword, FontStretch, FontSynthesis}; pub use self::font::{FontVariantAlternates, FontWeight}; pub use self::font::{FontVariantEastAsian, FontVariationSettings}; pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XLang, XTextZoom}; @@ -148,7 +148,7 @@ impl AngleOrPercentage { input: &mut Parser<'i, 't>, allow_unitless_zero: AllowUnitlessZeroAngle, ) -> Result> { - if let Ok(per) = input.try(|i| Percentage::parse(context, i)) { + if let Ok(per) = input.try_parse(|i| Percentage::parse(context, i)) { return Ok(AngleOrPercentage::Percentage(per)); } @@ -431,7 +431,9 @@ impl NumberOrPercentage { input: &mut Parser<'i, 't>, type_: AllowedNumericType, ) -> Result> { - if let Ok(per) = input.try(|i| Percentage::parse_with_clamping_mode(context, i, type_)) { + if let Ok(per) = + input.try_parse(|i| Percentage::parse_with_clamping_mode(context, i, type_)) + { return Ok(NumberOrPercentage::Percentage(per)); } @@ -750,7 +752,7 @@ impl ClipRect { let bottom; let left; - if input.try(|input| input.expect_comma()).is_ok() { + if input.try_parse(|input| input.expect_comma()).is_ok() { right = parse_argument(context, input, allow_quirks)?; input.expect_comma()?; bottom = parse_argument(context, input, allow_quirks)?; @@ -782,7 +784,7 @@ impl ClipRectOrAuto { input: &mut Parser<'i, 't>, allow_quirks: AllowQuirks, ) -> Result> { - if let Ok(v) = input.try(|i| ClipRect::parse_quirky(context, i, allow_quirks)) { + if let Ok(v) = input.try_parse(|i| ClipRect::parse_quirky(context, i, allow_quirks)) { return Ok(generics::GenericClipRectOrAuto::Rect(v)); } input.expect_ident_matching("auto")?; @@ -866,8 +868,8 @@ impl Attr { ) -> Result> { // Syntax is `[namespace? `|`]? ident` // no spaces allowed - let first = input.try(|i| i.expect_ident_cloned()).ok(); - if let Ok(token) = input.try(|i| i.next_including_whitespace().map(|t| t.clone())) { + let first = input.try_parse(|i| i.expect_ident_cloned()).ok(); + if let Ok(token) = input.try_parse(|i| i.next_including_whitespace().map(|t| t.clone())) { match token { Token::Delim('|') => { let location = input.current_source_location(); diff --git a/components/style/values/specified/motion.rs b/components/style/values/specified/motion.rs index 2351acecc6a2..7831b78afe68 100644 --- a/components/style/values/specified/motion.rs +++ b/components/style/values/specified/motion.rs @@ -39,18 +39,20 @@ impl Parse for RayFunction { let mut contain = false; loop { if angle.is_none() { - angle = input.try(|i| Angle::parse(context, i)).ok(); + angle = input.try_parse(|i| Angle::parse(context, i)).ok(); } if size.is_none() { - size = input.try(RaySize::parse).ok(); + size = input.try_parse(RaySize::parse).ok(); if size.is_some() { continue; } } if !contain { - contain = input.try(|i| i.expect_ident_matching("contain")).is_ok(); + contain = input + .try_parse(|i| i.expect_ident_matching("contain")) + .is_ok(); if contain { continue; } @@ -76,7 +78,7 @@ impl Parse for OffsetPath { input: &mut Parser<'i, 't>, ) -> Result> { // Parse none. - if input.try(|i| i.expect_ident_matching("none")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() { return Ok(OffsetPath::none()); } @@ -166,12 +168,12 @@ impl Parse for OffsetRotate { input: &mut Parser<'i, 't>, ) -> Result> { let location = input.current_source_location(); - let mut direction = input.try(OffsetRotateDirection::parse); - let angle = input.try(|i| Angle::parse(context, i)); + let mut direction = input.try_parse(OffsetRotateDirection::parse); + let angle = input.try_parse(|i| Angle::parse(context, i)); if direction.is_err() { // The direction and angle could be any order, so give it a change to parse // direction again. - direction = input.try(OffsetRotateDirection::parse); + direction = input.try_parse(OffsetRotateDirection::parse); } if direction.is_err() && angle.is_err() { diff --git a/components/style/values/specified/outline.rs b/components/style/values/specified/outline.rs index b981d8068e74..6e5382d4c2b7 100644 --- a/components/style/values/specified/outline.rs +++ b/components/style/values/specified/outline.rs @@ -56,7 +56,7 @@ impl Parse for OutlineStyle { _context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(border_style) = input.try(BorderStyle::parse) { + if let Ok(border_style) = input.try_parse(BorderStyle::parse) { if let BorderStyle::Hidden = border_style { return Err(input .new_custom_error(SelectorParseErrorKind::UnexpectedIdent("hidden".into()))); diff --git a/components/style/values/specified/position.rs b/components/style/values/specified/position.rs index c2998de328b5..72886b2d7b12 100644 --- a/components/style/values/specified/position.rs +++ b/components/style/values/specified/position.rs @@ -116,28 +116,31 @@ impl Position { input: &mut Parser<'i, 't>, allow_quirks: AllowQuirks, ) -> Result> { - match input.try(|i| PositionComponent::parse_quirky(context, i, allow_quirks)) { + match input.try_parse(|i| PositionComponent::parse_quirky(context, i, allow_quirks)) { Ok(x_pos @ PositionComponent::Center) => { if let Ok(y_pos) = - input.try(|i| PositionComponent::parse_quirky(context, i, allow_quirks)) + input.try_parse(|i| PositionComponent::parse_quirky(context, i, allow_quirks)) { return Ok(Self::new(x_pos, y_pos)); } let x_pos = input - .try(|i| PositionComponent::parse_quirky(context, i, allow_quirks)) + .try_parse(|i| PositionComponent::parse_quirky(context, i, allow_quirks)) .unwrap_or(x_pos); let y_pos = PositionComponent::Center; return Ok(Self::new(x_pos, y_pos)); }, Ok(PositionComponent::Side(x_keyword, lp)) => { - if input.try(|i| i.expect_ident_matching("center")).is_ok() { + if input + .try_parse(|i| i.expect_ident_matching("center")) + .is_ok() + { let x_pos = PositionComponent::Side(x_keyword, lp); let y_pos = PositionComponent::Center; return Ok(Self::new(x_pos, y_pos)); } - if let Ok(y_keyword) = input.try(VerticalPositionKeyword::parse) { + if let Ok(y_keyword) = input.try_parse(VerticalPositionKeyword::parse) { let y_lp = input - .try(|i| LengthPercentage::parse_quirky(context, i, allow_quirks)) + .try_parse(|i| LengthPercentage::parse_quirky(context, i, allow_quirks)) .ok(); let x_pos = PositionComponent::Side(x_keyword, lp); let y_pos = PositionComponent::Side(y_keyword, y_lp); @@ -148,30 +151,30 @@ impl Position { return Ok(Self::new(x_pos, y_pos)); }, Ok(x_pos @ PositionComponent::Length(_)) => { - if let Ok(y_keyword) = input.try(VerticalPositionKeyword::parse) { + if let Ok(y_keyword) = input.try_parse(VerticalPositionKeyword::parse) { let y_pos = PositionComponent::Side(y_keyword, None); return Ok(Self::new(x_pos, y_pos)); } if let Ok(y_lp) = - input.try(|i| LengthPercentage::parse_quirky(context, i, allow_quirks)) + input.try_parse(|i| LengthPercentage::parse_quirky(context, i, allow_quirks)) { let y_pos = PositionComponent::Length(y_lp); return Ok(Self::new(x_pos, y_pos)); } let y_pos = PositionComponent::Center; - let _ = input.try(|i| i.expect_ident_matching("center")); + let _ = input.try_parse(|i| i.expect_ident_matching("center")); return Ok(Self::new(x_pos, y_pos)); }, Err(_) => {}, } let y_keyword = VerticalPositionKeyword::parse(input)?; - let lp_and_x_pos: Result<_, ParseError> = input.try(|i| { + let lp_and_x_pos: Result<_, ParseError> = input.try_parse(|i| { let y_lp = i - .try(|i| LengthPercentage::parse_quirky(context, i, allow_quirks)) + .try_parse(|i| LengthPercentage::parse_quirky(context, i, allow_quirks)) .ok(); - if let Ok(x_keyword) = i.try(HorizontalPositionKeyword::parse) { + if let Ok(x_keyword) = i.try_parse(HorizontalPositionKeyword::parse) { let x_lp = i - .try(|i| LengthPercentage::parse_quirky(context, i, allow_quirks)) + .try_parse(|i| LengthPercentage::parse_quirky(context, i, allow_quirks)) .ok(); let x_pos = PositionComponent::Side(x_keyword, x_lp); return Ok((y_lp, x_pos)); @@ -250,15 +253,20 @@ impl PositionComponent { input: &mut Parser<'i, 't>, allow_quirks: AllowQuirks, ) -> Result> { - if input.try(|i| i.expect_ident_matching("center")).is_ok() { + if input + .try_parse(|i| i.expect_ident_matching("center")) + .is_ok() + { return Ok(PositionComponent::Center); } - if let Ok(lp) = input.try(|i| LengthPercentage::parse_quirky(context, i, allow_quirks)) { + if let Ok(lp) = + input.try_parse(|i| LengthPercentage::parse_quirky(context, i, allow_quirks)) + { return Ok(PositionComponent::Length(lp)); } let keyword = S::parse(context, input)?; let lp = input - .try(|i| LengthPercentage::parse_quirky(context, i, allow_quirks)) + .try_parse(|i| LengthPercentage::parse_quirky(context, i, allow_quirks)) .ok(); Ok(PositionComponent::Side(keyword, lp)) } @@ -730,7 +738,7 @@ impl Parse for TemplateAreas { ) -> Result> { let mut strings = vec![]; while let Ok(string) = - input.try(|i| i.expect_string().map(|s| s.as_ref().to_owned().into())) + input.try_parse(|i| i.expect_string().map(|s| s.as_ref().to_owned().into())) { strings.push(string); } @@ -889,10 +897,10 @@ impl Parse for AspectRatio { use crate::values::generics::position::PreferredRatio; let location = input.current_source_location(); - let mut auto = input.try(|i| i.expect_ident_matching("auto")); - let ratio = input.try(|i| Ratio::parse(context, i)); + let mut auto = input.try_parse(|i| i.expect_ident_matching("auto")); + let ratio = input.try_parse(|i| Ratio::parse(context, i)); if auto.is_err() { - auto = input.try(|i| i.expect_ident_matching("auto")); + auto = input.try_parse(|i| i.expect_ident_matching("auto")); } if auto.is_err() && ratio.is_err() { diff --git a/components/style/values/specified/source_size_list.rs b/components/style/values/specified/source_size_list.rs index 3cb558809ad8..edb2c09f73e2 100644 --- a/components/style/values/specified/source_size_list.rs +++ b/components/style/values/specified/source_size_list.rs @@ -87,7 +87,7 @@ impl Parse for SourceSizeOrLength { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(size) = input.try(|input| SourceSize::parse(context, input)) { + if let Ok(size) = input.try_parse(|input| SourceSize::parse(context, input)) { return Ok(SourceSizeOrLength::SourceSize(size)); } diff --git a/components/style/values/specified/svg.rs b/components/style/values/specified/svg.rs index cff899fce354..abc6587239ce 100644 --- a/components/style/values/specified/svg.rs +++ b/components/style/values/specified/svg.rs @@ -48,7 +48,8 @@ macro_rules! parse_svg_length { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(lp) = input.try(|i| <$lp>::parse_quirky(context, i, AllowQuirks::Always)) + if let Ok(lp) = + input.try_parse(|i| <$lp>::parse_quirky(context, i, AllowQuirks::Always)) { return Ok(generic::SVGLength::LengthPercentage(lp)); } @@ -71,7 +72,7 @@ impl Parse for SVGStrokeDashArray { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(values) = input.try(|i| { + if let Ok(values) = input.try_parse(|i| { CommaWithSpace::parse(i, |i| { NonNegativeLengthPercentage::parse_quirky(context, i, AllowQuirks::Always) }) @@ -161,7 +162,7 @@ impl Parse for SVGPaintOrder { _context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(()) = input.try(|i| i.expect_ident_matching("normal")) { + if let Ok(()) = input.try_parse(|i| i.expect_ident_matching("normal")) { return Ok(SVGPaintOrder::normal()); } @@ -172,7 +173,7 @@ impl Parse for SVGPaintOrder { let mut pos = 0; loop { - let result: Result<_, ParseError> = input.try(|input| { + let result: Result<_, ParseError> = input.try_parse(|input| { try_match_ident_ignore_ascii_case! { input, "fill" => Ok(PaintOrder::Fill), "stroke" => Ok(PaintOrder::Stroke), diff --git a/components/style/values/specified/text.rs b/components/style/values/specified/text.rs index bee3c665840f..7c5c712eb3e0 100644 --- a/components/style/values/specified/text.rs +++ b/components/style/values/specified/text.rs @@ -41,11 +41,16 @@ impl Parse for InitialLetter { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if input.try(|i| i.expect_ident_matching("normal")).is_ok() { + if input + .try_parse(|i| i.expect_ident_matching("normal")) + .is_ok() + { return Ok(GenericInitialLetter::Normal); } let size = Number::parse_at_least_one(context, input)?; - let sink = input.try(|i| Integer::parse_positive(context, i)).ok(); + let sink = input + .try_parse(|i| Integer::parse_positive(context, i)) + .ok(); Ok(GenericInitialLetter::Specified(size, sink)) } } @@ -161,7 +166,7 @@ impl Parse for TextOverflow { ) -> Result> { let first = TextOverflowSide::parse(context, input)?; let second = input - .try(|input| TextOverflowSide::parse(context, input)) + .try_parse(|input| TextOverflowSide::parse(context, input)) .ok(); Ok(TextOverflow { first, second }) } @@ -251,7 +256,7 @@ impl Parse for TextDecorationLine { // ensure we don't return an error if we don't consume the whole thing // because we find an invalid identifier or other kind of token. loop { - let flag: Result<_, ParseError<'i>> = input.try(|input| { + let flag: Result<_, ParseError<'i>> = input.try_parse(|input| { let flag = try_match_ident_ignore_ascii_case! { input, "none" if result.is_empty() => TextDecorationLine::NONE, "underline" => TextDecorationLine::UNDERLINE, @@ -791,22 +796,22 @@ impl Parse for TextEmphasisStyle { input: &mut Parser<'i, 't>, ) -> Result> { if input - .try(|input| input.expect_ident_matching("none")) + .try_parse(|input| input.expect_ident_matching("none")) .is_ok() { return Ok(TextEmphasisStyle::None); } - if let Ok(s) = input.try(|i| i.expect_string().map(|s| s.as_ref().to_owned())) { + if let Ok(s) = input.try_parse(|i| i.expect_string().map(|s| s.as_ref().to_owned())) { // Handle return Ok(TextEmphasisStyle::String(s.into())); } // Handle a pair of keywords - let mut shape = input.try(TextEmphasisShapeKeyword::parse).ok(); - let fill = input.try(TextEmphasisFillMode::parse).ok(); + let mut shape = input.try_parse(TextEmphasisShapeKeyword::parse).ok(); + let fill = input.try_parse(TextEmphasisFillMode::parse).ok(); if shape.is_none() { - shape = input.try(TextEmphasisShapeKeyword::parse).ok(); + shape = input.try_parse(TextEmphasisShapeKeyword::parse).ok(); } if shape.is_none() && fill.is_none() { @@ -922,7 +927,7 @@ impl Parse for TextEmphasisPosition { input: &mut Parser<'i, 't>, ) -> Result> { if let Ok(horizontal) = - input.try(|input| TextEmphasisHorizontalWritingModeValue::parse(input)) + input.try_parse(|input| TextEmphasisHorizontalWritingModeValue::parse(input)) { let vertical = TextEmphasisVerticalWritingModeValue::parse(input)?; Ok(TextEmphasisPosition(horizontal, vertical)) diff --git a/components/style/values/specified/transform.rs b/components/style/values/specified/transform.rs index a61f982cd2dc..ba2be4ee8d35 100644 --- a/components/style/values/specified/transform.rs +++ b/components/style/values/specified/transform.rs @@ -68,7 +68,7 @@ impl Transform { use style_traits::{Separator, Space}; if input - .try(|input| input.expect_ident_matching("none")) + .try_parse(|input| input.expect_ident_matching("none")) .is_ok() { return Ok(generic::Transform::none()); @@ -137,7 +137,7 @@ impl Transform { }, "translate" => { let sx = specified::LengthPercentage::parse(context, input)?; - if input.try(|input| input.expect_comma()).is_ok() { + if input.try_parse(|input| input.expect_comma()).is_ok() { let sy = specified::LengthPercentage::parse(context, input)?; Ok(generic::TransformOperation::Translate(sx, sy)) } else { @@ -166,7 +166,7 @@ impl Transform { }, "scale" => { let sx = NumberOrPercentage::parse(context, input)?.to_number(); - if input.try(|input| input.expect_comma()).is_ok() { + if input.try_parse(|input| input.expect_comma()).is_ok() { let sy = NumberOrPercentage::parse(context, input)?.to_number(); Ok(generic::TransformOperation::Scale(sx, sy)) } else { @@ -222,7 +222,7 @@ impl Transform { }, "skew" => { let ax = specified::Angle::parse_with_unitless(context, input)?; - if input.try(|input| input.expect_comma()).is_ok() { + if input.try_parse(|input| input.expect_comma()).is_ok() { let ay = specified::Angle::parse_with_unitless(context, input)?; Ok(generic::TransformOperation::Skew(ax, ay)) } else { @@ -282,17 +282,17 @@ impl Parse for TransformOrigin { ) -> Result> { let parse_depth = |input: &mut Parser| { input - .try(|i| Length::parse(context, i)) + .try_parse(|i| Length::parse(context, i)) .unwrap_or(Length::zero()) }; - match input.try(|i| OriginComponent::parse(context, i)) { + match input.try_parse(|i| OriginComponent::parse(context, i)) { Ok(x_origin @ OriginComponent::Center) => { - if let Ok(y_origin) = input.try(|i| OriginComponent::parse(context, i)) { + if let Ok(y_origin) = input.try_parse(|i| OriginComponent::parse(context, i)) { let depth = parse_depth(input); return Ok(Self::new(x_origin, y_origin, depth)); } let y_origin = OriginComponent::Center; - if let Ok(x_keyword) = input.try(HorizontalPositionKeyword::parse) { + if let Ok(x_keyword) = input.try_parse(HorizontalPositionKeyword::parse) { let x_origin = OriginComponent::Side(x_keyword); let depth = parse_depth(input); return Ok(Self::new(x_origin, y_origin, depth)); @@ -301,7 +301,7 @@ impl Parse for TransformOrigin { return Ok(Self::new(x_origin, y_origin, depth)); }, Ok(x_origin) => { - if let Ok(y_origin) = input.try(|i| OriginComponent::parse(context, i)) { + if let Ok(y_origin) = input.try_parse(|i| OriginComponent::parse(context, i)) { let depth = parse_depth(input); return Ok(Self::new(x_origin, y_origin, depth)); } @@ -313,12 +313,15 @@ impl Parse for TransformOrigin { } let y_keyword = VerticalPositionKeyword::parse(input)?; let y_origin = OriginComponent::Side(y_keyword); - if let Ok(x_keyword) = input.try(HorizontalPositionKeyword::parse) { + if let Ok(x_keyword) = input.try_parse(HorizontalPositionKeyword::parse) { let x_origin = OriginComponent::Side(x_keyword); let depth = parse_depth(input); return Ok(Self::new(x_origin, y_origin, depth)); } - if input.try(|i| i.expect_ident_matching("center")).is_ok() { + if input + .try_parse(|i| i.expect_ident_matching("center")) + .is_ok() + { let x_origin = OriginComponent::Center; let depth = parse_depth(input); return Ok(Self::new(x_origin, y_origin, depth)); @@ -368,7 +371,7 @@ impl Parse for Rotate { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if input.try(|i| i.expect_ident_matching("none")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() { return Ok(generic::Rotate::None); } @@ -376,9 +379,11 @@ impl Parse for Rotate { // // The rotate axis and angle could be in any order, so we parse angle twice to cover // two cases. i.e. `{3} ` or ` {3}` - let angle = input.try(|i| specified::Angle::parse(context, i)).ok(); + let angle = input + .try_parse(|i| specified::Angle::parse(context, i)) + .ok(); let axis = input - .try(|i| { + .try_parse(|i| { Ok(try_match_ident_ignore_ascii_case! { i, "x" => (Number::new(1.), Number::new(0.), Number::new(0.)), "y" => (Number::new(0.), Number::new(1.), Number::new(0.)), @@ -386,7 +391,7 @@ impl Parse for Rotate { }) }) .or_else(|_: ParseError| -> Result<_, ParseError> { - input.try(|i| { + input.try_parse(|i| { Ok(( Number::parse(context, i)?, Number::parse(context, i)?, @@ -415,13 +420,13 @@ impl Parse for Translate { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if input.try(|i| i.expect_ident_matching("none")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() { return Ok(generic::Translate::None); } let tx = specified::LengthPercentage::parse(context, input)?; - if let Ok(ty) = input.try(|i| specified::LengthPercentage::parse(context, i)) { - if let Ok(tz) = input.try(|i| specified::Length::parse(context, i)) { + if let Ok(ty) = input.try_parse(|i| specified::LengthPercentage::parse(context, i)) { + if let Ok(tz) = input.try_parse(|i| specified::Length::parse(context, i)) { // 'translate: ' return Ok(generic::Translate::Translate(tx, ty, tz)); } @@ -454,14 +459,14 @@ impl Parse for Scale { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if input.try(|i| i.expect_ident_matching("none")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() { return Ok(generic::Scale::None); } let sx = NumberOrPercentage::parse(context, input)?.to_number(); - if let Ok(sy) = input.try(|i| NumberOrPercentage::parse(context, i)) { + if let Ok(sy) = input.try_parse(|i| NumberOrPercentage::parse(context, i)) { let sy = sy.to_number(); - if let Ok(sz) = input.try(|i| NumberOrPercentage::parse(context, i)) { + if let Ok(sz) = input.try_parse(|i| NumberOrPercentage::parse(context, i)) { // 'scale: ' return Ok(generic::Scale::Scale(sx, sy, sz.to_number())); } diff --git a/components/style/values/specified/ui.rs b/components/style/values/specified/ui.rs index b94267162c94..74440a672059 100644 --- a/components/style/values/specified/ui.rs +++ b/components/style/values/specified/ui.rs @@ -27,7 +27,7 @@ impl Parse for Cursor { ) -> Result> { let mut images = vec![]; loop { - match input.try(|input| CursorImage::parse(context, input)) { + match input.try_parse(|input| CursorImage::parse(context, input)) { Ok(image) => images.push(image), Err(_) => break, } @@ -52,7 +52,7 @@ impl Parse for CursorImage { let mut hotspot_x = Number::zero(); let mut hotspot_y = Number::zero(); - if let Ok(x) = input.try(|input| Number::parse(context, input)) { + if let Ok(x) = input.try_parse(|input| Number::parse(context, input)) { has_hotspot = true; hotspot_x = x; hotspot_y = Number::parse(context, input)?; @@ -136,7 +136,7 @@ impl Parse for ScrollbarColor { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if input.try(|i| i.expect_ident_matching("auto")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("auto")).is_ok() { return Ok(generics::ScrollbarColor::Auto); } Ok(generics::ScrollbarColor::Colors {