style: Switch all callsites of try() to try_parse() in the style crate.

Fully automated via:

  $ rg -l '\.try\(' | xargs sed -i 's/\.try(/.try_parse(/g'
  $ cd servo/components/style && cargo +nightly fmt

Differential Revision: https://phabricator.services.mozilla.com/D80099
This commit is contained in:
Emilio Cobos Álvarez 2020-06-17 22:27:37 +00:00
parent 5af0d7ca7c
commit 685e749cfc
No known key found for this signature in database
GPG key ID: E1152D0994E4BF8A
56 changed files with 469 additions and 403 deletions

View file

@ -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<Self, ParseError<'i>> {
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<Self, ParseError<'i>> {
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<CounterBound, ParseError<'i>> {
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<Self, ParseError<'i>> {
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<Self, ParseError<'i>> {
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<Self, ParseError<'i>> {
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<Self, ParseError<'i>> {
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),

View file

@ -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 <custom-ident> 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 {

View file

@ -122,7 +122,7 @@ macro_rules! impl_range {
) -> Result<Self, ParseError<'i>> {
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<Source, ParseError<'i>> {
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| {

View file

@ -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<Self, ParseError<'i>> {
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)?;

View file

@ -200,14 +200,14 @@ fn consume_operation_or_colon(input: &mut Parser) -> Result<Option<Operator>, ()
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

View file

@ -125,8 +125,8 @@ impl MediaQuery {
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
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

View file

@ -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,
};

View file

@ -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,

View file

@ -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 {

View file

@ -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

View file

@ -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<Longhands, ParseError<'i>> {
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! {

View file

@ -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 <single-transition-property>,
// 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<Longhands, ParseError<'i>> {
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")?;

View file

@ -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;

View file

@ -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

View file

@ -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
}

View file

@ -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

View file

@ -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

View file

@ -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<NonNegativeNumber>),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<Longhands, ParseError<'i>> {
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<Longhands, ParseError<'i>> {
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<Longhands, ParseError<'i>> {
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<Longhands, ParseError<'i>> {
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! {

View file

@ -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

View file

@ -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;

View file

@ -135,7 +135,7 @@ impl DocumentMatchingFunction {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
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));
}

View file

@ -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,

View file

@ -103,7 +103,7 @@ impl SupportsCondition {
///
/// <https://drafts.csswg.org/css-conditional/#supports_condition>
pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
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<Self, ParseError<'i>> {
// 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<SupportsCondition, ParseError<'i>> {
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()

View file

@ -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 {

View file

@ -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<Self, ParseError<'i>> {
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);

View file

@ -107,7 +107,10 @@ impl<T: Parse> Parse for FontSettings<T> {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
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());
}

View file

@ -131,7 +131,7 @@ impl Parse for GridLine<specified::Integer> {
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
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<specified::Integer> {
for _ in 0..3 {
// Maximum possible entities for <grid-line>
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<specified::Integer> {
}
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<specified::Integer> {
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<specified::Integer> {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
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;

View file

@ -59,7 +59,7 @@ impl<LengthPercentage> LengthPercentageOrAuto<LengthPercentage> {
&mut Parser<'i, 't>,
) -> Result<LengthPercentage, ParseError<'i>>,
) -> Result<Self, ParseError<'i>> {
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);
}

View file

@ -101,13 +101,13 @@ impl Parse for CounterStyle {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
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

View file

@ -55,7 +55,7 @@ where
Parse: Fn(&ParserContext, &mut Parser<'i, 't>) -> Result<T, ParseError<'i>>,
{
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 {
// <first>
@ -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 {
// <first> <second>
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 {
// <first> <second> <third>

View file

@ -63,7 +63,7 @@ impl<L> Size2D<L> {
{
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))
}

View file

@ -129,7 +129,7 @@ impl<C: Parse, U: Parse> Parse for SVGPaint<C, U> {
});
}
let fallback = input
.try(|i| SVGPaintFallback::parse(context, i))
.try_parse(|i| SVGPaintFallback::parse(context, i))
.unwrap_or(SVGPaintFallback::Unset);
Ok(SVGPaint { kind, fallback })
}

View file

@ -63,7 +63,10 @@ impl<Value> Spacing<Value> {
where
F: FnOnce(&ParserContext, &mut Parser<'i, 't>) -> Result<Value, ParseError<'i>>,
{
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)

View file

@ -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 <baseline-position>, 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));
}
}
// <content-distribution>
if let Ok(value) = input.try(parse_content_distribution) {
if let Ok(value) = input.try_parse(parse_content_distribution) {
return Ok(ContentDistribution::new(value));
}
// <overflow-position>? <content-position>
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 <baseline-position>, 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));
}
// <overflow-position>? <self-position>
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.
// <baseline-position>
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));
}
// <overflow-position>? <self-position>
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 <baseline-position>, 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));
}
// <overflow-position>? <self-position>
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<AlignFlags, ParseE
// when this function is updated.
let flags = try_match_ident_ignore_ascii_case! { input,
"legacy" => {
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)

View file

@ -22,9 +22,10 @@ impl Parse for BackgroundSize {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
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)))
}
}

View file

