style: Revert try -> r#try change.

Since we're in an inconsistent state because mako files weren't updated, and
it's really really ugly.
This commit is contained in:
Emilio Cobos Álvarez 2018-11-10 21:20:27 +01:00
parent 155caba595
commit 212b3e1311
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
47 changed files with 326 additions and 336 deletions

View file

@ -370,7 +370,7 @@ impl Parse for System {
"symbolic" => Ok(System::Symbolic), "symbolic" => Ok(System::Symbolic),
"additive" => Ok(System::Additive), "additive" => Ok(System::Additive),
"fixed" => { "fixed" => {
let first_symbol_value = input.r#try(|i| Integer::parse(context, i)).ok(); let first_symbol_value = input.try(|i| Integer::parse(context, i)).ok();
Ok(System::Fixed { first_symbol_value: first_symbol_value }) Ok(System::Fixed { first_symbol_value: first_symbol_value })
} }
"extends" => { "extends" => {
@ -457,7 +457,7 @@ impl Parse for Negative {
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
Ok(Negative( Ok(Negative(
Symbol::parse(context, input)?, Symbol::parse(context, input)?,
input.r#try(|input| Symbol::parse(context, input)).ok(), input.try(|input| Symbol::parse(context, input)).ok(),
)) ))
} }
} }
@ -483,7 +483,7 @@ impl Parse for Ranges {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if input if input
.r#try(|input| input.expect_ident_matching("auto")) .try(|input| input.expect_ident_matching("auto"))
.is_ok() .is_ok()
{ {
Ok(Ranges(Vec::new())) Ok(Ranges(Vec::new()))
@ -512,7 +512,7 @@ fn parse_bound<'i, 't>(
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<CounterBound, ParseError<'i>> { ) -> Result<CounterBound, ParseError<'i>> {
if let Ok(integer) = input.r#try(|input| Integer::parse(context, input)) { if let Ok(integer) = input.try(|input| Integer::parse(context, input)) {
return Ok(CounterBound::Integer(integer)); return Ok(CounterBound::Integer(integer));
} }
input.expect_ident_matching("infinite")?; input.expect_ident_matching("infinite")?;
@ -556,7 +556,7 @@ impl Parse for Pad {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let pad_with = input.r#try(|input| Symbol::parse(context, input)); let pad_with = input.try(|input| Symbol::parse(context, input));
let min_length = Integer::parse_non_negative(context, input)?; let min_length = Integer::parse_non_negative(context, input)?;
let pad_with = pad_with.or_else(|_| Symbol::parse(context, input))?; let pad_with = pad_with.or_else(|_| Symbol::parse(context, input))?;
Ok(Pad(min_length, pad_with)) Ok(Pad(min_length, pad_with))
@ -588,7 +588,7 @@ impl Parse for Symbols {
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let mut symbols = Vec::new(); let mut symbols = Vec::new();
loop { loop {
if let Ok(s) = input.r#try(|input| Symbol::parse(context, input)) { if let Ok(s) = input.try(|input| Symbol::parse(context, input)) {
symbols.push(s) symbols.push(s)
} else { } else {
if symbols.is_empty() { if symbols.is_empty() {
@ -640,7 +640,7 @@ impl Parse for AdditiveTuple {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let symbol = input.r#try(|input| Symbol::parse(context, input)); let symbol = input.try(|input| Symbol::parse(context, input));
let weight = Integer::parse_non_negative(context, input)?; let weight = Integer::parse_non_negative(context, input)?;
let symbol = symbol.or_else(|_| Symbol::parse(context, input))?; let symbol = symbol.or_else(|_| Symbol::parse(context, input))?;
Ok(AdditiveTuple { Ok(AdditiveTuple {
@ -673,7 +673,7 @@ impl Parse for SpeakAs {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let mut is_spell_out = false; let mut is_spell_out = false;
let result = input.r#try(|input| { let result = input.try(|input| {
let ident = input.expect_ident().map_err(|_| ())?; let ident = input.expect_ident().map_err(|_| ())?;
match_ignore_ascii_case! { &*ident, match_ignore_ascii_case! { &*ident,
"auto" => Ok(SpeakAs::Auto), "auto" => Ok(SpeakAs::Auto),

View file

@ -553,7 +553,7 @@ fn parse_var_function<'i, 't>(
let name = parse_name(&name).map_err(|()| { let name = parse_name(&name).map_err(|()| {
input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(name.clone())) input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(name.clone()))
})?; })?;
if input.r#try(|input| input.expect_comma()).is_ok() { if input.try(|input| input.expect_comma()).is_ok() {
parse_fallback(input)?; parse_fallback(input)?;
} }
if let Some(refs) = references { if let Some(refs) = references {
@ -569,7 +569,7 @@ fn parse_env_function<'i, 't>(
// TODO(emilio): This should be <custom-ident> per spec, but no other // TODO(emilio): This should be <custom-ident> per spec, but no other
// browser does that, see https://github.com/w3c/csswg-drafts/issues/3262. // browser does that, see https://github.com/w3c/csswg-drafts/issues/3262.
input.expect_ident()?; input.expect_ident()?;
if input.r#try(|input| input.expect_comma()).is_ok() { if input.try(|input| input.expect_comma()).is_ok() {
parse_fallback(input)?; parse_fallback(input)?;
} }
if let Some(references) = references { if let Some(references) = references {

View file

@ -120,7 +120,7 @@ macro_rules! impl_range {
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let first = $component::parse(context, input)?; let first = $component::parse(context, input)?;
let second = input let second = input
.r#try(|input| $component::parse(context, input)) .try(|input| $component::parse(context, input))
.unwrap_or_else(|_| first.clone()); .unwrap_or_else(|_| first.clone());
Ok($range(first, second)) Ok($range(first, second))
} }
@ -234,7 +234,7 @@ impl Parse for FontStyle {
GenericFontStyle::Italic => FontStyle::Italic, GenericFontStyle::Italic => FontStyle::Italic,
GenericFontStyle::Oblique(angle) => { GenericFontStyle::Oblique(angle) => {
let second_angle = input let second_angle = input
.r#try(|input| SpecifiedFontStyle::parse_angle(context, input)) .try(|input| SpecifiedFontStyle::parse_angle(context, input))
.unwrap_or_else(|_| angle.clone()); .unwrap_or_else(|_| angle.clone());
FontStyle::Oblique(angle, second_angle) FontStyle::Oblique(angle, second_angle)
@ -380,7 +380,7 @@ impl Parse for Source {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Source, ParseError<'i>> { ) -> Result<Source, ParseError<'i>> {
if input if input
.r#try(|input| input.expect_function_matching("local")) .try(|input| input.expect_function_matching("local"))
.is_ok() .is_ok()
{ {
return input return input
@ -392,7 +392,7 @@ impl Parse for Source {
// Parsing optional format() // Parsing optional format()
let format_hints = if input let format_hints = if input
.r#try(|input| input.expect_function_matching("format")) .try(|input| input.expect_function_matching("format"))
.is_ok() .is_ok()
{ {
input.parse_nested_block(|input| { input.parse_nested_block(|input| {

View file

@ -114,7 +114,7 @@ impl MediaCondition {
// ParenthesisBlock. // ParenthesisBlock.
let first_condition = Self::parse_paren_block(context, input)?; let first_condition = Self::parse_paren_block(context, input)?;
let operator = match input.r#try(Operator::parse) { let operator = match input.try(Operator::parse) {
Ok(op) => op, Ok(op) => op,
Err(..) => return Ok(first_condition), Err(..) => return Ok(first_condition),
}; };
@ -133,7 +133,7 @@ impl MediaCondition {
}; };
loop { loop {
if input.r#try(|i| i.expect_ident_matching(delim)).is_err() { if input.try(|i| i.expect_ident_matching(delim)).is_err() {
return Ok(MediaCondition::Operation( return Ok(MediaCondition::Operation(
conditions.into_boxed_slice(), conditions.into_boxed_slice(),
operator, operator,
@ -159,7 +159,7 @@ impl MediaCondition {
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
input.parse_nested_block(|input| { input.parse_nested_block(|input| {
// Base case. // Base case.
if let Ok(inner) = input.r#try(|i| Self::parse(context, i)) { if let Ok(inner) = input.try(|i| Self::parse(context, i)) {
return Ok(MediaCondition::InParens(Box::new(inner))); return Ok(MediaCondition::InParens(Box::new(inner)));
} }
let expr = MediaFeatureExpression::parse_in_parenthesis_block(context, input)?; let expr = MediaFeatureExpression::parse_in_parenthesis_block(context, input)?;

View file

@ -221,14 +221,14 @@ fn consume_operation_or_colon(input: &mut Parser) -> Result<Option<Operator>, ()
Ok(Some(match first_delim { Ok(Some(match first_delim {
'=' => Operator::Equal, '=' => Operator::Equal,
'>' => { '>' => {
if input.r#try(|i| i.expect_delim('=')).is_ok() { if input.try(|i| i.expect_delim('=')).is_ok() {
Operator::GreaterThanEqual Operator::GreaterThanEqual
} else { } else {
Operator::GreaterThan Operator::GreaterThan
} }
}, },
'<' => { '<' => {
if input.r#try(|i| i.expect_delim('=')).is_ok() { if input.try(|i| i.expect_delim('=')).is_ok() {
Operator::LessThanEqual Operator::LessThanEqual
} else { } else {
Operator::LessThan Operator::LessThan
@ -350,7 +350,7 @@ impl MediaFeatureExpression {
} }
} }
let operator = input.r#try(consume_operation_or_colon); let operator = input.try(consume_operation_or_colon);
let operator = match operator { let operator = match operator {
Err(..) => { Err(..) => {
// If there's no colon, this is a media query of the // 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>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let (qualifier, explicit_media_type) = input let (qualifier, explicit_media_type) = input
.r#try(|input| -> Result<_, ()> { .try(|input| -> Result<_, ()> {
let qualifier = input.r#try(Qualifier::parse).ok(); let qualifier = input.try(Qualifier::parse).ok();
let ident = input.expect_ident().map_err(|_| ())?; let ident = input.expect_ident().map_err(|_| ())?;
let media_type = MediaQueryType::parse(&ident)?; let media_type = MediaQueryType::parse(&ident)?;
Ok((qualifier, Some(media_type))) Ok((qualifier, Some(media_type)))
@ -135,7 +135,7 @@ impl MediaQuery {
let condition = if explicit_media_type.is_none() { let condition = if explicit_media_type.is_none() {
Some(MediaCondition::parse(context, input)?) Some(MediaCondition::parse(context, input)?)
} else if input.r#try(|i| i.expect_ident_matching("and")).is_ok() { } else if input.try(|i| i.expect_ident_matching("and")).is_ok() {
Some(MediaCondition::parse_disallow_or(context, input)?) Some(MediaCondition::parse_disallow_or(context, input)?)
} else { } else {
None None

View file

@ -135,7 +135,7 @@ impl DocumentMatchingFunction {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(url) = input.r#try(|input| CssUrl::parse(context, input)) { if let Ok(url) = input.try(|input| CssUrl::parse(context, input)) {
return Ok(DocumentMatchingFunction::Url(url)); return Ok(DocumentMatchingFunction::Url(url));
} }

View file

@ -202,7 +202,7 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
return Err(input.new_custom_error(StyleParseErrorKind::UnexpectedNamespaceRule)) return Err(input.new_custom_error(StyleParseErrorKind::UnexpectedNamespaceRule))
} }
let prefix = input.r#try(|i| i.expect_ident_cloned()) let prefix = input.try(|i| i.expect_ident_cloned())
.map(|s| Prefix::from(s.as_ref())).ok(); .map(|s| Prefix::from(s.as_ref())).ok();
let maybe_namespace = match input.expect_url_or_string() { let maybe_namespace = match input.expect_url_or_string() {
Ok(url_or_string) => 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> /// <https://drafts.csswg.org/css-conditional/#supports_condition>
pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> { pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
if input.r#try(|i| i.expect_ident_matching("not")).is_ok() { if input.try(|i| i.expect_ident_matching("not")).is_ok() {
let inner = SupportsCondition::parse_in_parens(input)?; let inner = SupportsCondition::parse_in_parens(input)?;
return Ok(SupportsCondition::Not(Box::new(inner))); return Ok(SupportsCondition::Not(Box::new(inner)));
} }
@ -129,7 +129,7 @@ impl SupportsCondition {
loop { loop {
conditions.push(SupportsCondition::parse_in_parens(input)?); conditions.push(SupportsCondition::parse_in_parens(input)?);
if input if input
.r#try(|input| input.expect_ident_matching(keyword)) .try(|input| input.expect_ident_matching(keyword))
.is_err() .is_err()
{ {
// Did not find the expected keyword. // 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>> { fn parse_in_parens<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
// Whitespace is normally taken care of in `Parser::next`, // Whitespace is normally taken care of in `Parser::next`,
// but we want to not include it in `pos` for the SupportsCondition::FutureSyntax cases. // but we want to not include it in `pos` for the SupportsCondition::FutureSyntax cases.
while input.r#try(Parser::expect_whitespace).is_ok() {} while input.try(Parser::expect_whitespace).is_ok() {}
let pos = input.position(); let pos = input.position();
let location = input.current_source_location(); let location = input.current_source_location();
// FIXME: remove clone() when lifetimes are non-lexical // FIXME: remove clone() when lifetimes are non-lexical
match input.next()?.clone() { match input.next()?.clone() {
Token::ParenthesisBlock => { Token::ParenthesisBlock => {
let nested = let nested =
input.r#try(|input| input.parse_nested_block(parse_condition_or_declaration)); input.try(|input| input.parse_nested_block(parse_condition_or_declaration));
if nested.is_ok() { if nested.is_ok() {
return nested; return nested;
} }
}, },
Token::Function(ident) => { Token::Function(ident) => {
let nested = input.r#try(|input| { let nested = input.try(|input| {
input.parse_nested_block(|input| { input.parse_nested_block(|input| {
SupportsCondition::parse_functional(&ident, input) SupportsCondition::parse_functional(&ident, input)
}) })
@ -240,7 +240,7 @@ fn eval_moz_bool_pref(_: &CStr, _: &ParserContext) -> bool {
pub fn parse_condition_or_declaration<'i, 't>( pub fn parse_condition_or_declaration<'i, 't>(
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<SupportsCondition, ParseError<'i>> { ) -> Result<SupportsCondition, ParseError<'i>> {
if let Ok(condition) = input.r#try(SupportsCondition::parse) { if let Ok(condition) = input.try(SupportsCondition::parse) {
Ok(SupportsCondition::Parenthesized(Box::new(condition))) Ok(SupportsCondition::Parenthesized(Box::new(condition)))
} else { } else {
Declaration::parse(input).map(SupportsCondition::Declaration) Declaration::parse(input).map(SupportsCondition::Declaration)
@ -418,7 +418,7 @@ impl Declaration {
PropertyDeclaration::parse_into(&mut declarations, id, &context, input) PropertyDeclaration::parse_into(&mut declarations, id, &context, input)
.map_err(|_| input.new_custom_error(())) .map_err(|_| input.new_custom_error(()))
})?; })?;
let _ = input.r#try(parse_important); let _ = input.try(parse_important);
Ok(()) Ok(())
}) })
.is_ok() .is_ok()

View file

@ -265,7 +265,7 @@ fn parse_shorthand<'i, 't>(
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<(ViewportLength, ViewportLength), ParseError<'i>> { ) -> Result<(ViewportLength, ViewportLength), ParseError<'i>> {
let min = ViewportLength::parse(context, input)?; let min = ViewportLength::parse(context, input)?;
match input.r#try(|i| ViewportLength::parse(context, i)) { match input.try(|i| ViewportLength::parse(context, i)) {
Err(_) => Ok((min.clone(), min)), Err(_) => Ok((min.clone(), min)),
Ok(max) => Ok((min, max)), Ok(max) => Ok((min, max)),
} }
@ -289,8 +289,8 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for ViewportRuleParser<'a, 'b> {
) -> Result<Vec<ViewportDescriptorDeclaration>, ParseError<'i>> { ) -> Result<Vec<ViewportDescriptorDeclaration>, ParseError<'i>> {
macro_rules! declaration { macro_rules! declaration {
($declaration:ident($parse:expr)) => { ($declaration:ident($parse:expr)) => {
declaration!($declaration(value: r#try!($parse(input)), declaration!($declaration(value: try!($parse(input)),
important: input.r#try(parse_important).is_ok())) important: input.try(parse_important).is_ok()))
}; };
($declaration:ident(value: $value:expr, important: $important:expr)) => { ($declaration:ident(value: $value:expr, important: $important:expr)) => {
ViewportDescriptorDeclaration::new( ViewportDescriptorDeclaration::new(
@ -306,7 +306,7 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for ViewportRuleParser<'a, 'b> {
}; };
(shorthand -> [$min:ident, $max:ident]) => {{ (shorthand -> [$min:ident, $max:ident]) => {{
let shorthand = parse_shorthand(self.context, input)?; let shorthand = parse_shorthand(self.context, input)?;
let important = input.r#try(parse_important).is_ok(); let important = input.try(parse_important).is_ok();
Ok(vec![ Ok(vec![
declaration!($min(value: shorthand.0, important: important)), declaration!($min(value: shorthand.0, important: important)),

View file

@ -374,7 +374,7 @@ impl SingleFontFamily {
/// Parse a font-family value /// Parse a font-family value
pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> { pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
if let Ok(value) = input.r#try(|i| i.expect_string_cloned()) { if let Ok(value) = input.try(|i| i.expect_string_cloned()) {
return Ok(SingleFontFamily::FamilyName(FamilyName { return Ok(SingleFontFamily::FamilyName(FamilyName {
name: Atom::from(&*value), name: Atom::from(&*value),
syntax: FamilyNameSyntax::Quoted, syntax: FamilyNameSyntax::Quoted,
@ -419,7 +419,7 @@ impl SingleFontFamily {
value.push(' '); value.push(' ');
value.push_str(&ident); value.push_str(&ident);
} }
while let Ok(ident) = input.r#try(|i| i.expect_ident_cloned()) { while let Ok(ident) = input.try(|i| i.expect_ident_cloned()) {
value.push(' '); value.push(' ');
value.push_str(&ident); value.push_str(&ident);
} }

View file

@ -85,7 +85,7 @@ impl<T: Parse> Parse for FontSettings<T> {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if input.r#try(|i| i.expect_ident_matching("normal")).is_ok() { if input.try(|i| i.expect_ident_matching("normal")).is_ok() {
return Ok(Self::normal()); return Ok(Self::normal());
} }

View file

@ -86,7 +86,7 @@ impl Parse for GridLine<specified::Integer> {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let mut grid_line = Self::auto(); let mut grid_line = Self::auto();
if input.r#try(|i| i.expect_ident_matching("auto")).is_ok() { if input.try(|i| i.expect_ident_matching("auto")).is_ok() {
return Ok(grid_line); return Ok(grid_line);
} }
@ -99,7 +99,7 @@ impl Parse for GridLine<specified::Integer> {
for _ in 0..3 { for _ in 0..3 {
// Maximum possible entities for <grid-line> // Maximum possible entities for <grid-line>
let location = input.current_source_location(); let location = input.current_source_location();
if input.r#try(|i| i.expect_ident_matching("span")).is_ok() { if input.try(|i| i.expect_ident_matching("span")).is_ok() {
if grid_line.is_span { if grid_line.is_span {
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError)); return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError));
} }
@ -109,14 +109,14 @@ impl Parse for GridLine<specified::Integer> {
} }
grid_line.is_span = true; grid_line.is_span = true;
} else if let Ok(i) = input.r#try(|i| specified::Integer::parse(context, i)) { } else if let Ok(i) = input.try(|i| specified::Integer::parse(context, i)) {
// FIXME(emilio): Probably shouldn't reject if it's calc()... // FIXME(emilio): Probably shouldn't reject if it's calc()...
if i.value() == 0 || val_before_span || grid_line.line_num.is_some() { if i.value() == 0 || val_before_span || grid_line.line_num.is_some() {
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError)); return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError));
} }
grid_line.line_num = Some(i); grid_line.line_num = Some(i);
} else if let Ok(name) = input.r#try(|i| i.expect_ident_cloned()) { } else if let Ok(name) = input.try(|i| i.expect_ident_cloned()) {
if val_before_span || grid_line.ident.is_some() { if val_before_span || grid_line.ident.is_some() {
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError)); return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError));
} }
@ -375,7 +375,7 @@ impl Parse for RepeatCount<specified::Integer> {
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
// Maximum number of repeat is 10000. The greater numbers should be clamped. // Maximum number of repeat is 10000. The greater numbers should be clamped.
const MAX_LINE: i32 = 10000; const MAX_LINE: i32 = 10000;
if let Ok(mut i) = input.r#try(|i| specified::Integer::parse_positive(context, i)) { if let Ok(mut i) = input.try(|i| specified::Integer::parse_positive(context, i)) {
if i.value() > MAX_LINE { if i.value() > MAX_LINE {
i = specified::Integer::new(MAX_LINE); i = specified::Integer::new(MAX_LINE);
} }
@ -605,14 +605,14 @@ impl Parse for LineNameList {
let mut fill_idx = None; let mut fill_idx = None;
loop { loop {
let repeat_parse_result = input.r#try(|input| { let repeat_parse_result = input.try(|input| {
input.expect_function_matching("repeat")?; input.expect_function_matching("repeat")?;
input.parse_nested_block(|input| { input.parse_nested_block(|input| {
let count = RepeatCount::parse(context, input)?; let count = RepeatCount::parse(context, input)?;
input.expect_comma()?; input.expect_comma()?;
let mut names_list = vec![]; let mut names_list = vec![];
names_list.push(parse_line_names(input)?); // there should be at least one names_list.push(parse_line_names(input)?); // there should be at least one
while let Ok(names) = input.r#try(parse_line_names) { while let Ok(names) = input.try(parse_line_names) {
names_list.push(names); names_list.push(names);
} }
@ -643,7 +643,7 @@ impl Parse for LineNameList {
}, },
_ => return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)), _ => return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)),
} }
} else if let Ok(names) = input.r#try(parse_line_names) { } else if let Ok(names) = input.try(parse_line_names) {
line_names.push(names); line_names.push(names);
} else { } else {
break; break;

View file

@ -111,19 +111,16 @@ impl Parse for CounterStyleOrNone {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(name) = input.r#try(|i| parse_counter_style_name(i)) { if let Ok(name) = input.try(|i| parse_counter_style_name(i)) {
return Ok(CounterStyleOrNone::Name(name)); return Ok(CounterStyleOrNone::Name(name));
} }
if input.r#try(|i| i.expect_ident_matching("none")).is_ok() { if input.try(|i| i.expect_ident_matching("none")).is_ok() {
return Ok(CounterStyleOrNone::None); return Ok(CounterStyleOrNone::None);
} }
if input if input.try(|i| i.expect_function_matching("symbols")).is_ok() {
.r#try(|i| i.expect_function_matching("symbols"))
.is_ok()
{
return input.parse_nested_block(|input| { return input.parse_nested_block(|input| {
let symbols_type = input let symbols_type = input
.r#try(|i| SymbolsType::parse(i)) .try(|i| SymbolsType::parse(i))
.unwrap_or(SymbolsType::Symbolic); .unwrap_or(SymbolsType::Symbolic);
let symbols = Symbols::parse(context, input)?; let symbols = Symbols::parse(context, input)?;
// There must be at least two symbols for alphabetic or // There must be at least two symbols for alphabetic or

View file

@ -50,7 +50,7 @@ where
Parse: Fn(&ParserContext, &mut Parser<'i, 't>) -> Result<T, ParseError<'i>>, Parse: Fn(&ParserContext, &mut Parser<'i, 't>) -> Result<T, ParseError<'i>>,
{ {
let first = parse(context, input)?; let first = parse(context, input)?;
let second = if let Ok(second) = input.r#try(|i| parse(context, i)) { let second = if let Ok(second) = input.try(|i| parse(context, i)) {
second second
} else { } else {
// <first> // <first>
@ -61,13 +61,13 @@ where
first, first,
)); ));
}; };
let third = if let Ok(third) = input.r#try(|i| parse(context, i)) { let third = if let Ok(third) = input.try(|i| parse(context, i)) {
third third
} else { } else {
// <first> <second> // <first> <second>
return Ok(Self::new(first.clone(), second.clone(), first, second)); return Ok(Self::new(first.clone(), second.clone(), first, second));
}; };
let fourth = if let Ok(fourth) = input.r#try(|i| parse(context, i)) { let fourth = if let Ok(fourth) = input.try(|i| parse(context, i)) {
fourth fourth
} else { } else {
// <first> <second> <third> // <first> <second> <third>

View file

@ -55,7 +55,7 @@ impl<L> Size<L> {
{ {
let first = parse_one(context, input)?; let first = parse_one(context, input)?;
let second = input let second = input
.r#try(|i| parse_one(context, i)) .try(|i| parse_one(context, i))
.unwrap_or_else(|_| first.clone()); .unwrap_or_else(|_| first.clone());
Ok(Self::new(first, second)) Ok(Self::new(first, second))
} }

View file

@ -84,10 +84,10 @@ fn parse_fallback<'i, 't, ColorType: Parse>(
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Option<Either<ColorType, None_>> { ) -> Option<Either<ColorType, None_>> {
if input.r#try(|i| i.expect_ident_matching("none")).is_ok() { if input.try(|i| i.expect_ident_matching("none")).is_ok() {
Some(Either::Second(None_)) Some(Either::Second(None_))
} else { } else {
if let Ok(color) = input.r#try(|i| ColorType::parse(context, i)) { if let Ok(color) = input.try(|i| ColorType::parse(context, i)) {
Some(Either::First(color)) Some(Either::First(color))
} else { } else {
None None
@ -100,12 +100,12 @@ impl<ColorType: Parse, UrlPaintServer: Parse> Parse for SVGPaint<ColorType, UrlP
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(url) = input.r#try(|i| UrlPaintServer::parse(context, i)) { if let Ok(url) = input.try(|i| UrlPaintServer::parse(context, i)) {
Ok(SVGPaint { Ok(SVGPaint {
kind: SVGPaintKind::PaintServer(url), kind: SVGPaintKind::PaintServer(url),
fallback: parse_fallback(context, input), fallback: parse_fallback(context, input),
}) })
} else if let Ok(kind) = input.r#try(SVGPaintKind::parse_ident) { } else if let Ok(kind) = input.try(SVGPaintKind::parse_ident) {
if let SVGPaintKind::None = kind { if let SVGPaintKind::None = kind {
Ok(SVGPaint { Ok(SVGPaint {
kind: kind, kind: kind,
@ -117,7 +117,7 @@ impl<ColorType: Parse, UrlPaintServer: Parse> Parse for SVGPaint<ColorType, UrlP
fallback: parse_fallback(context, input), fallback: parse_fallback(context, input),
}) })
} }
} else if let Ok(color) = input.r#try(|i| ColorType::parse(context, i)) { } else if let Ok(color) = input.try(|i| ColorType::parse(context, i)) {
Ok(SVGPaint { Ok(SVGPaint {
kind: SVGPaintKind::Color(color), kind: SVGPaintKind::Color(color),
fallback: None, fallback: None,
@ -158,7 +158,7 @@ impl<LengthOrPercentageType: Parse, NumberType: Parse> Parse
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(num) = input.r#try(|i| NumberType::parse(context, i)) { if let Ok(num) = input.try(|i| NumberType::parse(context, i)) {
return Ok(SvgLengthOrPercentageOrNumber::Number(num)); return Ok(SvgLengthOrPercentageOrNumber::Number(num));
} }

View file

@ -58,7 +58,7 @@ impl<Value> Spacing<Value> {
where where
F: FnOnce(&ParserContext, &mut Parser<'i, 't>) -> Result<Value, ParseError<'i>>, F: FnOnce(&ParserContext, &mut Parser<'i, 't>) -> Result<Value, ParseError<'i>>,
{ {
if input.r#try(|i| i.expect_ident_matching("normal")).is_ok() { if input.try(|i| i.expect_ident_matching("normal")).is_ok() {
return Ok(Spacing::Normal); return Ok(Spacing::Normal);
} }
parse(context, input).map(Spacing::Value) parse(context, input).map(Spacing::Value)

View file

@ -44,7 +44,7 @@ where
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<UrlOrNone<Url>, ParseError<'i>> { ) -> Result<UrlOrNone<Url>, ParseError<'i>> {
if let Ok(url) = input.r#try(|input| Url::parse(context, input)) { if let Ok(url) = input.try(|input| Url::parse(context, input)) {
return Ok(UrlOrNone::Url(url)); return Ok(UrlOrNone::Url(url));
} }
input.expect_ident_matching("none")?; input.expect_ident_matching("none")?;

View file

@ -155,7 +155,7 @@ impl<A: Parse, B: Parse> Parse for Either<A, B> {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Either<A, B>, ParseError<'i>> { ) -> Result<Either<A, B>, ParseError<'i>> {
if let Ok(v) = input.r#try(|i| A::parse(context, i)) { if let Ok(v) = input.try(|i| A::parse(context, i)) {
Ok(Either::First(v)) Ok(Either::First(v))
} else { } else {
B::parse(context, input).map(Either::Second) B::parse(context, input).map(Either::Second)

View file

@ -195,25 +195,25 @@ impl ContentDistribution {
// when this function is updated. // when this function is updated.
// Try to parse normal first // Try to parse normal first
if input.r#try(|i| i.expect_ident_matching("normal")).is_ok() { if input.try(|i| i.expect_ident_matching("normal")).is_ok() {
return Ok(ContentDistribution::normal()); return Ok(ContentDistribution::normal());
} }
// Parse <baseline-position>, but only on the block axis. // Parse <baseline-position>, but only on the block axis.
if axis == AxisDirection::Block { if axis == AxisDirection::Block {
if let Ok(value) = input.r#try(parse_baseline) { if let Ok(value) = input.try(parse_baseline) {
return Ok(ContentDistribution::new(value)); return Ok(ContentDistribution::new(value));
} }
} }
// <content-distribution> // <content-distribution>
if let Ok(value) = input.r#try(parse_content_distribution) { if let Ok(value) = input.try(parse_content_distribution) {
return Ok(ContentDistribution::new(value)); return Ok(ContentDistribution::new(value));
} }
// <overflow-position>? <content-position> // <overflow-position>? <content-position>
let overflow_position = input let overflow_position = input
.r#try(parse_overflow_position) .try(parse_overflow_position)
.unwrap_or(AlignFlags::empty()); .unwrap_or(AlignFlags::empty());
let content_position = try_match_ident_ignore_ascii_case! { input, let content_position = try_match_ident_ignore_ascii_case! { input,
@ -358,18 +358,18 @@ impl SelfAlignment {
// //
// It's weird that this accepts <baseline-position>, but not // It's weird that this accepts <baseline-position>, but not
// justify-content... // justify-content...
if let Ok(value) = input.r#try(parse_baseline) { if let Ok(value) = input.try(parse_baseline) {
return Ok(SelfAlignment(value)); return Ok(SelfAlignment(value));
} }
// auto | normal | stretch // auto | normal | stretch
if let Ok(value) = input.r#try(parse_auto_normal_stretch) { if let Ok(value) = input.try(parse_auto_normal_stretch) {
return Ok(SelfAlignment(value)); return Ok(SelfAlignment(value));
} }
// <overflow-position>? <self-position> // <overflow-position>? <self-position>
let overflow_position = input let overflow_position = input
.r#try(parse_overflow_position) .try(parse_overflow_position)
.unwrap_or(AlignFlags::empty()); .unwrap_or(AlignFlags::empty());
let self_position = parse_self_position(input, axis)?; let self_position = parse_self_position(input, axis)?;
Ok(SelfAlignment(overflow_position | self_position)) Ok(SelfAlignment(overflow_position | self_position))
@ -484,17 +484,17 @@ impl Parse for AlignItems {
// this function is updated. // this function is updated.
// <baseline-position> // <baseline-position>
if let Ok(baseline) = input.r#try(parse_baseline) { if let Ok(baseline) = input.try(parse_baseline) {
return Ok(AlignItems(baseline)); return Ok(AlignItems(baseline));
} }
// normal | stretch // normal | stretch
if let Ok(value) = input.r#try(parse_normal_stretch) { if let Ok(value) = input.try(parse_normal_stretch) {
return Ok(AlignItems(value)); return Ok(AlignItems(value));
} }
// <overflow-position>? <self-position> // <overflow-position>? <self-position>
let overflow = input let overflow = input
.r#try(parse_overflow_position) .try(parse_overflow_position)
.unwrap_or(AlignFlags::empty()); .unwrap_or(AlignFlags::empty());
let self_position = parse_self_position(input, AxisDirection::Block)?; let self_position = parse_self_position(input, AxisDirection::Block)?;
Ok(AlignItems(self_position | overflow)) Ok(AlignItems(self_position | overflow))
@ -542,23 +542,23 @@ impl Parse for JustifyItems {
// //
// It's weird that this accepts <baseline-position>, but not // It's weird that this accepts <baseline-position>, but not
// justify-content... // justify-content...
if let Ok(baseline) = input.r#try(parse_baseline) { if let Ok(baseline) = input.try(parse_baseline) {
return Ok(JustifyItems(baseline)); return Ok(JustifyItems(baseline));
} }
// normal | stretch // normal | stretch
if let Ok(value) = input.r#try(parse_normal_stretch) { if let Ok(value) = input.try(parse_normal_stretch) {
return Ok(JustifyItems(value)); return Ok(JustifyItems(value));
} }
// legacy | [ legacy && [ left | right | center ] ] // legacy | [ legacy && [ left | right | center ] ]
if let Ok(value) = input.r#try(parse_legacy) { if let Ok(value) = input.try(parse_legacy) {
return Ok(JustifyItems(value)); return Ok(JustifyItems(value));
} }
// <overflow-position>? <self-position> // <overflow-position>? <self-position>
let overflow = input let overflow = input
.r#try(parse_overflow_position) .try(parse_overflow_position)
.unwrap_or(AlignFlags::empty()); .unwrap_or(AlignFlags::empty());
let self_position = parse_self_position(input, AxisDirection::Inline)?; let self_position = parse_self_position(input, AxisDirection::Inline)?;
Ok(JustifyItems(overflow | self_position)) Ok(JustifyItems(overflow | self_position))
@ -714,7 +714,7 @@ fn parse_legacy<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseE
// when this function is updated. // when this function is updated.
let flags = try_match_ident_ignore_ascii_case! { input, let flags = try_match_ident_ignore_ascii_case! { input,
"legacy" => { "legacy" => {
let flags = input.r#try(parse_left_right_center) let flags = input.try(parse_left_right_center)
.unwrap_or(AlignFlags::empty()); .unwrap_or(AlignFlags::empty());
return Ok(AlignFlags::LEGACY | flags) return Ok(AlignFlags::LEGACY | flags)

View file

@ -19,9 +19,9 @@ impl Parse for BackgroundSize {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(width) = input.r#try(|i| NonNegativeLengthOrPercentageOrAuto::parse(context, i)) { if let Ok(width) = input.try(|i| NonNegativeLengthOrPercentageOrAuto::parse(context, i)) {
let height = input let height = input
.r#try(|i| NonNegativeLengthOrPercentageOrAuto::parse(context, i)) .try(|i| NonNegativeLengthOrPercentageOrAuto::parse(context, i))
.unwrap_or(NonNegativeLengthOrPercentageOrAuto::auto()); .unwrap_or(NonNegativeLengthOrPercentageOrAuto::auto());
return Ok(GenericBackgroundSize::Explicit { width, height }); return Ok(GenericBackgroundSize::Explicit { width, height });
} }
@ -106,7 +106,7 @@ impl Parse for BackgroundRepeat {
}, },
}; };
let vertical = input.r#try(BackgroundRepeatKeyword::parse).ok(); let vertical = input.try(BackgroundRepeatKeyword::parse).ok();
Ok(BackgroundRepeat::Keywords(horizontal, vertical)) Ok(BackgroundRepeat::Keywords(horizontal, vertical))
} }
} }

View file

@ -70,12 +70,12 @@ impl Parse for ClippingShape {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if is_clip_path_path_enabled(context) { if is_clip_path_path_enabled(context) {
if let Ok(p) = input.r#try(|i| Path::parse(context, i)) { if let Ok(p) = input.try(|i| Path::parse(context, i)) {
return Ok(ShapeSource::Path(p)); return Ok(ShapeSource::Path(p));
} }
} }
if let Ok(url) = input.r#try(|i| SpecifiedUrl::parse(context, i)) { if let Ok(url) = input.try(|i| SpecifiedUrl::parse(context, i)) {
return Ok(ShapeSource::ImageOrUrl(url)); return Ok(ShapeSource::ImageOrUrl(url));
} }
@ -89,7 +89,7 @@ impl Parse for FloatAreaShape {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(image) = input.r#try(|i| Image::parse_with_cors_anonymous(context, i)) { if let Ok(image) = input.try(|i| Image::parse_with_cors_anonymous(context, i)) {
return Ok(ShapeSource::ImageOrUrl(image)); return Ok(ShapeSource::ImageOrUrl(image));
} }
@ -106,7 +106,7 @@ where
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if input.r#try(|i| i.expect_ident_matching("none")).is_ok() { if input.try(|i| i.expect_ident_matching("none")).is_ok() {
return Ok(ShapeSource::None); return Ok(ShapeSource::None);
} }
@ -119,7 +119,7 @@ where
return false; // already parsed this component return false; // already parsed this component
} }
*component = input.r#try(|i| U::parse(context, i)).ok(); *component = input.try(|i| U::parse(context, i)).ok();
component.is_some() component.is_some()
} }
@ -147,7 +147,7 @@ impl Parse for GeometryBox {
_context: &ParserContext, _context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(shape_box) = input.r#try(|i| ShapeBox::parse(i)) { if let Ok(shape_box) = input.try(|i| ShapeBox::parse(i)) {
return Ok(GeometryBox::ShapeBox(shape_box)); return Ok(GeometryBox::ShapeBox(shape_box));
} }
@ -197,7 +197,7 @@ impl InsetRect {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let rect = Rect::parse_with(context, input, LengthOrPercentage::parse)?; let rect = Rect::parse_with(context, input, LengthOrPercentage::parse)?;
let round = if input.r#try(|i| i.expect_ident_matching("round")).is_ok() { let round = if input.try(|i| i.expect_ident_matching("round")).is_ok() {
Some(BorderRadius::parse(context, input)?) Some(BorderRadius::parse(context, input)?)
} else { } else {
None None
@ -225,9 +225,9 @@ impl Circle {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let radius = input let radius = input
.r#try(|i| ShapeRadius::parse(context, i)) .try(|i| ShapeRadius::parse(context, i))
.unwrap_or_default(); .unwrap_or_default();
let position = if input.r#try(|i| i.expect_ident_matching("at")).is_ok() { let position = if input.try(|i| i.expect_ident_matching("at")).is_ok() {
Position::parse(context, input)? Position::parse(context, input)?
} else { } else {
Position::center() Position::center()
@ -270,14 +270,14 @@ impl Ellipse {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let (a, b) = input let (a, b) = input
.r#try(|i| -> Result<_, ParseError> { .try(|i| -> Result<_, ParseError> {
Ok(( Ok((
ShapeRadius::parse(context, i)?, ShapeRadius::parse(context, i)?,
ShapeRadius::parse(context, i)?, ShapeRadius::parse(context, i)?,
)) ))
}) })
.unwrap_or_default(); .unwrap_or_default();
let position = if input.r#try(|i| i.expect_ident_matching("at")).is_ok() { let position = if input.try(|i| i.expect_ident_matching("at")).is_ok() {
Position::parse(context, input)? Position::parse(context, input)?
} else { } else {
Position::center() Position::center()
@ -315,7 +315,7 @@ impl Parse for ShapeRadius {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(lop) = input.r#try(|i| LengthOrPercentage::parse_non_negative(context, i)) { if let Ok(lop) = input.try(|i| LengthOrPercentage::parse_non_negative(context, i)) {
return Ok(generic::ShapeRadius::Length(lop)); return Ok(generic::ShapeRadius::Length(lop));
} }
@ -419,7 +419,7 @@ impl Polygon {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let fill = input let fill = input
.r#try(|i| -> Result<_, ParseError> { .try(|i| -> Result<_, ParseError> {
let fill = FillRule::parse(i)?; let fill = FillRule::parse(i)?;
i.expect_comma()?; // only eat the comma if there is something before it i.expect_comma()?; // only eat the comma if there is something before it
Ok(fill) Ok(fill)
@ -457,7 +457,7 @@ impl Path {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let fill = input let fill = input
.r#try(|i| -> Result<_, ParseError> { .try(|i| -> Result<_, ParseError> {
let fill = FillRule::parse(i)?; let fill = FillRule::parse(i)?;
i.expect_comma()?; i.expect_comma()?;
Ok(fill) Ok(fill)

View file

@ -58,7 +58,7 @@ impl BorderSideWidth {
allow_quirks: AllowQuirks, allow_quirks: AllowQuirks,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(length) = if let Ok(length) =
input.r#try(|i| Length::parse_non_negative_quirky(context, i, allow_quirks)) input.try(|i| Length::parse_non_negative_quirky(context, i, allow_quirks))
{ {
return Ok(BorderSideWidth::Length(length)); return Ok(BorderSideWidth::Length(length));
} }
@ -115,11 +115,11 @@ impl Parse for BorderImageSideWidth {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if input.r#try(|i| i.expect_ident_matching("auto")).is_ok() { if input.try(|i| i.expect_ident_matching("auto")).is_ok() {
return Ok(GenericBorderImageSideWidth::Auto); return Ok(GenericBorderImageSideWidth::Auto);
} }
if let Ok(len) = input.r#try(|i| LengthOrPercentage::parse_non_negative(context, i)) { if let Ok(len) = input.try(|i| LengthOrPercentage::parse_non_negative(context, i)) {
return Ok(GenericBorderImageSideWidth::Length(len)); return Ok(GenericBorderImageSideWidth::Length(len));
} }
@ -133,10 +133,10 @@ impl Parse for BorderImageSlice {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let mut fill = input.r#try(|i| i.expect_ident_matching("fill")).is_ok(); let mut fill = input.try(|i| i.expect_ident_matching("fill")).is_ok();
let offsets = Rect::parse_with(context, input, NumberOrPercentage::parse_non_negative)?; let offsets = Rect::parse_with(context, input, NumberOrPercentage::parse_non_negative)?;
if !fill { if !fill {
fill = input.r#try(|i| i.expect_ident_matching("fill")).is_ok(); fill = input.try(|i| i.expect_ident_matching("fill")).is_ok();
} }
Ok(GenericBorderImageSlice { Ok(GenericBorderImageSlice {
offsets: offsets, offsets: offsets,
@ -151,7 +151,7 @@ impl Parse for BorderRadius {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let widths = Rect::parse_with(context, input, LengthOrPercentage::parse_non_negative)?; let widths = Rect::parse_with(context, input, LengthOrPercentage::parse_non_negative)?;
let heights = if input.r#try(|i| i.expect_delim('/')).is_ok() { let heights = if input.try(|i| i.expect_delim('/')).is_ok() {
Rect::parse_with(context, input, LengthOrPercentage::parse_non_negative)? Rect::parse_with(context, input, LengthOrPercentage::parse_non_negative)?
} else { } else {
widths.clone() widths.clone()
@ -236,7 +236,7 @@ impl Parse for BorderImageRepeat {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let horizontal = BorderImageRepeatKeyword::parse(input)?; let horizontal = BorderImageRepeatKeyword::parse(input)?;
let vertical = input.r#try(BorderImageRepeatKeyword::parse).ok(); let vertical = input.try(BorderImageRepeatKeyword::parse).ok();
Ok(BorderImageRepeat( Ok(BorderImageRepeat(
horizontal, horizontal,
vertical.unwrap_or(horizontal), vertical.unwrap_or(horizontal),

View file

@ -310,7 +310,7 @@ impl Parse for VerticalAlign {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(lop) = if let Ok(lop) =
input.r#try(|i| LengthOrPercentage::parse_quirky(context, i, AllowQuirks::Yes)) input.try(|i| LengthOrPercentage::parse_quirky(context, i, AllowQuirks::Yes))
{ {
return Ok(GenericVerticalAlign::Length(lop)); return Ok(GenericVerticalAlign::Length(lop));
} }
@ -341,7 +341,7 @@ impl Parse for AnimationIterationCount {
input: &mut ::cssparser::Parser<'i, 't>, input: &mut ::cssparser::Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if input if input
.r#try(|input| input.expect_ident_matching("infinite")) .try(|input| input.expect_ident_matching("infinite"))
.is_ok() .is_ok()
{ {
return Ok(GenericAnimationIterationCount::Infinite); return Ok(GenericAnimationIterationCount::Infinite);
@ -394,7 +394,7 @@ impl Parse for AnimationName {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(name) = input.r#try(|input| KeyframesName::parse(context, input)) { if let Ok(name) = input.try(|input| KeyframesName::parse(context, input)) {
return Ok(AnimationName(Some(name))); return Ok(AnimationName(Some(name)));
} }
@ -557,7 +557,7 @@ impl Parse for WillChange {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<WillChange, ParseError<'i>> { ) -> Result<WillChange, ParseError<'i>> {
if input if input
.r#try(|input| input.expect_ident_matching("auto")) .try(|input| input.expect_ident_matching("auto"))
.is_ok() .is_ok()
{ {
return Ok(WillChange::Auto); return Ok(WillChange::Auto);
@ -646,14 +646,14 @@ impl Parse for TouchAction {
"none" => Ok(TouchAction::TOUCH_ACTION_NONE), "none" => Ok(TouchAction::TOUCH_ACTION_NONE),
"manipulation" => Ok(TouchAction::TOUCH_ACTION_MANIPULATION), "manipulation" => Ok(TouchAction::TOUCH_ACTION_MANIPULATION),
"pan-x" => { "pan-x" => {
if input.r#try(|i| i.expect_ident_matching("pan-y")).is_ok() { if input.try(|i| i.expect_ident_matching("pan-y")).is_ok() {
Ok(TouchAction::TOUCH_ACTION_PAN_X | TouchAction::TOUCH_ACTION_PAN_Y) Ok(TouchAction::TOUCH_ACTION_PAN_X | TouchAction::TOUCH_ACTION_PAN_Y)
} else { } else {
Ok(TouchAction::TOUCH_ACTION_PAN_X) Ok(TouchAction::TOUCH_ACTION_PAN_X)
} }
}, },
"pan-y" => { "pan-y" => {
if input.r#try(|i| i.expect_ident_matching("pan-x")).is_ok() { if input.try(|i| i.expect_ident_matching("pan-x")).is_ok() {
Ok(TouchAction::TOUCH_ACTION_PAN_X | TouchAction::TOUCH_ACTION_PAN_Y) Ok(TouchAction::TOUCH_ACTION_PAN_X | TouchAction::TOUCH_ACTION_PAN_Y)
} else { } else {
Ok(TouchAction::TOUCH_ACTION_PAN_Y) Ok(TouchAction::TOUCH_ACTION_PAN_Y)
@ -757,7 +757,7 @@ impl Parse for Contain {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Contain, ParseError<'i>> { ) -> Result<Contain, ParseError<'i>> {
let mut result = Contain::empty(); let mut result = Contain::empty();
while let Ok(name) = input.r#try(|i| i.expect_ident_cloned()) { while let Ok(name) = input.try(|i| i.expect_ident_cloned()) {
let flag = match_ignore_ascii_case! { &name, let flag = match_ignore_ascii_case! { &name,
"size" => Some(Contain::SIZE), "size" => Some(Contain::SIZE),
"layout" => Some(Contain::LAYOUT), "layout" => Some(Contain::LAYOUT),
@ -794,7 +794,7 @@ impl Parse for Perspective {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if input.r#try(|i| i.expect_ident_matching("none")).is_ok() { if input.try(|i| i.expect_ident_matching("none")).is_ok() {
return Ok(GenericPerspective::None); return Ok(GenericPerspective::None);
} }
Ok(GenericPerspective::Length(NonNegativeLength::parse( Ok(GenericPerspective::Length(NonNegativeLength::parse(

View file

@ -142,7 +142,7 @@ impl Parse for Color {
input.reset(&start); input.reset(&start);
let compontent_parser = ColorComponentParser(&*context); let compontent_parser = ColorComponentParser(&*context);
match input.r#try(|i| CSSParserColor::parse_with(&compontent_parser, i)) { match input.try(|i| CSSParserColor::parse_with(&compontent_parser, i)) {
Ok(value) => Ok(match value { Ok(value) => Ok(match value {
CSSParserColor::CurrentColor => Color::CurrentColor, CSSParserColor::CurrentColor => Color::CurrentColor,
CSSParserColor::RGBA(rgba) => Color::Numeric { CSSParserColor::RGBA(rgba) => Color::Numeric {
@ -245,7 +245,7 @@ impl Color {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
allow_quirks: AllowQuirks, allow_quirks: AllowQuirks,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
input.r#try(|i| Self::parse(context, i)).or_else(|e| { input.try(|i| Self::parse(context, i)).or_else(|e| {
if !allow_quirks.allowed(context.quirks_mode) { if !allow_quirks.allowed(context.quirks_mode) {
return Err(e); return Err(e);
} }

View file

@ -18,7 +18,7 @@ impl Parse for ColumnCount {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if input.r#try(|i| i.expect_ident_matching("auto")).is_ok() { if input.try(|i| i.expect_ident_matching("auto")).is_ok() {
return Ok(GenericColumnCount::Auto); return Ok(GenericColumnCount::Auto);
} }
Ok(GenericColumnCount::Integer(PositiveInteger::parse( Ok(GenericColumnCount::Integer(PositiveInteger::parse(

View file

@ -52,7 +52,7 @@ fn parse_counters<'i, 't>(
default_value: i32, default_value: i32,
) -> Result<Vec<CounterPair<Integer>>, ParseError<'i>> { ) -> Result<Vec<CounterPair<Integer>>, ParseError<'i>> {
if input if input
.r#try(|input| input.expect_ident_matching("none")) .try(|input| input.expect_ident_matching("none"))
.is_ok() .is_ok()
{ {
return Ok(vec![]); return Ok(vec![]);
@ -68,7 +68,7 @@ fn parse_counters<'i, 't>(
}; };
let value = input let value = input
.r#try(|input| Integer::parse(context, input)) .try(|input| Integer::parse(context, input))
.unwrap_or(Integer::new(default_value)); .unwrap_or(Integer::new(default_value));
counters.push(CounterPair { name, value }); counters.push(CounterPair { name, value });
} }
@ -90,7 +90,7 @@ impl Content {
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
fn parse_counter_style(_: &ParserContext, input: &mut Parser) -> ListStyleType { fn parse_counter_style(_: &ParserContext, input: &mut Parser) -> ListStyleType {
input input
.r#try(|input| { .try(|input| {
input.expect_comma()?; input.expect_comma()?;
ListStyleType::parse(input) ListStyleType::parse(input)
}) })
@ -100,7 +100,7 @@ impl Content {
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
fn parse_counter_style(context: &ParserContext, input: &mut Parser) -> CounterStyleOrNone { fn parse_counter_style(context: &ParserContext, input: &mut Parser) -> CounterStyleOrNone {
input input
.r#try(|input| { .try(|input| {
input.expect_comma()?; input.expect_comma()?;
CounterStyleOrNone::parse(context, input) CounterStyleOrNone::parse(context, input)
}) })
@ -117,13 +117,13 @@ impl Parse for Content {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if input if input
.r#try(|input| input.expect_ident_matching("normal")) .try(|input| input.expect_ident_matching("normal"))
.is_ok() .is_ok()
{ {
return Ok(generics::Content::Normal); return Ok(generics::Content::Normal);
} }
if input if input
.r#try(|input| input.expect_ident_matching("none")) .try(|input| input.expect_ident_matching("none"))
.is_ok() .is_ok()
{ {
return Ok(generics::Content::None); return Ok(generics::Content::None);
@ -131,7 +131,7 @@ impl Parse for Content {
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
{ {
if input if input
.r#try(|input| input.expect_ident_matching("-moz-alt-content")) .try(|input| input.expect_ident_matching("-moz-alt-content"))
.is_ok() .is_ok()
{ {
return Ok(generics::Content::MozAltContent); return Ok(generics::Content::MozAltContent);
@ -142,7 +142,7 @@ impl Parse for Content {
loop { loop {
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
{ {
if let Ok(url) = input.r#try(|i| SpecifiedImageUrl::parse(context, i)) { if let Ok(url) = input.try(|i| SpecifiedImageUrl::parse(context, i)) {
content.push(generics::ContentItem::Url(url)); content.push(generics::ContentItem::Url(url));
continue; continue;
} }

View file

@ -21,10 +21,10 @@ impl Parse for TimingFunction {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(keyword) = input.r#try(TimingKeyword::parse) { if let Ok(keyword) = input.try(TimingKeyword::parse) {
return Ok(GenericTimingFunction::Keyword(keyword)); return Ok(GenericTimingFunction::Keyword(keyword));
} }
if let Ok(ident) = input.r#try(|i| i.expect_ident_cloned()) { if let Ok(ident) = input.try(|i| i.expect_ident_cloned()) {
let position = match_ignore_ascii_case! { &ident, let position = match_ignore_ascii_case! { &ident,
"step-start" => StepPosition::Start, "step-start" => StepPosition::Start,
"step-end" => StepPosition::End, "step-end" => StepPosition::End,
@ -57,7 +57,7 @@ impl Parse for TimingFunction {
}, },
"steps" => { "steps" => {
let steps = Integer::parse_positive(context, i)?; let steps = Integer::parse_positive(context, i)?;
let position = i.r#try(|i| { let position = i.try(|i| {
i.expect_comma()?; i.expect_comma()?;
StepPosition::parse(context, i) StepPosition::parse(context, i)
}).unwrap_or(StepPosition::End); }).unwrap_or(StepPosition::End);

View file

@ -109,7 +109,7 @@ impl Parse for BoxShadow {
loop { loop {
if !inset { if !inset {
if input if input
.r#try(|input| input.expect_ident_matching("inset")) .try(|input| input.expect_ident_matching("inset"))
.is_ok() .is_ok()
{ {
inset = true; inset = true;
@ -117,14 +117,14 @@ impl Parse for BoxShadow {
} }
} }
if lengths.is_none() { if lengths.is_none() {
let value = input.r#try::<_, _, ParseError>(|i| { let value = input.try::<_, _, ParseError>(|i| {
let horizontal = Length::parse(context, i)?; let horizontal = Length::parse(context, i)?;
let vertical = Length::parse(context, i)?; let vertical = Length::parse(context, i)?;
let (blur, spread) = match i let (blur, spread) = match i
.r#try::<_, _, ParseError>(|i| Length::parse_non_negative(context, i)) .try::<_, _, ParseError>(|i| Length::parse_non_negative(context, i))
{ {
Ok(blur) => { Ok(blur) => {
let spread = i.r#try(|i| Length::parse(context, i)).ok(); let spread = i.try(|i| Length::parse(context, i)).ok();
(Some(blur.into()), spread) (Some(blur.into()), spread)
}, },
Err(_) => (None, None), Err(_) => (None, None),
@ -137,7 +137,7 @@ impl Parse for BoxShadow {
} }
} }
if color.is_none() { if color.is_none() {
if let Ok(value) = input.r#try(|i| Color::parse(context, i)) { if let Ok(value) = input.try(|i| Color::parse(context, i)) {
color = Some(value); color = Some(value);
continue; continue;
} }
@ -194,7 +194,7 @@ impl Parse for Filter {
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
{ {
if let Ok(url) = input.r#try(|i| SpecifiedUrl::parse(context, i)) { if let Ok(url) = input.try(|i| SpecifiedUrl::parse(context, i)) {
return Ok(GenericFilter::Url(url)); return Ok(GenericFilter::Url(url));
} }
} }
@ -253,12 +253,12 @@ impl Parse for SimpleShadow {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let color = input.r#try(|i| Color::parse(context, i)).ok(); let color = input.try(|i| Color::parse(context, i)).ok();
let horizontal = Length::parse(context, input)?; let horizontal = Length::parse(context, input)?;
let vertical = Length::parse(context, input)?; let vertical = Length::parse(context, input)?;
let blur = input.r#try(|i| Length::parse_non_negative(context, i)).ok(); let blur = input.try(|i| Length::parse_non_negative(context, i)).ok();
let blur = blur.map(NonNegative::<Length>); let blur = blur.map(NonNegative::<Length>);
let color = color.or_else(|| input.r#try(|i| Color::parse(context, i)).ok()); let color = color.or_else(|| input.try(|i| Color::parse(context, i)).ok());
Ok(SimpleShadow { Ok(SimpleShadow {
color, color,

View file

@ -25,7 +25,7 @@ impl Parse for FlexBasis {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(width) = input.r#try(|i| Width::parse(context, i)) { if let Ok(width) = input.try(|i| Width::parse(context, i)) {
return Ok(GenericFlexBasis::Width(width)); return Ok(GenericFlexBasis::Width(width));
} }
try_match_ident_ignore_ascii_case! { input, try_match_ident_ignore_ascii_case! { input,

View file

@ -117,7 +117,7 @@ impl Parse for FontWeight {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<FontWeight, ParseError<'i>> { ) -> Result<FontWeight, ParseError<'i>> {
if let Ok(absolute) = input.r#try(|input| AbsoluteFontWeight::parse(context, input)) { if let Ok(absolute) = input.try(|input| AbsoluteFontWeight::parse(context, input)) {
return Ok(FontWeight::Absolute(absolute)); return Ok(FontWeight::Absolute(absolute));
} }
@ -190,7 +190,7 @@ impl Parse for AbsoluteFontWeight {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(number) = input.r#try(|input| Number::parse(context, input)) { if let Ok(number) = input.try(|input| Number::parse(context, input)) {
// We could add another AllowedNumericType value, but it doesn't // We could add another AllowedNumericType value, but it doesn't
// seem worth it just for a single property with such a weird range, // seem worth it just for a single property with such a weird range,
// so we do the clamping here manually. // so we do the clamping here manually.
@ -242,7 +242,7 @@ impl Parse for SpecifiedFontStyle {
"normal" => generics::FontStyle::Normal, "normal" => generics::FontStyle::Normal,
"italic" => generics::FontStyle::Italic, "italic" => generics::FontStyle::Italic,
"oblique" => { "oblique" => {
let angle = input.r#try(|input| Self::parse_angle(context, input)) let angle = input.try(|input| Self::parse_angle(context, input))
.unwrap_or_else(|_| Self::default_angle()); .unwrap_or_else(|_| Self::default_angle());
generics::FontStyle::Oblique(angle) generics::FontStyle::Oblique(angle)
@ -481,8 +481,7 @@ impl Parse for FontStretch {
// //
// Values less than 0% are not allowed and are treated as parse // Values less than 0% are not allowed and are treated as parse
// errors. // errors.
if let Ok(percentage) = input.r#try(|input| Percentage::parse_non_negative(context, input)) if let Ok(percentage) = input.try(|input| Percentage::parse_non_negative(context, input)) {
{
return Ok(FontStretch::Stretch(percentage)); return Ok(FontStretch::Stretch(percentage));
} }
@ -682,7 +681,7 @@ impl Parse for FontSizeAdjust {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<FontSizeAdjust, ParseError<'i>> { ) -> Result<FontSizeAdjust, ParseError<'i>> {
if input if input
.r#try(|input| input.expect_ident_matching("none")) .try(|input| input.expect_ident_matching("none"))
.is_ok() .is_ok()
{ {
return Ok(FontSizeAdjust::None); return Ok(FontSizeAdjust::None);
@ -990,12 +989,12 @@ impl FontSize {
allow_quirks: AllowQuirks, allow_quirks: AllowQuirks,
) -> Result<FontSize, ParseError<'i>> { ) -> Result<FontSize, ParseError<'i>> {
if let Ok(lop) = if let Ok(lop) =
input.r#try(|i| LengthOrPercentage::parse_non_negative_quirky(context, i, allow_quirks)) input.try(|i| LengthOrPercentage::parse_non_negative_quirky(context, i, allow_quirks))
{ {
return Ok(FontSize::Length(lop)); return Ok(FontSize::Length(lop));
} }
if let Ok(kw) = input.r#try(KeywordSize::parse) { if let Ok(kw) = input.try(KeywordSize::parse) {
return Ok(FontSize::Keyword(kw.into())); return Ok(FontSize::Keyword(kw.into()));
} }
@ -1177,7 +1176,7 @@ impl Parse for FontVariantAlternates {
) -> Result<FontVariantAlternates, ParseError<'i>> { ) -> Result<FontVariantAlternates, ParseError<'i>> {
let mut alternates = Vec::new(); let mut alternates = Vec::new();
if input if input
.r#try(|input| input.expect_ident_matching("normal")) .try(|input| input.expect_ident_matching("normal"))
.is_ok() .is_ok()
{ {
return Ok(FontVariantAlternates::Value(VariantAlternatesList( return Ok(FontVariantAlternates::Value(VariantAlternatesList(
@ -1194,7 +1193,7 @@ impl Parse for FontVariantAlternates {
parsed_alternates |= $flag; parsed_alternates |= $flag;
) )
); );
while let Ok(_) = input.r#try(|input| { while let Ok(_) = input.try(|input| {
// FIXME: remove clone() when lifetimes are non-lexical // FIXME: remove clone() when lifetimes are non-lexical
match input.next()?.clone() { match input.next()?.clone() {
Token::Ident(ref value) if value.eq_ignore_ascii_case("historical-forms") => { Token::Ident(ref value) if value.eq_ignore_ascii_case("historical-forms") => {
@ -1409,13 +1408,13 @@ impl Parse for FontVariantEastAsian {
let mut result = VariantEastAsian::empty(); let mut result = VariantEastAsian::empty();
if input if input
.r#try(|input| input.expect_ident_matching("normal")) .try(|input| input.expect_ident_matching("normal"))
.is_ok() .is_ok()
{ {
return Ok(FontVariantEastAsian::Value(result)); return Ok(FontVariantEastAsian::Value(result));
} }
while let Ok(flag) = input.r#try(|input| { while let Ok(flag) = input.try(|input| {
Ok( Ok(
match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?, match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?,
"jis78" => "jis78" =>
@ -1633,19 +1632,19 @@ impl Parse for FontVariantLigatures {
let mut result = VariantLigatures::empty(); let mut result = VariantLigatures::empty();
if input if input
.r#try(|input| input.expect_ident_matching("normal")) .try(|input| input.expect_ident_matching("normal"))
.is_ok() .is_ok()
{ {
return Ok(FontVariantLigatures::Value(result)); return Ok(FontVariantLigatures::Value(result));
} }
if input if input
.r#try(|input| input.expect_ident_matching("none")) .try(|input| input.expect_ident_matching("none"))
.is_ok() .is_ok()
{ {
return Ok(FontVariantLigatures::Value(VariantLigatures::NONE)); return Ok(FontVariantLigatures::Value(VariantLigatures::NONE));
} }
while let Ok(flag) = input.r#try(|input| { while let Ok(flag) = input.try(|input| {
Ok( Ok(
match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?, match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?,
"common-ligatures" => "common-ligatures" =>
@ -1842,13 +1841,13 @@ impl Parse for FontVariantNumeric {
let mut result = VariantNumeric::empty(); let mut result = VariantNumeric::empty();
if input if input
.r#try(|input| input.expect_ident_matching("normal")) .try(|input| input.expect_ident_matching("normal"))
.is_ok() .is_ok()
{ {
return Ok(FontVariantNumeric::Value(result)); return Ok(FontVariantNumeric::Value(result));
} }
while let Ok(flag) = input.r#try(|input| { while let Ok(flag) = input.try(|input| {
Ok( Ok(
match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?, match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?,
"ordinal" => "ordinal" =>
@ -1982,14 +1981,14 @@ impl Parse for FontSynthesis {
"none" => Ok(result), "none" => Ok(result),
"weight" => { "weight" => {
result.weight = true; result.weight = true;
if input.r#try(|input| input.expect_ident_matching("style")).is_ok() { if input.try(|input| input.expect_ident_matching("style")).is_ok() {
result.style = true; result.style = true;
} }
Ok(result) Ok(result)
}, },
"style" => { "style" => {
result.style = true; result.style = true;
if input.r#try(|input| input.expect_ident_matching("weight")).is_ok() { if input.try(|input| input.expect_ident_matching("weight")).is_ok() {
result.weight = true; result.weight = true;
} }
Ok(result) Ok(result)
@ -2128,7 +2127,7 @@ impl Parse for FontLanguageOverride {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<FontLanguageOverride, ParseError<'i>> { ) -> Result<FontLanguageOverride, ParseError<'i>> {
if input if input
.r#try(|input| input.expect_ident_matching("normal")) .try(|input| input.expect_ident_matching("normal"))
.is_ok() .is_ok()
{ {
return Ok(FontLanguageOverride::Normal); return Ok(FontLanguageOverride::Normal);
@ -2195,7 +2194,7 @@ fn parse_one_feature_value<'i, 't>(
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Integer, ParseError<'i>> { ) -> Result<Integer, ParseError<'i>> {
if let Ok(integer) = input.r#try(|i| Integer::parse_non_negative(context, i)) { if let Ok(integer) = input.try(|i| Integer::parse_non_negative(context, i)) {
return Ok(integer); return Ok(integer);
} }
@ -2213,7 +2212,7 @@ impl Parse for FeatureTagValue<Integer> {
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let tag = FontTag::parse(context, input)?; let tag = FontTag::parse(context, input)?;
let value = input let value = input
.r#try(|i| parse_one_feature_value(context, i)) .try(|i| parse_one_feature_value(context, i))
.unwrap_or_else(|_| Integer::new(1)); .unwrap_or_else(|_| Integer::new(1));
Ok(Self { tag, value }) Ok(Self { tag, value })
@ -2331,7 +2330,7 @@ impl Parse for MozScriptLevel {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<MozScriptLevel, ParseError<'i>> { ) -> Result<MozScriptLevel, ParseError<'i>> {
// We don't bother to handle calc here. // We don't bother to handle calc here.
if let Ok(i) = input.r#try(|i| i.expect_integer()) { if let Ok(i) = input.try(|i| i.expect_integer()) {
return Ok(MozScriptLevel::Relative(i)); return Ok(MozScriptLevel::Relative(i));
} }
input.expect_ident_matching("auto")?; input.expect_ident_matching("auto")?;

View file

@ -25,7 +25,7 @@ impl Parse for ScrollSnapPoint {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if input.r#try(|i| i.expect_ident_matching("none")).is_ok() { if input.try(|i| i.expect_ident_matching("none")).is_ok() {
return Ok(GenericScrollSnapPoint::None); return Ok(GenericScrollSnapPoint::None);
} }
input.expect_function_matching("repeat")?; input.expect_function_matching("repeat")?;

View file

@ -36,11 +36,11 @@ impl Parse for TrackBreadth<LengthOrPercentage> {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(lop) = input.r#try(|i| LengthOrPercentage::parse_non_negative(context, i)) { if let Ok(lop) = input.try(|i| LengthOrPercentage::parse_non_negative(context, i)) {
return Ok(TrackBreadth::Breadth(lop)); return Ok(TrackBreadth::Breadth(lop));
} }
if let Ok(f) = input.r#try(parse_flex) { if let Ok(f) = input.try(parse_flex) {
return Ok(TrackBreadth::Fr(f)); return Ok(TrackBreadth::Fr(f));
} }
@ -53,17 +53,14 @@ impl Parse for TrackSize<LengthOrPercentage> {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(b) = input.r#try(|i| TrackBreadth::parse(context, i)) { if let Ok(b) = input.try(|i| TrackBreadth::parse(context, i)) {
return Ok(TrackSize::Breadth(b)); return Ok(TrackSize::Breadth(b));
} }
if input if input.try(|i| i.expect_function_matching("minmax")).is_ok() {
.r#try(|i| i.expect_function_matching("minmax"))
.is_ok()
{
return input.parse_nested_block(|input| { return input.parse_nested_block(|input| {
let inflexible_breadth = let inflexible_breadth =
match input.r#try(|i| LengthOrPercentage::parse_non_negative(context, i)) { match input.try(|i| LengthOrPercentage::parse_non_negative(context, i)) {
Ok(lop) => TrackBreadth::Breadth(lop), Ok(lop) => TrackBreadth::Breadth(lop),
Err(..) => { Err(..) => {
let keyword = TrackKeyword::parse(input)?; let keyword = TrackKeyword::parse(input)?;
@ -95,7 +92,7 @@ pub fn parse_line_names<'i, 't>(
input.expect_square_bracket_block()?; input.expect_square_bracket_block()?;
input.parse_nested_block(|input| { input.parse_nested_block(|input| {
let mut values = vec![]; let mut values = vec![];
while let Ok((loc, ident)) = input.r#try(|i| -> Result<_, CssParseError<()>> { while let Ok((loc, ident)) = input.try(|i| -> Result<_, CssParseError<()>> {
Ok((i.current_source_location(), i.expect_ident_cloned()?)) Ok((i.current_source_location(), i.expect_ident_cloned()?))
}) { }) {
let ident = CustomIdent::from_ident(loc, &ident, &["span", "auto"])?; let ident = CustomIdent::from_ident(loc, &ident, &["span", "auto"])?;
@ -126,7 +123,7 @@ impl TrackRepeat<LengthOrPercentage, Integer> {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<(Self, RepeatType), ParseError<'i>> { ) -> Result<(Self, RepeatType), ParseError<'i>> {
input input
.r#try(|i| i.expect_function_matching("repeat").map_err(|e| e.into())) .try(|i| i.expect_function_matching("repeat").map_err(|e| e.into()))
.and_then(|_| { .and_then(|_| {
input.parse_nested_block(|input| { input.parse_nested_block(|input| {
let count = RepeatCount::parse(context, input)?; let count = RepeatCount::parse(context, input)?;
@ -146,9 +143,9 @@ impl TrackRepeat<LengthOrPercentage, Integer> {
loop { loop {
current_names = input current_names = input
.r#try(parse_line_names) .try(parse_line_names)
.unwrap_or(vec![].into_boxed_slice()); .unwrap_or(vec![].into_boxed_slice());
if let Ok(track_size) = input.r#try(|i| TrackSize::parse(context, i)) { if let Ok(track_size) = input.try(|i| TrackSize::parse(context, i)) {
if !track_size.is_fixed() { if !track_size.is_fixed() {
if is_auto { if is_auto {
// should be <fixed-size> for <auto-repeat> // should be <fixed-size> for <auto-repeat>
@ -172,7 +169,7 @@ impl TrackRepeat<LengthOrPercentage, Integer> {
// gecko implements new spec. // gecko implements new spec.
names.push( names.push(
input input
.r#try(parse_line_names) .try(parse_line_names)
.unwrap_or(vec![].into_boxed_slice()), .unwrap_or(vec![].into_boxed_slice()),
); );
break; break;
@ -226,10 +223,10 @@ impl Parse for TrackList<LengthOrPercentage, Integer> {
loop { loop {
current_names.extend_from_slice( current_names.extend_from_slice(
&mut input &mut input
.r#try(parse_line_names) .try(parse_line_names)
.unwrap_or(vec![].into_boxed_slice()), .unwrap_or(vec![].into_boxed_slice()),
); );
if let Ok(track_size) = input.r#try(|i| TrackSize::parse(context, i)) { if let Ok(track_size) = input.try(|i| TrackSize::parse(context, i)) {
if !track_size.is_fixed() { if !track_size.is_fixed() {
atleast_one_not_fixed = true; atleast_one_not_fixed = true;
if auto_repeat.is_some() { if auto_repeat.is_some() {
@ -242,7 +239,7 @@ impl Parse for TrackList<LengthOrPercentage, Integer> {
names.push(vec.into_boxed_slice()); names.push(vec.into_boxed_slice());
values.push(TrackListValue::TrackSize(track_size)); values.push(TrackListValue::TrackSize(track_size));
} else if let Ok((repeat, type_)) = } else if let Ok((repeat, type_)) =
input.r#try(|i| TrackRepeat::parse_with_repeat_type(context, i)) input.try(|i| TrackRepeat::parse_with_repeat_type(context, i))
{ {
if list_type == TrackListType::Explicit { if list_type == TrackListType::Explicit {
list_type = TrackListType::Normal; // <explicit-track-list> doesn't contain repeat() list_type = TrackListType::Normal; // <explicit-track-list> doesn't contain repeat()
@ -404,7 +401,7 @@ impl Parse for GridTemplateComponent<LengthOrPercentage, Integer> {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if input.r#try(|i| i.expect_ident_matching("none")).is_ok() { if input.try(|i| i.expect_ident_matching("none")).is_ok() {
return Ok(GridTemplateComponent::None); return Ok(GridTemplateComponent::None);
} }
@ -419,7 +416,7 @@ impl GridTemplateComponent<LengthOrPercentage, Integer> {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if allow_grid_template_subgrids() { if allow_grid_template_subgrids() {
if let Ok(t) = input.r#try(|i| LineNameList::parse(context, i)) { if let Ok(t) = input.try(|i| LineNameList::parse(context, i)) {
return Ok(GridTemplateComponent::Subgrid(t)); return Ok(GridTemplateComponent::Subgrid(t));
} }
} }

View file

@ -39,7 +39,7 @@ impl ImageLayer {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(v) = input.r#try(|i| None_::parse(context, i)) { if let Ok(v) = input.try(|i| None_::parse(context, i)) {
return Ok(Either::First(v)); return Ok(Either::First(v));
} }
Image::parse_with_cors_anonymous(context, input).map(Either::Second) Image::parse_with_cors_anonymous(context, input).map(Either::Second)
@ -142,19 +142,19 @@ impl Parse for Image {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Image, ParseError<'i>> { ) -> Result<Image, ParseError<'i>> {
if let Ok(url) = input.r#try(|input| SpecifiedImageUrl::parse(context, input)) { if let Ok(url) = input.try(|input| SpecifiedImageUrl::parse(context, input)) {
return Ok(generic::Image::Url(url)); return Ok(generic::Image::Url(url));
} }
if let Ok(gradient) = input.r#try(|i| Gradient::parse(context, i)) { if let Ok(gradient) = input.try(|i| Gradient::parse(context, i)) {
return Ok(generic::Image::Gradient(Box::new(gradient))); return Ok(generic::Image::Gradient(Box::new(gradient)));
} }
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
{ {
if let Ok(paint_worklet) = input.r#try(|i| PaintWorklet::parse(context, i)) { if let Ok(paint_worklet) = input.try(|i| PaintWorklet::parse(context, i)) {
return Ok(generic::Image::PaintWorklet(paint_worklet)); return Ok(generic::Image::PaintWorklet(paint_worklet));
} }
} }
if let Ok(image_rect) = input.r#try(|input| MozImageRect::parse(context, input)) { if let Ok(image_rect) = input.try(|input| MozImageRect::parse(context, input)) {
return Ok(generic::Image::Rect(Box::new(image_rect))); return Ok(generic::Image::Rect(Box::new(image_rect)));
} }
Ok(generic::Image::Element(Image::parse_element(input)?)) Ok(generic::Image::Element(Image::parse_element(input)?))
@ -172,7 +172,7 @@ impl Image {
/// Parses a `-moz-element(# <element-id>)`. /// Parses a `-moz-element(# <element-id>)`.
fn parse_element<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Atom, ParseError<'i>> { fn parse_element<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Atom, ParseError<'i>> {
input.r#try(|i| i.expect_function_matching("-moz-element"))?; input.try(|i| i.expect_function_matching("-moz-element"))?;
let location = input.current_source_location(); let location = input.current_source_location();
input.parse_nested_block(|i| match *i.next()? { input.parse_nested_block(|i| match *i.next()? {
Token::IDHash(ref id) => Ok(Atom::from(id.as_ref())), Token::IDHash(ref id) => Ok(Atom::from(id.as_ref())),
@ -190,7 +190,7 @@ impl Image {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Image, ParseError<'i>> { ) -> Result<Image, ParseError<'i>> {
if let Ok(url) = if let Ok(url) =
input.r#try(|input| SpecifiedImageUrl::parse_with_cors_anonymous(context, input)) input.try(|input| SpecifiedImageUrl::parse_with_cors_anonymous(context, input))
{ {
return Ok(generic::Image::Url(url)); return Ok(generic::Image::Url(url));
} }
@ -350,7 +350,7 @@ impl Gradient {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
input.r#try(|i| { input.try(|i| {
let x = Component::parse(context, i)?; let x = Component::parse(context, i)?;
let y = Component::parse(context, i)?; let y = Component::parse(context, i)?;
@ -413,13 +413,13 @@ impl Gradient {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(side) = input.r#try(|i| S::parse(context, i)) { if let Ok(side) = input.try(|i| S::parse(context, i)) {
return Ok(Component::Side(side)); return Ok(Component::Side(side));
} }
if let Ok(number) = input.r#try(|i| NumberOrPercentage::parse(context, i)) { if let Ok(number) = input.try(|i| NumberOrPercentage::parse(context, i)) {
return Ok(Component::Number(number)); return Ok(Component::Number(number));
} }
input.r#try(|i| i.expect_ident_matching("center"))?; input.try(|i| i.expect_ident_matching("center"))?;
Ok(Component::Center) Ok(Component::Center)
} }
} }
@ -477,7 +477,7 @@ impl Gradient {
}; };
let mut items = input let mut items = input
.r#try(|i| { .try(|i| {
i.expect_comma()?; i.expect_comma()?;
i.parse_comma_separated(|i| { i.parse_comma_separated(|i| {
let function = i.expect_function()?.clone(); let function = i.expect_function()?.clone();
@ -572,8 +572,8 @@ impl GradientKind {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
compat_mode: &mut CompatMode, compat_mode: &mut CompatMode,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let direction = let direction = if let Ok(d) = input.try(|i| LineDirection::parse(context, i, compat_mode))
if let Ok(d) = input.r#try(|i| LineDirection::parse(context, i, compat_mode)) { {
input.expect_comma()?; input.expect_comma()?;
d d
} else { } else {
@ -592,16 +592,16 @@ impl GradientKind {
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let (shape, position, angle, moz_position) = match *compat_mode { let (shape, position, angle, moz_position) = match *compat_mode {
CompatMode::Modern => { CompatMode::Modern => {
let shape = input.r#try(|i| EndingShape::parse(context, i, *compat_mode)); let shape = input.try(|i| EndingShape::parse(context, i, *compat_mode));
let position = input.r#try(|i| { let position = input.try(|i| {
i.expect_ident_matching("at")?; i.expect_ident_matching("at")?;
Position::parse(context, i) Position::parse(context, i)
}); });
(shape, position.ok(), None, None) (shape, position.ok(), None, None)
}, },
CompatMode::WebKit => { CompatMode::WebKit => {
let position = input.r#try(|i| Position::parse(context, i)); let position = input.try(|i| Position::parse(context, i));
let shape = input.r#try(|i| { let shape = input.try(|i| {
if position.is_ok() { if position.is_ok() {
i.expect_comma()?; i.expect_comma()?;
} }
@ -620,13 +620,13 @@ impl GradientKind {
// cover | contain // cover | contain
// and <color-stop> = <color> [ <percentage> | <length> ]? // and <color-stop> = <color> [ <percentage> | <length> ]?
CompatMode::Moz => { CompatMode::Moz => {
let mut position = input.r#try(|i| LegacyPosition::parse(context, i)); let mut position = input.try(|i| LegacyPosition::parse(context, i));
let angle = input.r#try(|i| Angle::parse(context, i)).ok(); let angle = input.try(|i| Angle::parse(context, i)).ok();
if position.is_err() { if position.is_err() {
position = input.r#try(|i| LegacyPosition::parse(context, i)); position = input.try(|i| LegacyPosition::parse(context, i));
} }
let shape = input.r#try(|i| { let shape = input.try(|i| {
if position.is_ok() || angle.is_some() { if position.is_ok() || angle.is_some() {
i.expect_comma()?; i.expect_comma()?;
} }
@ -768,18 +768,18 @@ impl LineDirection {
compat_mode: &mut CompatMode, compat_mode: &mut CompatMode,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let mut _angle = if *compat_mode == CompatMode::Moz { let mut _angle = if *compat_mode == CompatMode::Moz {
input.r#try(|i| Angle::parse(context, i)).ok() input.try(|i| Angle::parse(context, i)).ok()
} else { } else {
// Gradients allow unitless zero angles as an exception, see: // Gradients allow unitless zero angles as an exception, see:
// https://github.com/w3c/csswg-drafts/issues/1162 // https://github.com/w3c/csswg-drafts/issues/1162
if let Ok(angle) = input.r#try(|i| Angle::parse_with_unitless(context, i)) { if let Ok(angle) = input.try(|i| Angle::parse_with_unitless(context, i)) {
return Ok(LineDirection::Angle(angle)); return Ok(LineDirection::Angle(angle));
} }
None None
}; };
input.r#try(|i| { input.try(|i| {
let to_ident = i.r#try(|i| i.expect_ident_matching("to")); let to_ident = i.try(|i| i.expect_ident_matching("to"));
match *compat_mode { match *compat_mode {
// `to` keyword is mandatory in modern syntax. // `to` keyword is mandatory in modern syntax.
CompatMode::Modern => to_ident?, CompatMode::Modern => to_ident?,
@ -801,9 +801,9 @@ impl LineDirection {
{ {
// `-moz-` prefixed linear gradient can be both Angle and Position. // `-moz-` prefixed linear gradient can be both Angle and Position.
if *compat_mode == CompatMode::Moz { if *compat_mode == CompatMode::Moz {
let position = i.r#try(|i| LegacyPosition::parse(context, i)).ok(); let position = i.try(|i| LegacyPosition::parse(context, i)).ok();
if _angle.is_none() { if _angle.is_none() {
_angle = i.r#try(|i| Angle::parse(context, i)).ok(); _angle = i.try(|i| Angle::parse(context, i)).ok();
}; };
if _angle.is_none() && position.is_none() { if _angle.is_none() && position.is_none() {
@ -813,14 +813,14 @@ impl LineDirection {
} }
} }
if let Ok(x) = i.r#try(X::parse) { if let Ok(x) = i.try(X::parse) {
if let Ok(y) = i.r#try(Y::parse) { if let Ok(y) = i.try(Y::parse) {
return Ok(LineDirection::Corner(x, y)); return Ok(LineDirection::Corner(x, y));
} }
return Ok(LineDirection::Horizontal(x)); return Ok(LineDirection::Horizontal(x));
} }
let y = Y::parse(i)?; let y = Y::parse(i)?;
if let Ok(x) = i.r#try(X::parse) { if let Ok(x) = i.try(X::parse) {
return Ok(LineDirection::Corner(x, y)); return Ok(LineDirection::Corner(x, y));
} }
Ok(LineDirection::Vertical(y)) Ok(LineDirection::Vertical(y))
@ -850,20 +850,19 @@ impl EndingShape {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
compat_mode: CompatMode, compat_mode: CompatMode,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(extent) = input.r#try(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode)) { if let Ok(extent) = input.try(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode)) {
if input.r#try(|i| i.expect_ident_matching("circle")).is_ok() { if input.try(|i| i.expect_ident_matching("circle")).is_ok() {
return Ok(generic::EndingShape::Circle(Circle::Extent(extent))); return Ok(generic::EndingShape::Circle(Circle::Extent(extent)));
} }
let _ = input.r#try(|i| i.expect_ident_matching("ellipse")); let _ = input.try(|i| i.expect_ident_matching("ellipse"));
return Ok(generic::EndingShape::Ellipse(Ellipse::Extent(extent))); return Ok(generic::EndingShape::Ellipse(Ellipse::Extent(extent)));
} }
if input.r#try(|i| i.expect_ident_matching("circle")).is_ok() { if input.try(|i| i.expect_ident_matching("circle")).is_ok() {
if let Ok(extent) = input.r#try(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode)) if let Ok(extent) = input.try(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode)) {
{
return Ok(generic::EndingShape::Circle(Circle::Extent(extent))); return Ok(generic::EndingShape::Circle(Circle::Extent(extent)));
} }
if compat_mode == CompatMode::Modern { if compat_mode == CompatMode::Modern {
if let Ok(length) = input.r#try(|i| Length::parse(context, i)) { if let Ok(length) = input.try(|i| Length::parse(context, i)) {
return Ok(generic::EndingShape::Circle(Circle::Radius(length))); return Ok(generic::EndingShape::Circle(Circle::Radius(length)));
} }
} }
@ -871,13 +870,12 @@ impl EndingShape {
ShapeExtent::FarthestCorner, ShapeExtent::FarthestCorner,
))); )));
} }
if input.r#try(|i| i.expect_ident_matching("ellipse")).is_ok() { if input.try(|i| i.expect_ident_matching("ellipse")).is_ok() {
if let Ok(extent) = input.r#try(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode)) if let Ok(extent) = input.try(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode)) {
{
return Ok(generic::EndingShape::Ellipse(Ellipse::Extent(extent))); return Ok(generic::EndingShape::Ellipse(Ellipse::Extent(extent)));
} }
if compat_mode == CompatMode::Modern { if compat_mode == CompatMode::Modern {
let pair: Result<_, ParseError> = input.r#try(|i| { let pair: Result<_, ParseError> = input.try(|i| {
let x = LengthOrPercentage::parse(context, i)?; let x = LengthOrPercentage::parse(context, i)?;
let y = LengthOrPercentage::parse(context, i)?; let y = LengthOrPercentage::parse(context, i)?;
Ok((x, y)) Ok((x, y))
@ -893,10 +891,10 @@ impl EndingShape {
// -moz- prefixed radial gradient doesn't allow EndingShape's Length or LengthOrPercentage // -moz- prefixed radial gradient doesn't allow EndingShape's Length or LengthOrPercentage
// to come before shape keyword. Otherwise it conflicts with <position>. // to come before shape keyword. Otherwise it conflicts with <position>.
if compat_mode != CompatMode::Moz { if compat_mode != CompatMode::Moz {
if let Ok(length) = input.r#try(|i| Length::parse(context, i)) { if let Ok(length) = input.try(|i| Length::parse(context, i)) {
if let Ok(y) = input.r#try(|i| LengthOrPercentage::parse(context, i)) { if let Ok(y) = input.try(|i| LengthOrPercentage::parse(context, i)) {
if compat_mode == CompatMode::Modern { if compat_mode == CompatMode::Modern {
let _ = input.r#try(|i| i.expect_ident_matching("ellipse")); let _ = input.try(|i| i.expect_ident_matching("ellipse"));
} }
return Ok(generic::EndingShape::Ellipse(Ellipse::Radii( return Ok(generic::EndingShape::Ellipse(Ellipse::Radii(
length.into(), length.into(),
@ -904,7 +902,7 @@ impl EndingShape {
))); )));
} }
if compat_mode == CompatMode::Modern { if compat_mode == CompatMode::Modern {
let y = input.r#try(|i| { let y = input.try(|i| {
i.expect_ident_matching("ellipse")?; i.expect_ident_matching("ellipse")?;
LengthOrPercentage::parse(context, i) LengthOrPercentage::parse(context, i)
}); });
@ -914,17 +912,17 @@ impl EndingShape {
y, y,
))); )));
} }
let _ = input.r#try(|i| i.expect_ident_matching("circle")); let _ = input.try(|i| i.expect_ident_matching("circle"));
} }
return Ok(generic::EndingShape::Circle(Circle::Radius(length))); return Ok(generic::EndingShape::Circle(Circle::Radius(length)));
} }
} }
input.r#try(|i| { input.try(|i| {
let x = Percentage::parse(context, i)?; let x = Percentage::parse(context, i)?;
let y = if let Ok(y) = i.r#try(|i| LengthOrPercentage::parse(context, i)) { let y = if let Ok(y) = i.try(|i| LengthOrPercentage::parse(context, i)) {
if compat_mode == CompatMode::Modern { if compat_mode == CompatMode::Modern {
let _ = i.r#try(|i| i.expect_ident_matching("ellipse")); let _ = i.try(|i| i.expect_ident_matching("ellipse"));
} }
y y
} else { } else {
@ -965,7 +963,7 @@ impl GradientItem {
loop { loop {
input.parse_until_before(Delimiter::Comma, |input| { input.parse_until_before(Delimiter::Comma, |input| {
if seen_stop { if seen_stop {
if let Ok(hint) = input.r#try(|i| LengthOrPercentage::parse(context, i)) { if let Ok(hint) = input.try(|i| LengthOrPercentage::parse(context, i)) {
seen_stop = false; seen_stop = false;
items.push(generic::GradientItem::InterpolationHint(hint)); items.push(generic::GradientItem::InterpolationHint(hint));
return Ok(()); return Ok(());
@ -974,7 +972,7 @@ impl GradientItem {
let stop = ColorStop::parse(context, input)?; let stop = ColorStop::parse(context, input)?;
if let Ok(multi_position) = input.r#try(|i| LengthOrPercentage::parse(context, i)) { if let Ok(multi_position) = input.try(|i| LengthOrPercentage::parse(context, i)) {
let stop_color = stop.color.clone(); let stop_color = stop.color.clone();
items.push(generic::GradientItem::ColorStop(stop)); items.push(generic::GradientItem::ColorStop(stop));
items.push(generic::GradientItem::ColorStop(ColorStop { items.push(generic::GradientItem::ColorStop(ColorStop {
@ -1010,7 +1008,7 @@ impl Parse for ColorStop {
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
Ok(ColorStop { Ok(ColorStop {
color: Color::parse(context, input)?, color: Color::parse(context, input)?,
position: input.r#try(|i| LengthOrPercentage::parse(context, i)).ok(), position: input.try(|i| LengthOrPercentage::parse(context, i)).ok(),
}) })
} }
} }
@ -1024,7 +1022,7 @@ impl Parse for PaintWorklet {
input.parse_nested_block(|input| { input.parse_nested_block(|input| {
let name = Atom::from(&**input.expect_ident()?); let name = Atom::from(&**input.expect_ident()?);
let arguments = input let arguments = input
.r#try(|input| { .try(|input| {
input.expect_comma()?; input.expect_comma()?;
input.parse_comma_separated(|input| SpecifiedValue::parse(input)) input.parse_comma_separated(|input| SpecifiedValue::parse(input))
}) })
@ -1039,7 +1037,7 @@ impl Parse for MozImageRect {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
input.r#try(|i| i.expect_function_matching("-moz-image-rect"))?; input.try(|i| i.expect_function_matching("-moz-image-rect"))?;
input.parse_nested_block(|i| { input.parse_nested_block(|i| {
let string = i.expect_url_or_string()?; let string = i.expect_url_or_string()?;
let url = SpecifiedImageUrl::parse_from_string(string.as_ref().to_owned(), context); let url = SpecifiedImageUrl::parse_from_string(string.as_ref().to_owned(), context);

View file

@ -1228,7 +1228,7 @@ impl LengthOrNumber {
// We try to parse as a Number first because, for cases like // We try to parse as a Number first because, for cases like
// LengthOrNumber, we want "0" to be parsed as a plain Number rather // LengthOrNumber, we want "0" to be parsed as a plain Number rather
// than a Length (0px); this matches the behaviour of all major browsers // than a Length (0px); this matches the behaviour of all major browsers
if let Ok(v) = input.r#try(|i| Number::parse_non_negative(context, i)) { if let Ok(v) = input.try(|i| Number::parse_non_negative(context, i)) {
return Ok(Either::Second(v)); return Ok(Either::Second(v));
} }
@ -1272,7 +1272,7 @@ impl MozLength {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
allow_quirks: AllowQuirks, allow_quirks: AllowQuirks,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(l) = input.r#try(ExtremumLength::parse) { if let Ok(l) = input.try(ExtremumLength::parse) {
return Ok(GenericMozLength::ExtremumLength(l)); return Ok(GenericMozLength::ExtremumLength(l));
} }
@ -1324,7 +1324,7 @@ impl MaxLength {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
allow_quirks: AllowQuirks, allow_quirks: AllowQuirks,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(l) = input.r#try(ExtremumLength::parse) { if let Ok(l) = input.try(ExtremumLength::parse) {
return Ok(GenericMaxLength::ExtremumLength(l)); return Ok(GenericMaxLength::ExtremumLength(l));
} }

View file

@ -63,7 +63,7 @@ impl Parse for ListStyleType {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(style) = input.r#try(|i| CounterStyleOrNone::parse(context, i)) { if let Ok(style) = input.try(|i| CounterStyleOrNone::parse(context, i)) {
return Ok(ListStyleType::CounterStyle(style)); return Ok(ListStyleType::CounterStyle(style));
} }
@ -97,7 +97,7 @@ impl Parse for Quotes {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Quotes, ParseError<'i>> { ) -> Result<Quotes, ParseError<'i>> {
if input if input
.r#try(|input| input.expect_ident_matching("none")) .try(|input| input.expect_ident_matching("none"))
.is_ok() .is_ok()
{ {
return Ok(Quotes(Arc::new(Box::new([])))); return Ok(Quotes(Arc::new(Box::new([]))));

View file

@ -359,7 +359,7 @@ impl NumberOrPercentage {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
type_: AllowedNumericType, type_: AllowedNumericType,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(per) = input.r#try(|i| Percentage::parse_with_clamping_mode(context, i, type_)) { if let Ok(per) = input.try(|i| Percentage::parse_with_clamping_mode(context, i, type_)) {
return Ok(NumberOrPercentage::Percentage(per)); return Ok(NumberOrPercentage::Percentage(per));
} }
@ -703,7 +703,7 @@ impl ClipRect {
allow_quirks: AllowQuirks, allow_quirks: AllowQuirks,
) -> Result<Option<Length>, ParseError<'i>> { ) -> Result<Option<Length>, ParseError<'i>> {
if input if input
.r#try(|input| input.expect_ident_matching("auto")) .try(|input| input.expect_ident_matching("auto"))
.is_ok() .is_ok()
{ {
Ok(None) Ok(None)
@ -720,7 +720,7 @@ impl ClipRect {
let bottom; let bottom;
let left; let left;
if input.r#try(|input| input.expect_comma()).is_ok() { if input.try(|input| input.expect_comma()).is_ok() {
right = parse_argument(context, input, allow_quirks)?; right = parse_argument(context, input, allow_quirks)?;
input.expect_comma()?; input.expect_comma()?;
bottom = parse_argument(context, input, allow_quirks)?; bottom = parse_argument(context, input, allow_quirks)?;
@ -751,7 +751,7 @@ impl ClipRectOrAuto {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
allow_quirks: AllowQuirks, allow_quirks: AllowQuirks,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(v) = input.r#try(|i| ClipRect::parse_quirky(context, i, allow_quirks)) { if let Ok(v) = input.try(|i| ClipRect::parse_quirky(context, i, allow_quirks)) {
Ok(Either::First(v)) Ok(Either::First(v))
} else { } else {
Auto::parse(context, input).map(Either::Second) Auto::parse(context, input).map(Either::Second)
@ -816,8 +816,8 @@ impl Attr {
) -> Result<Attr, ParseError<'i>> { ) -> Result<Attr, ParseError<'i>> {
// Syntax is `[namespace? `|`]? ident` // Syntax is `[namespace? `|`]? ident`
// no spaces allowed // no spaces allowed
let first = input.r#try(|i| i.expect_ident_cloned()).ok(); let first = input.try(|i| i.expect_ident_cloned()).ok();
if let Ok(token) = input.r#try(|i| i.next_including_whitespace().map(|t| t.clone())) { if let Ok(token) = input.try(|i| i.next_including_whitespace().map(|t| t.clone())) {
match token { match token {
Token::Delim('|') => { Token::Delim('|') => {
let location = input.current_source_location(); let location = input.current_source_location();

View file

@ -50,7 +50,7 @@ impl Parse for OffsetPath {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
// Parse none. // Parse none.
if input.r#try(|i| i.expect_ident_matching("none")).is_ok() { if input.try(|i| i.expect_ident_matching("none")).is_ok() {
return Ok(OffsetPath::none()); return Ok(OffsetPath::none());
} }

View file

@ -53,7 +53,7 @@ impl Parse for OutlineStyle {
_context: &ParserContext, _context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<OutlineStyle, ParseError<'i>> { ) -> Result<OutlineStyle, ParseError<'i>> {
if let Ok(border_style) = input.r#try(BorderStyle::parse) { if let Ok(border_style) = input.try(BorderStyle::parse) {
if let BorderStyle::Hidden = border_style { if let BorderStyle::Hidden = border_style {
return Err(input return Err(input
.new_custom_error(SelectorParseErrorKind::UnexpectedIdent("hidden".into()))); .new_custom_error(SelectorParseErrorKind::UnexpectedIdent("hidden".into())));

View file

@ -102,28 +102,28 @@ impl Position {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
allow_quirks: AllowQuirks, allow_quirks: AllowQuirks,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
match input.r#try(|i| PositionComponent::parse_quirky(context, i, allow_quirks)) { match input.try(|i| PositionComponent::parse_quirky(context, i, allow_quirks)) {
Ok(x_pos @ PositionComponent::Center) => { Ok(x_pos @ PositionComponent::Center) => {
if let Ok(y_pos) = if let Ok(y_pos) =
input.r#try(|i| PositionComponent::parse_quirky(context, i, allow_quirks)) input.try(|i| PositionComponent::parse_quirky(context, i, allow_quirks))
{ {
return Ok(Self::new(x_pos, y_pos)); return Ok(Self::new(x_pos, y_pos));
} }
let x_pos = input let x_pos = input
.r#try(|i| PositionComponent::parse_quirky(context, i, allow_quirks)) .try(|i| PositionComponent::parse_quirky(context, i, allow_quirks))
.unwrap_or(x_pos); .unwrap_or(x_pos);
let y_pos = PositionComponent::Center; let y_pos = PositionComponent::Center;
return Ok(Self::new(x_pos, y_pos)); return Ok(Self::new(x_pos, y_pos));
}, },
Ok(PositionComponent::Side(x_keyword, lop)) => { Ok(PositionComponent::Side(x_keyword, lop)) => {
if input.r#try(|i| i.expect_ident_matching("center")).is_ok() { if input.try(|i| i.expect_ident_matching("center")).is_ok() {
let x_pos = PositionComponent::Side(x_keyword, lop); let x_pos = PositionComponent::Side(x_keyword, lop);
let y_pos = PositionComponent::Center; let y_pos = PositionComponent::Center;
return Ok(Self::new(x_pos, y_pos)); return Ok(Self::new(x_pos, y_pos));
} }
if let Ok(y_keyword) = input.r#try(Y::parse) { if let Ok(y_keyword) = input.try(Y::parse) {
let y_lop = input let y_lop = input
.r#try(|i| LengthOrPercentage::parse_quirky(context, i, allow_quirks)) .try(|i| LengthOrPercentage::parse_quirky(context, i, allow_quirks))
.ok(); .ok();
let x_pos = PositionComponent::Side(x_keyword, lop); let x_pos = PositionComponent::Side(x_keyword, lop);
let y_pos = PositionComponent::Side(y_keyword, y_lop); let y_pos = PositionComponent::Side(y_keyword, y_lop);
@ -134,30 +134,30 @@ impl Position {
return Ok(Self::new(x_pos, y_pos)); return Ok(Self::new(x_pos, y_pos));
}, },
Ok(x_pos @ PositionComponent::Length(_)) => { Ok(x_pos @ PositionComponent::Length(_)) => {
if let Ok(y_keyword) = input.r#try(Y::parse) { if let Ok(y_keyword) = input.try(Y::parse) {
let y_pos = PositionComponent::Side(y_keyword, None); let y_pos = PositionComponent::Side(y_keyword, None);
return Ok(Self::new(x_pos, y_pos)); return Ok(Self::new(x_pos, y_pos));
} }
if let Ok(y_lop) = if let Ok(y_lop) =
input.r#try(|i| LengthOrPercentage::parse_quirky(context, i, allow_quirks)) input.try(|i| LengthOrPercentage::parse_quirky(context, i, allow_quirks))
{ {
let y_pos = PositionComponent::Length(y_lop); let y_pos = PositionComponent::Length(y_lop);
return Ok(Self::new(x_pos, y_pos)); return Ok(Self::new(x_pos, y_pos));
} }
let y_pos = PositionComponent::Center; let y_pos = PositionComponent::Center;
let _ = input.r#try(|i| i.expect_ident_matching("center")); let _ = input.try(|i| i.expect_ident_matching("center"));
return Ok(Self::new(x_pos, y_pos)); return Ok(Self::new(x_pos, y_pos));
}, },
Err(_) => {}, Err(_) => {},
} }
let y_keyword = Y::parse(input)?; let y_keyword = Y::parse(input)?;
let lop_and_x_pos: Result<_, ParseError> = input.r#try(|i| { let lop_and_x_pos: Result<_, ParseError> = input.try(|i| {
let y_lop = i let y_lop = i
.r#try(|i| LengthOrPercentage::parse_quirky(context, i, allow_quirks)) .try(|i| LengthOrPercentage::parse_quirky(context, i, allow_quirks))
.ok(); .ok();
if let Ok(x_keyword) = i.r#try(X::parse) { if let Ok(x_keyword) = i.try(X::parse) {
let x_lop = i let x_lop = i
.r#try(|i| LengthOrPercentage::parse_quirky(context, i, allow_quirks)) .try(|i| LengthOrPercentage::parse_quirky(context, i, allow_quirks))
.ok(); .ok();
let x_pos = PositionComponent::Side(x_keyword, x_lop); let x_pos = PositionComponent::Side(x_keyword, x_lop);
return Ok((y_lop, x_pos)); return Ok((y_lop, x_pos));
@ -230,16 +230,15 @@ impl<S: Parse> PositionComponent<S> {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
allow_quirks: AllowQuirks, allow_quirks: AllowQuirks,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if input.r#try(|i| i.expect_ident_matching("center")).is_ok() { if input.try(|i| i.expect_ident_matching("center")).is_ok() {
return Ok(PositionComponent::Center); return Ok(PositionComponent::Center);
} }
if let Ok(lop) = input.r#try(|i| LengthOrPercentage::parse_quirky(context, i, allow_quirks)) if let Ok(lop) = input.try(|i| LengthOrPercentage::parse_quirky(context, i, allow_quirks)) {
{
return Ok(PositionComponent::Length(lop)); return Ok(PositionComponent::Length(lop));
} }
let keyword = S::parse(context, input)?; let keyword = S::parse(context, input)?;
let lop = input let lop = input
.r#try(|i| LengthOrPercentage::parse_quirky(context, i, allow_quirks)) .try(|i| LengthOrPercentage::parse_quirky(context, i, allow_quirks))
.ok(); .ok();
Ok(PositionComponent::Side(keyword, lop)) Ok(PositionComponent::Side(keyword, lop))
} }
@ -360,51 +359,51 @@ impl LegacyPosition {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
allow_quirks: AllowQuirks, allow_quirks: AllowQuirks,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
match input.r#try(|i| OriginComponent::parse(context, i)) { match input.try(|i| OriginComponent::parse(context, i)) {
Ok(x_pos @ OriginComponent::Center) => { Ok(x_pos @ OriginComponent::Center) => {
if let Ok(y_pos) = input.r#try(|i| OriginComponent::parse(context, i)) { if let Ok(y_pos) = input.try(|i| OriginComponent::parse(context, i)) {
return Ok(Self::new(x_pos, y_pos)); return Ok(Self::new(x_pos, y_pos));
} }
let x_pos = input let x_pos = input
.r#try(|i| OriginComponent::parse(context, i)) .try(|i| OriginComponent::parse(context, i))
.unwrap_or(x_pos); .unwrap_or(x_pos);
let y_pos = OriginComponent::Center; let y_pos = OriginComponent::Center;
return Ok(Self::new(x_pos, y_pos)); return Ok(Self::new(x_pos, y_pos));
}, },
Ok(OriginComponent::Side(x_keyword)) => { Ok(OriginComponent::Side(x_keyword)) => {
if let Ok(y_keyword) = input.r#try(Y::parse) { if let Ok(y_keyword) = input.try(Y::parse) {
let x_pos = OriginComponent::Side(x_keyword); let x_pos = OriginComponent::Side(x_keyword);
let y_pos = OriginComponent::Side(y_keyword); let y_pos = OriginComponent::Side(y_keyword);
return Ok(Self::new(x_pos, y_pos)); return Ok(Self::new(x_pos, y_pos));
} }
let x_pos = OriginComponent::Side(x_keyword); let x_pos = OriginComponent::Side(x_keyword);
if let Ok(y_lop) = if let Ok(y_lop) =
input.r#try(|i| LengthOrPercentage::parse_quirky(context, i, allow_quirks)) input.try(|i| LengthOrPercentage::parse_quirky(context, i, allow_quirks))
{ {
return Ok(Self::new(x_pos, OriginComponent::Length(y_lop))); return Ok(Self::new(x_pos, OriginComponent::Length(y_lop)));
} }
let _ = input.r#try(|i| i.expect_ident_matching("center")); let _ = input.try(|i| i.expect_ident_matching("center"));
return Ok(Self::new(x_pos, OriginComponent::Center)); return Ok(Self::new(x_pos, OriginComponent::Center));
}, },
Ok(x_pos @ OriginComponent::Length(_)) => { Ok(x_pos @ OriginComponent::Length(_)) => {
if let Ok(y_keyword) = input.r#try(Y::parse) { if let Ok(y_keyword) = input.try(Y::parse) {
let y_pos = OriginComponent::Side(y_keyword); let y_pos = OriginComponent::Side(y_keyword);
return Ok(Self::new(x_pos, y_pos)); return Ok(Self::new(x_pos, y_pos));
} }
if let Ok(y_lop) = if let Ok(y_lop) =
input.r#try(|i| LengthOrPercentage::parse_quirky(context, i, allow_quirks)) input.try(|i| LengthOrPercentage::parse_quirky(context, i, allow_quirks))
{ {
let y_pos = OriginComponent::Length(y_lop); let y_pos = OriginComponent::Length(y_lop);
return Ok(Self::new(x_pos, y_pos)); return Ok(Self::new(x_pos, y_pos));
} }
let _ = input.r#try(|i| i.expect_ident_matching("center")); let _ = input.try(|i| i.expect_ident_matching("center"));
return Ok(Self::new(x_pos, OriginComponent::Center)); return Ok(Self::new(x_pos, OriginComponent::Center));
}, },
Err(_) => {}, Err(_) => {},
} }
let y_keyword = Y::parse(input)?; let y_keyword = Y::parse(input)?;
let x_pos: Result<_, ParseError> = input.r#try(|i| { let x_pos: Result<_, ParseError> = input.try(|i| {
if let Ok(x_keyword) = i.r#try(X::parse) { if let Ok(x_keyword) = i.try(X::parse) {
let x_pos = OriginComponent::Side(x_keyword); let x_pos = OriginComponent::Side(x_keyword);
return Ok(x_pos); return Ok(x_pos);
} }
@ -649,7 +648,7 @@ impl Parse for TemplateAreas {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let mut strings = vec![]; let mut strings = vec![];
while let Ok(string) = input.r#try(|i| i.expect_string().map(|s| s.as_ref().into())) { while let Ok(string) = input.try(|i| i.expect_string().map(|s| s.as_ref().into())) {
strings.push(string); strings.push(string);
} }
@ -743,7 +742,7 @@ impl Parse for ZIndex {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if input.r#try(|i| i.expect_ident_matching("auto")).is_ok() { if input.try(|i| i.expect_ident_matching("auto")).is_ok() {
return Ok(GenericZIndex::Auto); return Ok(GenericZIndex::Auto);
} }
Ok(GenericZIndex::Integer(Integer::parse(context, input)?)) Ok(GenericZIndex::Integer(Integer::parse(context, input)?))

View file

@ -92,7 +92,7 @@ impl Parse for SourceSizeOrLength {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(size) = input.r#try(|input| SourceSize::parse(context, input)) { if let Ok(size) = input.try(|input| SourceSize::parse(context, input)) {
return Ok(SourceSizeOrLength::SourceSize(size)); return Ok(SourceSizeOrLength::SourceSize(size));
} }

View file

@ -63,7 +63,7 @@ impl Parse for SVGLength {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
input input
.r#try(|i| SvgLengthOrPercentageOrNumber::parse(context, i)) .try(|i| SvgLengthOrPercentageOrNumber::parse(context, i))
.map(Into::into) .map(Into::into)
.or_else(|_| parse_context_value(input, generic::SVGLength::ContextValue)) .or_else(|_| parse_context_value(input, generic::SVGLength::ContextValue))
} }
@ -89,7 +89,7 @@ impl Parse for SVGWidth {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
input input
.r#try(|i| NonNegativeSvgLengthOrPercentageOrNumber::parse(context, i)) .try(|i| NonNegativeSvgLengthOrPercentageOrNumber::parse(context, i))
.map(Into::into) .map(Into::into)
.or_else(|_| parse_context_value(input, generic::SVGLength::ContextValue)) .or_else(|_| parse_context_value(input, generic::SVGLength::ContextValue))
} }
@ -109,13 +109,13 @@ impl Parse for SVGStrokeDashArray {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(values) = input.r#try(|i| { if let Ok(values) = input.try(|i| {
CommaWithSpace::parse(i, |i| { CommaWithSpace::parse(i, |i| {
NonNegativeSvgLengthOrPercentageOrNumber::parse(context, i) NonNegativeSvgLengthOrPercentageOrNumber::parse(context, i)
}) })
}) { }) {
Ok(generic::SVGStrokeDashArray::Values(values)) Ok(generic::SVGStrokeDashArray::Values(values))
} else if let Ok(_) = input.r#try(|i| i.expect_ident_matching("none")) { } else if let Ok(_) = input.try(|i| i.expect_ident_matching("none")) {
Ok(generic::SVGStrokeDashArray::Values(vec![])) Ok(generic::SVGStrokeDashArray::Values(vec![]))
} else { } else {
parse_context_value(input, generic::SVGStrokeDashArray::ContextValue) parse_context_value(input, generic::SVGStrokeDashArray::ContextValue)
@ -131,7 +131,7 @@ impl Parse for SVGOpacity {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(opacity) = input.r#try(|i| Opacity::parse(context, i)) { if let Ok(opacity) = input.try(|i| Opacity::parse(context, i)) {
return Ok(generic::SVGOpacity::Opacity(opacity)); return Ok(generic::SVGOpacity::Opacity(opacity));
} }
@ -196,7 +196,7 @@ impl Parse for SVGPaintOrder {
_context: &ParserContext, _context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<SVGPaintOrder, ParseError<'i>> { ) -> Result<SVGPaintOrder, ParseError<'i>> {
if let Ok(()) = input.r#try(|i| i.expect_ident_matching("normal")) { if let Ok(()) = input.try(|i| i.expect_ident_matching("normal")) {
return Ok(SVGPaintOrder::normal()); return Ok(SVGPaintOrder::normal());
} }
@ -207,7 +207,7 @@ impl Parse for SVGPaintOrder {
let mut pos = 0; let mut pos = 0;
loop { loop {
let result: Result<_, ParseError> = input.r#try(|input| { let result: Result<_, ParseError> = input.try(|input| {
try_match_ident_ignore_ascii_case! { input, try_match_ident_ignore_ascii_case! { input,
"fill" => Ok(PaintOrder::Fill), "fill" => Ok(PaintOrder::Fill),
"stroke" => Ok(PaintOrder::Stroke), "stroke" => Ok(PaintOrder::Stroke),

View file

@ -45,11 +45,11 @@ impl Parse for InitialLetter {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if input.r#try(|i| i.expect_ident_matching("normal")).is_ok() { if input.try(|i| i.expect_ident_matching("normal")).is_ok() {
return Ok(GenericInitialLetter::Normal); return Ok(GenericInitialLetter::Normal);
} }
let size = Number::parse_at_least_one(context, input)?; let size = Number::parse_at_least_one(context, input)?;
let sink = input.r#try(|i| Integer::parse_positive(context, i)).ok(); let sink = input.try(|i| Integer::parse_positive(context, i)).ok();
Ok(GenericInitialLetter::Specified(size, sink)) Ok(GenericInitialLetter::Specified(size, sink))
} }
} }
@ -81,10 +81,10 @@ impl Parse for LineHeight {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(number) = input.r#try(|i| NonNegativeNumber::parse(context, i)) { if let Ok(number) = input.try(|i| NonNegativeNumber::parse(context, i)) {
return Ok(GenericLineHeight::Number(number)); return Ok(GenericLineHeight::Number(number));
} }
if let Ok(nlop) = input.r#try(|i| NonNegativeLengthOrPercentage::parse(context, i)) { if let Ok(nlop) = input.try(|i| NonNegativeLengthOrPercentage::parse(context, i)) {
return Ok(GenericLineHeight::Length(nlop)); return Ok(GenericLineHeight::Length(nlop));
} }
let location = input.current_source_location(); let location = input.current_source_location();
@ -215,7 +215,7 @@ impl Parse for TextOverflow {
) -> Result<TextOverflow, ParseError<'i>> { ) -> Result<TextOverflow, ParseError<'i>> {
let first = TextOverflowSide::parse(context, input)?; let first = TextOverflowSide::parse(context, input)?;
let second = input let second = input
.r#try(|input| TextOverflowSide::parse(context, input)) .try(|input| TextOverflowSide::parse(context, input))
.ok(); .ok();
Ok(TextOverflow { first, second }) Ok(TextOverflow { first, second })
} }
@ -295,14 +295,14 @@ macro_rules! impl_text_decoration_line {
) -> Result<TextDecorationLine, ParseError<'i>> { ) -> Result<TextDecorationLine, ParseError<'i>> {
let mut result = TextDecorationLine::NONE; let mut result = TextDecorationLine::NONE;
if input if input
.r#try(|input| input.expect_ident_matching("none")) .try(|input| input.expect_ident_matching("none"))
.is_ok() .is_ok()
{ {
return Ok(result); return Ok(result);
} }
loop { loop {
let result = input.r#try(|input| { let result = input.try(|input| {
let ident = input.expect_ident().map_err(|_| ())?; let ident = input.expect_ident().map_err(|_| ())?;
match_ignore_ascii_case! { ident, match_ignore_ascii_case! { ident,
$( $(
@ -444,7 +444,7 @@ impl Parse for TextAlign {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
// MozCenterOrInherit cannot be parsed, only set directly on the elements // MozCenterOrInherit cannot be parsed, only set directly on the elements
if let Ok(key) = input.r#try(TextAlignKeyword::parse) { if let Ok(key) = input.try(TextAlignKeyword::parse) {
return Ok(TextAlign::Keyword(key)); return Ok(TextAlign::Keyword(key));
} }
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
@ -678,22 +678,22 @@ impl Parse for TextEmphasisStyle {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if input if input
.r#try(|input| input.expect_ident_matching("none")) .try(|input| input.expect_ident_matching("none"))
.is_ok() .is_ok()
{ {
return Ok(TextEmphasisStyle::None); return Ok(TextEmphasisStyle::None);
} }
if let Ok(s) = input.r#try(|i| i.expect_string().map(|s| s.as_ref().to_owned())) { if let Ok(s) = input.try(|i| i.expect_string().map(|s| s.as_ref().to_owned())) {
// Handle <string> // Handle <string>
return Ok(TextEmphasisStyle::String(s)); return Ok(TextEmphasisStyle::String(s));
} }
// Handle a pair of keywords // Handle a pair of keywords
let mut shape = input.r#try(TextEmphasisShapeKeyword::parse).ok(); let mut shape = input.try(TextEmphasisShapeKeyword::parse).ok();
let fill = input.r#try(TextEmphasisFillMode::parse).ok(); let fill = input.try(TextEmphasisFillMode::parse).ok();
if shape.is_none() { if shape.is_none() {
shape = input.r#try(TextEmphasisShapeKeyword::parse).ok(); shape = input.try(TextEmphasisShapeKeyword::parse).ok();
} }
// At least one of shape or fill must be handled // At least one of shape or fill must be handled
@ -793,7 +793,7 @@ impl Parse for TextEmphasisPosition {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(horizontal) = if let Ok(horizontal) =
input.r#try(|input| TextEmphasisHorizontalWritingModeValue::parse(input)) input.try(|input| TextEmphasisHorizontalWritingModeValue::parse(input))
{ {
let vertical = TextEmphasisVerticalWritingModeValue::parse(input)?; let vertical = TextEmphasisVerticalWritingModeValue::parse(input)?;
Ok(TextEmphasisPosition(horizontal, vertical)) Ok(TextEmphasisPosition(horizontal, vertical))
@ -845,7 +845,7 @@ impl Parse for MozTabSize {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if let Ok(number) = input.r#try(|i| NonNegativeNumber::parse(context, i)) { if let Ok(number) = input.try(|i| NonNegativeNumber::parse(context, i)) {
// Numbers need to be parsed first because `0` must be recognised // Numbers need to be parsed first because `0` must be recognised
// as the number `0` and not the length `0px`. // as the number `0` and not the length `0px`.
return Ok(GenericMozTabSize::Number(number)); return Ok(GenericMozTabSize::Number(number));

View file

@ -38,7 +38,7 @@ impl Transform {
use style_traits::{Separator, Space}; use style_traits::{Separator, Space};
if input if input
.r#try(|input| input.expect_ident_matching("none")) .try(|input| input.expect_ident_matching("none"))
.is_ok() .is_ok()
{ {
return Ok(generic::Transform(Vec::new())); return Ok(generic::Transform(Vec::new()));
@ -106,7 +106,7 @@ impl Transform {
}, },
"translate" => { "translate" => {
let sx = specified::LengthOrPercentage::parse(context, input)?; let sx = specified::LengthOrPercentage::parse(context, input)?;
if input.r#try(|input| input.expect_comma()).is_ok() { if input.try(|input| input.expect_comma()).is_ok() {
let sy = specified::LengthOrPercentage::parse(context, input)?; let sy = specified::LengthOrPercentage::parse(context, input)?;
Ok(generic::TransformOperation::Translate(sx, Some(sy))) Ok(generic::TransformOperation::Translate(sx, Some(sy)))
} else { } else {
@ -135,7 +135,7 @@ impl Transform {
}, },
"scale" => { "scale" => {
let sx = Number::parse(context, input)?; let sx = Number::parse(context, input)?;
if input.r#try(|input| input.expect_comma()).is_ok() { if input.try(|input| input.expect_comma()).is_ok() {
let sy = Number::parse(context, input)?; let sy = Number::parse(context, input)?;
Ok(generic::TransformOperation::Scale(sx, Some(sy))) Ok(generic::TransformOperation::Scale(sx, Some(sy)))
} else { } else {
@ -191,7 +191,7 @@ impl Transform {
}, },
"skew" => { "skew" => {
let ax = specified::Angle::parse_with_unitless(context, input)?; let ax = specified::Angle::parse_with_unitless(context, input)?;
if input.r#try(|input| input.expect_comma()).is_ok() { if input.try(|input| input.expect_comma()).is_ok() {
let ay = specified::Angle::parse_with_unitless(context, input)?; let ay = specified::Angle::parse_with_unitless(context, input)?;
Ok(generic::TransformOperation::Skew(ax, Some(ay))) Ok(generic::TransformOperation::Skew(ax, Some(ay)))
} else { } else {
@ -248,17 +248,17 @@ impl Parse for TransformOrigin {
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let parse_depth = |input: &mut Parser| { let parse_depth = |input: &mut Parser| {
input input
.r#try(|i| Length::parse(context, i)) .try(|i| Length::parse(context, i))
.unwrap_or(Length::from_px(0.)) .unwrap_or(Length::from_px(0.))
}; };
match input.r#try(|i| OriginComponent::parse(context, i)) { match input.try(|i| OriginComponent::parse(context, i)) {
Ok(x_origin @ OriginComponent::Center) => { Ok(x_origin @ OriginComponent::Center) => {
if let Ok(y_origin) = input.r#try(|i| OriginComponent::parse(context, i)) { if let Ok(y_origin) = input.try(|i| OriginComponent::parse(context, i)) {
let depth = parse_depth(input); let depth = parse_depth(input);
return Ok(Self::new(x_origin, y_origin, depth)); return Ok(Self::new(x_origin, y_origin, depth));
} }
let y_origin = OriginComponent::Center; let y_origin = OriginComponent::Center;
if let Ok(x_keyword) = input.r#try(X::parse) { if let Ok(x_keyword) = input.try(X::parse) {
let x_origin = OriginComponent::Side(x_keyword); let x_origin = OriginComponent::Side(x_keyword);
let depth = parse_depth(input); let depth = parse_depth(input);
return Ok(Self::new(x_origin, y_origin, depth)); return Ok(Self::new(x_origin, y_origin, depth));
@ -267,7 +267,7 @@ impl Parse for TransformOrigin {
return Ok(Self::new(x_origin, y_origin, depth)); return Ok(Self::new(x_origin, y_origin, depth));
}, },
Ok(x_origin) => { Ok(x_origin) => {
if let Ok(y_origin) = input.r#try(|i| OriginComponent::parse(context, i)) { if let Ok(y_origin) = input.try(|i| OriginComponent::parse(context, i)) {
let depth = parse_depth(input); let depth = parse_depth(input);
return Ok(Self::new(x_origin, y_origin, depth)); return Ok(Self::new(x_origin, y_origin, depth));
} }
@ -279,12 +279,12 @@ impl Parse for TransformOrigin {
} }
let y_keyword = Y::parse(input)?; let y_keyword = Y::parse(input)?;
let y_origin = OriginComponent::Side(y_keyword); let y_origin = OriginComponent::Side(y_keyword);
if let Ok(x_keyword) = input.r#try(X::parse) { if let Ok(x_keyword) = input.try(X::parse) {
let x_origin = OriginComponent::Side(x_keyword); let x_origin = OriginComponent::Side(x_keyword);
let depth = parse_depth(input); let depth = parse_depth(input);
return Ok(Self::new(x_origin, y_origin, depth)); return Ok(Self::new(x_origin, y_origin, depth));
} }
if input.r#try(|i| i.expect_ident_matching("center")).is_ok() { if input.try(|i| i.expect_ident_matching("center")).is_ok() {
let x_origin = OriginComponent::Center; let x_origin = OriginComponent::Center;
let depth = parse_depth(input); let depth = parse_depth(input);
return Ok(Self::new(x_origin, y_origin, depth)); return Ok(Self::new(x_origin, y_origin, depth));
@ -303,10 +303,10 @@ where
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if input.r#try(|i| i.expect_ident_matching("center")).is_ok() { if input.try(|i| i.expect_ident_matching("center")).is_ok() {
return Ok(OriginComponent::Center); return Ok(OriginComponent::Center);
} }
if let Ok(lop) = input.r#try(|i| LengthOrPercentage::parse(context, i)) { if let Ok(lop) = input.try(|i| LengthOrPercentage::parse(context, i)) {
return Ok(OriginComponent::Length(lop)); return Ok(OriginComponent::Length(lop));
} }
let keyword = S::parse(context, input)?; let keyword = S::parse(context, input)?;
@ -353,11 +353,11 @@ impl Parse for Rotate {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if input.r#try(|i| i.expect_ident_matching("none")).is_ok() { if input.try(|i| i.expect_ident_matching("none")).is_ok() {
return Ok(generic::Rotate::None); return Ok(generic::Rotate::None);
} }
if let Ok(rx) = input.r#try(|i| Number::parse(context, i)) { if let Ok(rx) = input.try(|i| Number::parse(context, i)) {
// 'rotate: <number>{3} <angle>' // 'rotate: <number>{3} <angle>'
let ry = Number::parse(context, input)?; let ry = Number::parse(context, input)?;
let rz = Number::parse(context, input)?; let rz = Number::parse(context, input)?;
@ -379,13 +379,13 @@ impl Parse for Translate {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if input.r#try(|i| i.expect_ident_matching("none")).is_ok() { if input.try(|i| i.expect_ident_matching("none")).is_ok() {
return Ok(generic::Translate::None); return Ok(generic::Translate::None);
} }
let tx = specified::LengthOrPercentage::parse(context, input)?; let tx = specified::LengthOrPercentage::parse(context, input)?;
if let Ok(ty) = input.r#try(|i| specified::LengthOrPercentage::parse(context, i)) { if let Ok(ty) = input.try(|i| specified::LengthOrPercentage::parse(context, i)) {
if let Ok(tz) = input.r#try(|i| specified::Length::parse(context, i)) { if let Ok(tz) = input.try(|i| specified::Length::parse(context, i)) {
// 'translate: <length-percentage> <length-percentage> <length>' // 'translate: <length-percentage> <length-percentage> <length>'
return Ok(generic::Translate::Translate3D(tx, ty, tz)); return Ok(generic::Translate::Translate3D(tx, ty, tz));
} }
@ -410,13 +410,13 @@ impl Parse for Scale {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if input.r#try(|i| i.expect_ident_matching("none")).is_ok() { if input.try(|i| i.expect_ident_matching("none")).is_ok() {
return Ok(generic::Scale::None); return Ok(generic::Scale::None);
} }
let sx = Number::parse(context, input)?; let sx = Number::parse(context, input)?;
if let Ok(sy) = input.r#try(|i| Number::parse(context, i)) { if let Ok(sy) = input.try(|i| Number::parse(context, i)) {
if let Ok(sz) = input.r#try(|i| Number::parse(context, i)) { if let Ok(sz) = input.try(|i| Number::parse(context, i)) {
// 'scale: <number> <number> <number>' // 'scale: <number> <number> <number>'
return Ok(generic::Scale::Scale3D(sx, sy, sz)); return Ok(generic::Scale::Scale3D(sx, sy, sz));
} }

View file

@ -32,7 +32,7 @@ impl Parse for Cursor {
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let mut images = vec![]; let mut images = vec![];
loop { loop {
match input.r#try(|input| CursorImage::parse(context, input)) { match input.try(|input| CursorImage::parse(context, input)) {
Ok(image) => images.push(image), Ok(image) => images.push(image),
Err(_) => break, Err(_) => break,
} }
@ -64,7 +64,7 @@ impl Parse for CursorImage {
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
Ok(Self { Ok(Self {
url: SpecifiedImageUrl::parse(context, input)?, url: SpecifiedImageUrl::parse(context, input)?,
hotspot: match input.r#try(|input| Number::parse(context, input)) { hotspot: match input.try(|input| Number::parse(context, input)) {
Ok(number) => Some((number, Number::parse(context, input)?)), Ok(number) => Some((number, Number::parse(context, input)?)),
Err(_) => None, Err(_) => None,
}, },
@ -131,7 +131,7 @@ impl Parse for ScrollbarColor {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
if input.r#try(|i| i.expect_ident_matching("auto")).is_ok() { if input.try(|i| i.expect_ident_matching("auto")).is_ok() {
return Ok(generics::ScrollbarColor::Auto); return Ok(generics::ScrollbarColor::Auto);
} }
Ok(generics::ScrollbarColor::Colors { Ok(generics::ScrollbarColor::Colors {

View file

@ -324,7 +324,7 @@ impl Separator for Space {
let mut results = vec![parse_one(input)?]; let mut results = vec![parse_one(input)?];
loop { loop {
input.skip_whitespace(); // Unnecessary for correctness, but may help try() rewind less. input.skip_whitespace(); // Unnecessary for correctness, but may help try() rewind less.
if let Ok(item) = input.r#try(&mut parse_one) { if let Ok(item) = input.try(&mut parse_one) {
results.push(item); results.push(item);
} else { } else {
return Ok(results); return Ok(results);
@ -350,9 +350,9 @@ impl Separator for CommaWithSpace {
loop { loop {
input.skip_whitespace(); // Unnecessary for correctness, but may help try() rewind less. input.skip_whitespace(); // Unnecessary for correctness, but may help try() rewind less.
let comma_location = input.current_source_location(); let comma_location = input.current_source_location();
let comma = input.r#try(|i| i.expect_comma()).is_ok(); let comma = input.try(|i| i.expect_comma()).is_ok();
input.skip_whitespace(); // Unnecessary for correctness, but may help try() rewind less. input.skip_whitespace(); // Unnecessary for correctness, but may help try() rewind less.
if let Ok(item) = input.r#try(&mut parse_one) { if let Ok(item) = input.try(&mut parse_one) {
results.push(item); results.push(item);
} else if comma { } else if comma {
return Err(comma_location.new_unexpected_token_error(Token::Comma)); return Err(comma_location.new_unexpected_token_error(Token::Comma));