@ -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<Self, ParseError<'i>> {
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<Self, ParseError<'i>> {
// 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<Self, ParseError<'i>> {
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<Self, ParseError<'i>> {
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<Self, ParseError<'i>> {
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<Self, ParseError<'i>> {
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<Self, ParseError<'i>> {
let fill = input
.try(|i| -> Result<_, ParseError> {
.try_parse(|i| -> Result<_, ParseError> {
let fill = FillRule::parse(i)?;
i.expect_comma()?;
Ok(fill)

View file

@ -121,7 +121,8 @@ impl BorderSideWidth {
input: &mut Parser<'i, 't>,
allow_quirks: AllowQuirks,
) -> Result<Self, ParseError<'i>> {
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<Self, ParseError<'i>> {
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<Self, ParseError<'i>> {
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<Self, ParseError<'i>> {
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),

View file

@ -530,30 +530,30 @@ impl Parse for Display {
input: &mut Parser<'i, 't>,
) -> Result<Display, ParseError<'i>> {
// Parse all combinations of <display-inside/outside>? 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)
};
// <display-listitem> = <display-outside>? && [ 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<Self, ParseError<'i>> {
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<Self, ParseError<'i>> {
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<Self, ParseError<'i>> {
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<Self, ParseError<'i>> {
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<ScrollSnapAlign, ParseError<'i>> {
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<Self, ParseError<'i>> {
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<Contain, ParseError<'i>> {
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),

View file

@ -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<Self, ParseError<'i>> {
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);
}

View file

@ -50,7 +50,7 @@ fn parse_counters<'i, 't>(
default_value: i32,
) -> Result<Vec<CounterPair<Integer>>, 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<Self, ParseError<'i>> {
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;
}

View file

@ -21,10 +21,10 @@ impl Parse for TimingFunction {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
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);

View file

@ -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<Self, ParseError<'i>> {
#[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<Self, ParseError<'i>> {
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::<Length>);
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,

View file

@ -171,7 +171,7 @@ impl Parse for AbsoluteFontWeight {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
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<FontSize, ParseError<'i>> {
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<FontVariantAlternates, ParseError<'i>> {
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<FontLanguageOverride, ParseError<'i>> {
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<Integer, ParseError<'i>> {
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<Integer> {
) -> Result<Self, ParseError<'i>> {
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<MozScriptLevel, ParseError<'i>> {
// 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")?;

View file

@ -52,11 +52,11 @@ impl Parse for TrackBreadth<LengthPercentage> {
// 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<LengthPercentage> {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
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<LengthPercentage, Integer> {
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<LengthPercentage, Integer> {
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 <fixed-size> for <auto-repeat>
@ -224,8 +227,9 @@ impl Parse for TrackList<LengthPercentage, Integer> {
// assume that everything is <fixed-size>. This flag is useful when we encounter <auto-repeat>
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<LengthPercentage, Integer> {
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<LengthPercentage, Integer> {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
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<LengthPercentage, Integer> {
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
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);
}
}

View file

@ -132,24 +132,24 @@ impl Parse for Image {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Image, ParseError<'i>> {
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(# <element-id>)`.
#[cfg(feature = "gecko")]
fn parse_element<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Atom, ParseError<'i>> {
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<Image, ParseError<'i>> {
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<Self, ParseError<'i>> {
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<LengthPercentageItemList, ParseError<'i>> {
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<Self, ParseError<'i>> {
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<Self, ParseError<'i>> {
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<Self, ParseError<'i>> {
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<Self, ParseError<'i>> {
// 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<Self, ParseError<'i>> {
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<T> generic::GradientItem<Color, T> {
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<T> generic::GradientItem<Color, T> {
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<T> generic::ColorStop<Color, T> {
) -> Result<Self, ParseError<'i>> {
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<Self, ParseError<'i>> {
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(

View file

@ -1226,12 +1226,12 @@ impl Size {
) -> Result<Self, ParseError<'i>> {
#[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<Self, ParseError<'i>> {
#[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);
}

View file

@ -75,10 +75,10 @@ impl Parse for ListStyleType {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
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<Quotes, ParseError<'i>> {
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()));

View file

@ -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<Self, ParseError<'i>> {
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<Self, ParseError<'i>> {
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<Self, ParseError<'i>> {
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<Attr, ParseError<'i>> {
// 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();

View file

@ -39,18 +39,20 @@ impl Parse for RayFunction<Angle> {
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<Self, ParseError<'i>> {
// 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<Self, ParseError<'i>> {
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() {

View file

@ -56,7 +56,7 @@ impl Parse for OutlineStyle {
_context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<OutlineStyle, ParseError<'i>> {
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())));

View file

@ -116,28 +116,31 @@ impl Position {
input: &mut Parser<'i, 't>,
allow_quirks: AllowQuirks,
) -> Result<Self, ParseError<'i>> {
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<S: Parse> PositionComponent<S> {
input: &mut Parser<'i, 't>,
allow_quirks: AllowQuirks,
) -> Result<Self, ParseError<'i>> {
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<Self, ParseError<'i>> {
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() {

View file

@ -87,7 +87,7 @@ impl Parse for SourceSizeOrLength {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
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));
}

View file

@ -48,7 +48,8 @@ macro_rules! parse_svg_length {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
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<Self, ParseError<'i>> {
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<SVGPaintOrder, ParseError<'i>> {
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),

View file

@ -41,11 +41,16 @@ impl Parse for InitialLetter {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
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<TextOverflow, ParseError<'i>> {
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<Self, ParseError<'i>> {
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 <string>
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<Self, ParseError<'i>> {
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))

View file

@ -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<Self, ParseError<'i>> {
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<Self, ParseError<'i>> {
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. `<number>{3} <angle>` or `<angle> <number>{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<Self, ParseError<'i>> {
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: <length-percentage> <length-percentage> <length>'
return Ok(generic::Translate::Translate(tx, ty, tz));
}
@ -454,14 +459,14 @@ impl Parse for Scale {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
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: <number> <number> <number>'
return Ok(generic::Scale::Scale(sx, sy, sz.to_number()));
}

View file

@ -27,7 +27,7 @@ impl Parse for Cursor {
) -> Result<Self, ParseError<'i>> {
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<Self, ParseError<'i>> {
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 {