mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
style: Simplify some code now that lifetimes are non-lexical.
Differential Revision: https://phabricator.services.mozilla.com/D54529
This commit is contained in:
parent
1ef7c2f96b
commit
d9aa0571e3
11 changed files with 262 additions and 258 deletions
|
@ -306,8 +306,7 @@ fn parse_declaration_value_block<'i, 't>(
|
|||
) -> Result<(TokenSerializationType, TokenSerializationType), ParseError<'i>> {
|
||||
let mut token_start = input.position();
|
||||
let mut token = match input.next_including_whitespace_and_comments() {
|
||||
// FIXME: remove clone() when borrows are non-lexical
|
||||
Ok(token) => token.clone(),
|
||||
Ok(token) => token,
|
||||
Err(_) => {
|
||||
return Ok((
|
||||
TokenSerializationType::nothing(),
|
||||
|
@ -335,8 +334,9 @@ fn parse_declaration_value_block<'i, 't>(
|
|||
}
|
||||
};
|
||||
}
|
||||
let last_token_type = match token {
|
||||
let last_token_type = match *token {
|
||||
Token::Comment(_) => {
|
||||
let serialization_type = token.serialization_type();
|
||||
let token_slice = input.slice_from(token_start);
|
||||
if !token_slice.ends_with("*/") {
|
||||
missing_closing_characters.push_str(if token_slice.ends_with('*') {
|
||||
|
@ -345,14 +345,14 @@ fn parse_declaration_value_block<'i, 't>(
|
|||
"*/"
|
||||
})
|
||||
}
|
||||
token.serialization_type()
|
||||
serialization_type
|
||||
},
|
||||
Token::BadUrl(u) => {
|
||||
let e = StyleParseErrorKind::BadUrlInDeclarationValueBlock(u);
|
||||
Token::BadUrl(ref u) => {
|
||||
let e = StyleParseErrorKind::BadUrlInDeclarationValueBlock(u.clone());
|
||||
return Err(input.new_custom_error(e));
|
||||
},
|
||||
Token::BadString(s) => {
|
||||
let e = StyleParseErrorKind::BadStringInDeclarationValueBlock(s);
|
||||
Token::BadString(ref s) => {
|
||||
let e = StyleParseErrorKind::BadStringInDeclarationValueBlock(s.clone());
|
||||
return Err(input.new_custom_error(e));
|
||||
},
|
||||
Token::CloseParenthesis => {
|
||||
|
@ -401,13 +401,14 @@ fn parse_declaration_value_block<'i, 't>(
|
|||
Token::CloseSquareBracket.serialization_type()
|
||||
},
|
||||
Token::QuotedString(_) => {
|
||||
let serialization_type = token.serialization_type();
|
||||
let token_slice = input.slice_from(token_start);
|
||||
let quote = &token_slice[..1];
|
||||
debug_assert!(matches!(quote, "\"" | "'"));
|
||||
if !(token_slice.ends_with(quote) && token_slice.len() > 1) {
|
||||
missing_closing_characters.push_str(quote)
|
||||
}
|
||||
token.serialization_type()
|
||||
serialization_type
|
||||
},
|
||||
Token::Ident(ref value) |
|
||||
Token::AtKeyword(ref value) |
|
||||
|
@ -417,6 +418,8 @@ fn parse_declaration_value_block<'i, 't>(
|
|||
Token::Dimension {
|
||||
unit: ref value, ..
|
||||
} => {
|
||||
let serialization_type = token.serialization_type();
|
||||
let is_unquoted_url = matches!(token, Token::UnquotedUrl(_));
|
||||
if value.ends_with("<EFBFBD>") && input.slice_from(token_start).ends_with("\\") {
|
||||
// Unescaped backslash at EOF in these contexts is interpreted as U+FFFD
|
||||
// Check the value in case the final backslash was itself escaped.
|
||||
|
@ -424,18 +427,17 @@ fn parse_declaration_value_block<'i, 't>(
|
|||
// (Unescaped U+FFFD would also work, but removing the backslash is annoying.)
|
||||
missing_closing_characters.push_str("<EFBFBD>")
|
||||
}
|
||||
if matches!(token, Token::UnquotedUrl(_)) {
|
||||
if is_unquoted_url {
|
||||
check_closed!(")");
|
||||
}
|
||||
token.serialization_type()
|
||||
serialization_type
|
||||
},
|
||||
_ => token.serialization_type(),
|
||||
};
|
||||
|
||||
token_start = input.position();
|
||||
token = match input.next_including_whitespace_and_comments() {
|
||||
// FIXME: remove clone() when borrows are non-lexical
|
||||
Ok(token) => token.clone(),
|
||||
Ok(token) => token,
|
||||
Err(..) => return Ok((first_token_type, last_token_type)),
|
||||
};
|
||||
}
|
||||
|
@ -888,15 +890,12 @@ fn substitute_block<'i>(
|
|||
let mut set_position_at_next_iteration = false;
|
||||
loop {
|
||||
let before_this_token = input.position();
|
||||
// FIXME: remove clone() when borrows are non-lexical
|
||||
let next = input
|
||||
.next_including_whitespace_and_comments()
|
||||
.map(|t| t.clone());
|
||||
let next = input.next_including_whitespace_and_comments();
|
||||
if set_position_at_next_iteration {
|
||||
*position = (
|
||||
before_this_token,
|
||||
match next {
|
||||
Ok(ref token) => token.serialization_type(),
|
||||
Ok(token) => token.serialization_type(),
|
||||
Err(_) => TokenSerializationType::nothing(),
|
||||
},
|
||||
);
|
||||
|
|
|
@ -178,8 +178,7 @@ impl SupportsCondition {
|
|||
while input.try(Parser::expect_whitespace).is_ok() {}
|
||||
let pos = input.position();
|
||||
let location = input.current_source_location();
|
||||
// FIXME: remove clone() when lifetimes are non-lexical
|
||||
match input.next()?.clone() {
|
||||
match *input.next()? {
|
||||
Token::ParenthesisBlock => {
|
||||
let nested =
|
||||
input.try(|input| input.parse_nested_block(parse_condition_or_declaration));
|
||||
|
@ -187,7 +186,8 @@ impl SupportsCondition {
|
|||
return nested;
|
||||
}
|
||||
},
|
||||
Token::Function(ident) => {
|
||||
Token::Function(ref ident) => {
|
||||
let ident = ident.clone();
|
||||
let nested = input.try(|input| {
|
||||
input.parse_nested_block(|input| {
|
||||
SupportsCondition::parse_functional(&ident, input)
|
||||
|
@ -197,7 +197,7 @@ impl SupportsCondition {
|
|||
return nested;
|
||||
}
|
||||
},
|
||||
t => return Err(location.new_unexpected_token_error(t)),
|
||||
ref t => return Err(location.new_unexpected_token_error(t.clone())),
|
||||
}
|
||||
input.parse_nested_block(consume_any_value)?;
|
||||
Ok(SupportsCondition::FutureSyntax(
|
||||
|
|
|
@ -208,24 +208,34 @@ impl Angle {
|
|||
input: &mut Parser<'i, 't>,
|
||||
allow_unitless_zero: AllowUnitlessZeroAngle,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
// FIXME: remove clone() when lifetimes are non-lexical
|
||||
let token = input.next()?.clone();
|
||||
match token {
|
||||
let t = input.next()?;
|
||||
match *t {
|
||||
Token::Dimension {
|
||||
value, ref unit, ..
|
||||
} => {
|
||||
Angle::parse_dimension(value, unit, /* from_calc = */ false)
|
||||
match Angle::parse_dimension(value, unit, /* from_calc = */ false) {
|
||||
Ok(angle) => Ok(angle),
|
||||
Err(()) => {
|
||||
let t = t.clone();
|
||||
Err(input.new_unexpected_token_error(t))
|
||||
}
|
||||
}
|
||||
},
|
||||
Token::Number { value, .. } if value == 0. => match allow_unitless_zero {
|
||||
AllowUnitlessZeroAngle::Yes => Ok(Angle::zero()),
|
||||
AllowUnitlessZeroAngle::No => Err(()),
|
||||
AllowUnitlessZeroAngle::No => {
|
||||
let t = t.clone();
|
||||
Err(input.new_unexpected_token_error(t))
|
||||
},
|
||||
},
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {
|
||||
return input.parse_nested_block(|i| CalcNode::parse_angle(context, i));
|
||||
},
|
||||
_ => Err(()),
|
||||
ref t => {
|
||||
let t = t.clone();
|
||||
Err(input.new_unexpected_token_error(t))
|
||||
}
|
||||
}
|
||||
.map_err(|()| input.new_unexpected_token_error(token.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -163,9 +163,8 @@ impl CalcNode {
|
|||
expected_unit: CalcUnit,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let location = input.current_source_location();
|
||||
// FIXME: remove early returns when lifetimes are non-lexical
|
||||
match (input.next()?, expected_unit) {
|
||||
(&Token::Number { value, .. }, _) => return Ok(CalcNode::Number(value)),
|
||||
(&Token::Number { value, .. }, _) => Ok(CalcNode::Number(value)),
|
||||
(
|
||||
&Token::Dimension {
|
||||
value, ref unit, ..
|
||||
|
@ -178,11 +177,11 @@ impl CalcNode {
|
|||
},
|
||||
CalcUnit::LengthPercentage,
|
||||
) => {
|
||||
return NoCalcLength::parse_dimension(context, value, unit)
|
||||
NoCalcLength::parse_dimension(context, value, unit)
|
||||
.map(CalcNode::Length)
|
||||
.map_err(|()| {
|
||||
location.new_custom_error(StyleParseErrorKind::UnspecifiedError)
|
||||
});
|
||||
})
|
||||
},
|
||||
(
|
||||
&Token::Dimension {
|
||||
|
@ -190,11 +189,11 @@ impl CalcNode {
|
|||
},
|
||||
CalcUnit::Angle,
|
||||
) => {
|
||||
return Angle::parse_dimension(value, unit, /* from_calc = */ true)
|
||||
Angle::parse_dimension(value, unit, /* from_calc = */ true)
|
||||
.map(CalcNode::Angle)
|
||||
.map_err(|()| {
|
||||
location.new_custom_error(StyleParseErrorKind::UnspecifiedError)
|
||||
});
|
||||
})
|
||||
},
|
||||
(
|
||||
&Token::Dimension {
|
||||
|
@ -202,21 +201,24 @@ impl CalcNode {
|
|||
},
|
||||
CalcUnit::Time,
|
||||
) => {
|
||||
return Time::parse_dimension(value, unit, /* from_calc = */ true)
|
||||
Time::parse_dimension(value, unit, /* from_calc = */ true)
|
||||
.map(CalcNode::Time)
|
||||
.map_err(|()| {
|
||||
location.new_custom_error(StyleParseErrorKind::UnspecifiedError)
|
||||
});
|
||||
})
|
||||
},
|
||||
(&Token::Percentage { unit_value, .. }, CalcUnit::LengthPercentage) |
|
||||
(&Token::Percentage { unit_value, .. }, CalcUnit::Percentage) => {
|
||||
return Ok(CalcNode::Percentage(unit_value));
|
||||
Ok(CalcNode::Percentage(unit_value))
|
||||
},
|
||||
(&Token::ParenthesisBlock, _) => {},
|
||||
(&Token::Function(ref name), _) if name.eq_ignore_ascii_case("calc") => {},
|
||||
(t, _) => return Err(location.new_unexpected_token_error(t.clone())),
|
||||
(&Token::ParenthesisBlock, _) => {
|
||||
input.parse_nested_block(|i| CalcNode::parse(context, i, expected_unit))
|
||||
},
|
||||
(&Token::Function(ref name), _) if name.eq_ignore_ascii_case("calc") => {
|
||||
input.parse_nested_block(|i| CalcNode::parse(context, i, expected_unit))
|
||||
},
|
||||
(t, _) => Err(location.new_unexpected_token_error(t.clone())),
|
||||
}
|
||||
input.parse_nested_block(|i| CalcNode::parse(context, i, expected_unit))
|
||||
}
|
||||
|
||||
/// Parse a top-level `calc` expression, with all nested sub-expressions.
|
||||
|
@ -236,8 +238,7 @@ impl CalcNode {
|
|||
if input.is_exhausted() {
|
||||
break; // allow trailing whitespace
|
||||
}
|
||||
// FIXME: remove clone() when lifetimes are non-lexical
|
||||
match input.next()?.clone() {
|
||||
match *input.next()? {
|
||||
Token::Delim('+') => {
|
||||
let rhs = Self::parse_product(context, input, expected_unit)?;
|
||||
let new_root = CalcNode::Sum(Box::new(root), Box::new(rhs));
|
||||
|
@ -248,7 +249,10 @@ impl CalcNode {
|
|||
let new_root = CalcNode::Sub(Box::new(root), Box::new(rhs));
|
||||
root = new_root;
|
||||
},
|
||||
t => return Err(input.new_unexpected_token_error(t)),
|
||||
ref t => {
|
||||
let t = t.clone();
|
||||
return Err(input.new_unexpected_token_error(t));
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
|
|
|
@ -63,7 +63,10 @@ fn parse_counters<'i, 't>(
|
|||
let location = input.current_source_location();
|
||||
let name = match input.next() {
|
||||
Ok(&Token::Ident(ref ident)) => CustomIdent::from_ident(location, ident, &["none"])?,
|
||||
Ok(t) => return Err(location.new_unexpected_token_error(t.clone())),
|
||||
Ok(t) => {
|
||||
let t = t.clone();
|
||||
return Err(location.new_unexpected_token_error(t));
|
||||
},
|
||||
Err(_) => break,
|
||||
};
|
||||
|
||||
|
@ -147,57 +150,60 @@ impl Parse for Content {
|
|||
continue;
|
||||
}
|
||||
}
|
||||
// FIXME: remove clone() when lifetimes are non-lexical
|
||||
match input.next().map(|t| t.clone()) {
|
||||
Ok(Token::QuotedString(ref value)) => {
|
||||
match input.next() {
|
||||
Ok(&Token::QuotedString(ref value)) => {
|
||||
content.push(generics::ContentItem::String(
|
||||
value.as_ref().to_owned().into_boxed_str(),
|
||||
));
|
||||
},
|
||||
Ok(Token::Function(ref name)) => {
|
||||
Ok(&Token::Function(ref name)) => {
|
||||
let result = match_ignore_ascii_case! { &name,
|
||||
"counter" => Some(input.parse_nested_block(|input| {
|
||||
"counter" => input.parse_nested_block(|input| {
|
||||
let location = input.current_source_location();
|
||||
let name = CustomIdent::from_ident(location, input.expect_ident()?, &[])?;
|
||||
let style = Content::parse_counter_style(context, input);
|
||||
Ok(generics::ContentItem::Counter(name, style))
|
||||
})),
|
||||
"counters" => Some(input.parse_nested_block(|input| {
|
||||
}),
|
||||
"counters" => input.parse_nested_block(|input| {
|
||||
let location = input.current_source_location();
|
||||
let name = CustomIdent::from_ident(location, input.expect_ident()?, &[])?;
|
||||
input.expect_comma()?;
|
||||
let separator = input.expect_string()?.as_ref().to_owned().into_boxed_str();
|
||||
let style = Content::parse_counter_style(context, input);
|
||||
Ok(generics::ContentItem::Counters(name, separator, style))
|
||||
})),
|
||||
}),
|
||||
#[cfg(feature = "gecko")]
|
||||
"attr" => Some(input.parse_nested_block(|input| {
|
||||
"attr" => input.parse_nested_block(|input| {
|
||||
Ok(generics::ContentItem::Attr(Attr::parse_function(context, input)?))
|
||||
})),
|
||||
_ => None
|
||||
};
|
||||
match result {
|
||||
Some(result) => content.push(result?),
|
||||
None => {
|
||||
}),
|
||||
_ => {
|
||||
let name = name.clone();
|
||||
return Err(input.new_custom_error(
|
||||
StyleParseErrorKind::UnexpectedFunction(name.clone()),
|
||||
));
|
||||
},
|
||||
}
|
||||
StyleParseErrorKind::UnexpectedFunction(name),
|
||||
))
|
||||
}
|
||||
}?;
|
||||
content.push(result);
|
||||
},
|
||||
Ok(Token::Ident(ref ident)) => {
|
||||
Ok(&Token::Ident(ref ident)) => {
|
||||
content.push(match_ignore_ascii_case! { &ident,
|
||||
"open-quote" => generics::ContentItem::OpenQuote,
|
||||
"close-quote" => generics::ContentItem::CloseQuote,
|
||||
"no-open-quote" => generics::ContentItem::NoOpenQuote,
|
||||
"no-close-quote" => generics::ContentItem::NoCloseQuote,
|
||||
_ => return Err(input.new_custom_error(
|
||||
SelectorParseErrorKind::UnexpectedIdent(ident.clone())
|
||||
))
|
||||
_ =>{
|
||||
let ident = ident.clone();
|
||||
return Err(input.new_custom_error(
|
||||
SelectorParseErrorKind::UnexpectedIdent(ident)
|
||||
));
|
||||
}
|
||||
});
|
||||
},
|
||||
Err(_) => break,
|
||||
Ok(t) => return Err(input.new_unexpected_token_error(t)),
|
||||
Ok(t) => {
|
||||
let t = t.clone();
|
||||
return Err(input.new_unexpected_token_error(t));
|
||||
}
|
||||
}
|
||||
}
|
||||
if content.is_empty() {
|
||||
|
|
|
@ -1213,64 +1213,66 @@ impl Parse for FontVariantAlternates {
|
|||
)
|
||||
);
|
||||
while let Ok(_) = input.try(|input| {
|
||||
// FIXME: remove clone() when lifetimes are non-lexical
|
||||
match input.next()?.clone() {
|
||||
match *input.next()? {
|
||||
Token::Ident(ref value) if value.eq_ignore_ascii_case("historical-forms") => {
|
||||
check_if_parsed!(input, VariantAlternatesParsingFlags::HISTORICAL_FORMS);
|
||||
alternates.push(VariantAlternates::HistoricalForms);
|
||||
Ok(())
|
||||
},
|
||||
Token::Function(ref name) => input.parse_nested_block(|i| {
|
||||
match_ignore_ascii_case! { &name,
|
||||
"swash" => {
|
||||
check_if_parsed!(i, VariantAlternatesParsingFlags::SWASH);
|
||||
let location = i.current_source_location();
|
||||
let ident = CustomIdent::from_ident(location, i.expect_ident()?, &[])?;
|
||||
alternates.push(VariantAlternates::Swash(ident));
|
||||
Ok(())
|
||||
},
|
||||
"stylistic" => {
|
||||
check_if_parsed!(i, VariantAlternatesParsingFlags::STYLISTIC);
|
||||
let location = i.current_source_location();
|
||||
let ident = CustomIdent::from_ident(location, i.expect_ident()?, &[])?;
|
||||
alternates.push(VariantAlternates::Stylistic(ident));
|
||||
Ok(())
|
||||
},
|
||||
"ornaments" => {
|
||||
check_if_parsed!(i, VariantAlternatesParsingFlags::ORNAMENTS);
|
||||
let location = i.current_source_location();
|
||||
let ident = CustomIdent::from_ident(location, i.expect_ident()?, &[])?;
|
||||
alternates.push(VariantAlternates::Ornaments(ident));
|
||||
Ok(())
|
||||
},
|
||||
"annotation" => {
|
||||
check_if_parsed!(i, VariantAlternatesParsingFlags::ANNOTATION);
|
||||
let location = i.current_source_location();
|
||||
let ident = CustomIdent::from_ident(location, i.expect_ident()?, &[])?;
|
||||
alternates.push(VariantAlternates::Annotation(ident));
|
||||
Ok(())
|
||||
},
|
||||
"styleset" => {
|
||||
check_if_parsed!(i, VariantAlternatesParsingFlags::STYLESET);
|
||||
let idents = i.parse_comma_separated(|i| {
|
||||
Token::Function(ref name) => {
|
||||
let name = name.clone();
|
||||
input.parse_nested_block(|i| {
|
||||
match_ignore_ascii_case! { &name,
|
||||
"swash" => {
|
||||
check_if_parsed!(i, VariantAlternatesParsingFlags::SWASH);
|
||||
let location = i.current_source_location();
|
||||
CustomIdent::from_ident(location, i.expect_ident()?, &[])
|
||||
})?;
|
||||
alternates.push(VariantAlternates::Styleset(idents.into()));
|
||||
Ok(())
|
||||
},
|
||||
"character-variant" => {
|
||||
check_if_parsed!(i, VariantAlternatesParsingFlags::CHARACTER_VARIANT);
|
||||
let idents = i.parse_comma_separated(|i| {
|
||||
let ident = CustomIdent::from_ident(location, i.expect_ident()?, &[])?;
|
||||
alternates.push(VariantAlternates::Swash(ident));
|
||||
Ok(())
|
||||
},
|
||||
"stylistic" => {
|
||||
check_if_parsed!(i, VariantAlternatesParsingFlags::STYLISTIC);
|
||||
let location = i.current_source_location();
|
||||
CustomIdent::from_ident(location, i.expect_ident()?, &[])
|
||||
})?;
|
||||
alternates.push(VariantAlternates::CharacterVariant(idents.into()));
|
||||
Ok(())
|
||||
},
|
||||
_ => return Err(i.new_custom_error(StyleParseErrorKind::UnspecifiedError)),
|
||||
}
|
||||
}),
|
||||
let ident = CustomIdent::from_ident(location, i.expect_ident()?, &[])?;
|
||||
alternates.push(VariantAlternates::Stylistic(ident));
|
||||
Ok(())
|
||||
},
|
||||
"ornaments" => {
|
||||
check_if_parsed!(i, VariantAlternatesParsingFlags::ORNAMENTS);
|
||||
let location = i.current_source_location();
|
||||
let ident = CustomIdent::from_ident(location, i.expect_ident()?, &[])?;
|
||||
alternates.push(VariantAlternates::Ornaments(ident));
|
||||
Ok(())
|
||||
},
|
||||
"annotation" => {
|
||||
check_if_parsed!(i, VariantAlternatesParsingFlags::ANNOTATION);
|
||||
let location = i.current_source_location();
|
||||
let ident = CustomIdent::from_ident(location, i.expect_ident()?, &[])?;
|
||||
alternates.push(VariantAlternates::Annotation(ident));
|
||||
Ok(())
|
||||
},
|
||||
"styleset" => {
|
||||
check_if_parsed!(i, VariantAlternatesParsingFlags::STYLESET);
|
||||
let idents = i.parse_comma_separated(|i| {
|
||||
let location = i.current_source_location();
|
||||
CustomIdent::from_ident(location, i.expect_ident()?, &[])
|
||||
})?;
|
||||
alternates.push(VariantAlternates::Styleset(idents.into()));
|
||||
Ok(())
|
||||
},
|
||||
"character-variant" => {
|
||||
check_if_parsed!(i, VariantAlternatesParsingFlags::CHARACTER_VARIANT);
|
||||
let idents = i.parse_comma_separated(|i| {
|
||||
let location = i.current_source_location();
|
||||
CustomIdent::from_ident(location, i.expect_ident()?, &[])
|
||||
})?;
|
||||
alternates.push(VariantAlternates::CharacterVariant(idents.into()));
|
||||
Ok(())
|
||||
},
|
||||
_ => return Err(i.new_custom_error(StyleParseErrorKind::UnspecifiedError)),
|
||||
}
|
||||
})
|
||||
},
|
||||
_ => Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)),
|
||||
}
|
||||
}) {}
|
||||
|
|
|
@ -192,62 +192,57 @@ impl Parse for Gradient {
|
|||
Radial,
|
||||
}
|
||||
|
||||
// FIXME: remove clone() when lifetimes are non-lexical
|
||||
let func = input.expect_function()?.clone();
|
||||
let result = match_ignore_ascii_case! { &func,
|
||||
let func = input.expect_function()?;
|
||||
let (shape, repeating, mut compat_mode) = match_ignore_ascii_case! { &func,
|
||||
"linear-gradient" => {
|
||||
Some((Shape::Linear, false, GradientCompatMode::Modern))
|
||||
(Shape::Linear, false, GradientCompatMode::Modern)
|
||||
},
|
||||
"-webkit-linear-gradient" => {
|
||||
Some((Shape::Linear, false, GradientCompatMode::WebKit))
|
||||
(Shape::Linear, false, GradientCompatMode::WebKit)
|
||||
},
|
||||
#[cfg(feature = "gecko")]
|
||||
"-moz-linear-gradient" => {
|
||||
Some((Shape::Linear, false, GradientCompatMode::Moz))
|
||||
(Shape::Linear, false, GradientCompatMode::Moz)
|
||||
},
|
||||
"repeating-linear-gradient" => {
|
||||
Some((Shape::Linear, true, GradientCompatMode::Modern))
|
||||
(Shape::Linear, true, GradientCompatMode::Modern)
|
||||
},
|
||||
"-webkit-repeating-linear-gradient" => {
|
||||
Some((Shape::Linear, true, GradientCompatMode::WebKit))
|
||||
(Shape::Linear, true, GradientCompatMode::WebKit)
|
||||
},
|
||||
#[cfg(feature = "gecko")]
|
||||
"-moz-repeating-linear-gradient" => {
|
||||
Some((Shape::Linear, true, GradientCompatMode::Moz))
|
||||
(Shape::Linear, true, GradientCompatMode::Moz)
|
||||
},
|
||||
"radial-gradient" => {
|
||||
Some((Shape::Radial, false, GradientCompatMode::Modern))
|
||||
(Shape::Radial, false, GradientCompatMode::Modern)
|
||||
},
|
||||
"-webkit-radial-gradient" => {
|
||||
Some((Shape::Radial, false, GradientCompatMode::WebKit))
|
||||
(Shape::Radial, false, GradientCompatMode::WebKit)
|
||||
},
|
||||
#[cfg(feature = "gecko")]
|
||||
"-moz-radial-gradient" => {
|
||||
Some((Shape::Radial, false, GradientCompatMode::Moz))
|
||||
(Shape::Radial, false, GradientCompatMode::Moz)
|
||||
},
|
||||
"repeating-radial-gradient" => {
|
||||
Some((Shape::Radial, true, GradientCompatMode::Modern))
|
||||
(Shape::Radial, true, GradientCompatMode::Modern)
|
||||
},
|
||||
"-webkit-repeating-radial-gradient" => {
|
||||
Some((Shape::Radial, true, GradientCompatMode::WebKit))
|
||||
(Shape::Radial, true, GradientCompatMode::WebKit)
|
||||
},
|
||||
#[cfg(feature = "gecko")]
|
||||
"-moz-repeating-radial-gradient" => {
|
||||
Some((Shape::Radial, true, GradientCompatMode::Moz))
|
||||
(Shape::Radial, true, GradientCompatMode::Moz)
|
||||
},
|
||||
"-webkit-gradient" => {
|
||||
return input.parse_nested_block(|i| {
|
||||
Self::parse_webkit_gradient_argument(context, i)
|
||||
});
|
||||
},
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let (shape, repeating, mut compat_mode) = match result {
|
||||
Some(result) => result,
|
||||
None => {
|
||||
_ => {
|
||||
let func = func.clone();
|
||||
return Err(input.new_custom_error(StyleParseErrorKind::UnexpectedFunction(func)));
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
let (kind, items) = input.parse_nested_block(|i| {
|
||||
|
|
|
@ -587,39 +587,37 @@ impl Length {
|
|||
num_context: AllowedNumericType,
|
||||
allow_quirks: AllowQuirks,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
// FIXME: remove early returns when lifetimes are non-lexical
|
||||
{
|
||||
let location = input.current_source_location();
|
||||
let token = input.next()?;
|
||||
match *token {
|
||||
Token::Dimension {
|
||||
value, ref unit, ..
|
||||
} if num_context.is_ok(context.parsing_mode, value) => {
|
||||
return NoCalcLength::parse_dimension(context, value, unit)
|
||||
.map(Length::NoCalc)
|
||||
.map_err(|()| location.new_unexpected_token_error(token.clone()));
|
||||
},
|
||||
Token::Number { value, .. } if num_context.is_ok(context.parsing_mode, value) => {
|
||||
if value != 0. &&
|
||||
!context.parsing_mode.allows_unitless_lengths() &&
|
||||
!allow_quirks.allowed(context.quirks_mode)
|
||||
{
|
||||
return Err(
|
||||
location.new_custom_error(StyleParseErrorKind::UnspecifiedError)
|
||||
);
|
||||
}
|
||||
return Ok(Length::NoCalc(NoCalcLength::Absolute(AbsoluteLength::Px(
|
||||
value,
|
||||
))));
|
||||
},
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {},
|
||||
ref token => return Err(location.new_unexpected_token_error(token.clone())),
|
||||
}
|
||||
let location = input.current_source_location();
|
||||
let token = input.next()?;
|
||||
match *token {
|
||||
Token::Dimension {
|
||||
value, ref unit, ..
|
||||
} if num_context.is_ok(context.parsing_mode, value) => {
|
||||
NoCalcLength::parse_dimension(context, value, unit)
|
||||
.map(Length::NoCalc)
|
||||
.map_err(|()| location.new_unexpected_token_error(token.clone()))
|
||||
},
|
||||
Token::Number { value, .. } if num_context.is_ok(context.parsing_mode, value) => {
|
||||
if value != 0. &&
|
||||
!context.parsing_mode.allows_unitless_lengths() &&
|
||||
!allow_quirks.allowed(context.quirks_mode)
|
||||
{
|
||||
return Err(
|
||||
location.new_custom_error(StyleParseErrorKind::UnspecifiedError)
|
||||
);
|
||||
}
|
||||
Ok(Length::NoCalc(NoCalcLength::Absolute(AbsoluteLength::Px(
|
||||
value,
|
||||
))))
|
||||
},
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {
|
||||
input.parse_nested_block(|input| {
|
||||
CalcNode::parse_length(context, input, num_context)
|
||||
.map(|calc| Length::Calc(Box::new(calc)))
|
||||
})
|
||||
},
|
||||
ref token => return Err(location.new_unexpected_token_error(token.clone())),
|
||||
}
|
||||
input.parse_nested_block(|input| {
|
||||
CalcNode::parse_length(context, input, num_context)
|
||||
.map(|calc| Length::Calc(Box::new(calc)))
|
||||
})
|
||||
}
|
||||
|
||||
/// Parse a non-negative length
|
||||
|
@ -809,44 +807,41 @@ impl LengthPercentage {
|
|||
num_context: AllowedNumericType,
|
||||
allow_quirks: AllowQuirks,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
// FIXME: remove early returns when lifetimes are non-lexical
|
||||
{
|
||||
let location = input.current_source_location();
|
||||
let token = input.next()?;
|
||||
match *token {
|
||||
Token::Dimension {
|
||||
value, ref unit, ..
|
||||
} if num_context.is_ok(context.parsing_mode, value) => {
|
||||
return NoCalcLength::parse_dimension(context, value, unit)
|
||||
.map(LengthPercentage::Length)
|
||||
.map_err(|()| location.new_unexpected_token_error(token.clone()));
|
||||
},
|
||||
Token::Percentage { unit_value, .. }
|
||||
if num_context.is_ok(context.parsing_mode, unit_value) =>
|
||||
{
|
||||
return Ok(LengthPercentage::Percentage(computed::Percentage(
|
||||
unit_value,
|
||||
)));
|
||||
}
|
||||
Token::Number { value, .. } if num_context.is_ok(context.parsing_mode, value) => {
|
||||
if value != 0. &&
|
||||
!context.parsing_mode.allows_unitless_lengths() &&
|
||||
!allow_quirks.allowed(context.quirks_mode)
|
||||
{
|
||||
return Err(location.new_unexpected_token_error(token.clone()));
|
||||
} else {
|
||||
return Ok(LengthPercentage::Length(NoCalcLength::from_px(value)));
|
||||
}
|
||||
},
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {},
|
||||
_ => return Err(location.new_unexpected_token_error(token.clone())),
|
||||
let location = input.current_source_location();
|
||||
let token = input.next()?;
|
||||
match *token {
|
||||
Token::Dimension {
|
||||
value, ref unit, ..
|
||||
} if num_context.is_ok(context.parsing_mode, value) => {
|
||||
return NoCalcLength::parse_dimension(context, value, unit)
|
||||
.map(LengthPercentage::Length)
|
||||
.map_err(|()| location.new_unexpected_token_error(token.clone()));
|
||||
},
|
||||
Token::Percentage { unit_value, .. }
|
||||
if num_context.is_ok(context.parsing_mode, unit_value) =>
|
||||
{
|
||||
return Ok(LengthPercentage::Percentage(computed::Percentage(
|
||||
unit_value,
|
||||
)));
|
||||
}
|
||||
Token::Number { value, .. } if num_context.is_ok(context.parsing_mode, value) => {
|
||||
if value != 0. &&
|
||||
!context.parsing_mode.allows_unitless_lengths() &&
|
||||
!allow_quirks.allowed(context.quirks_mode)
|
||||
{
|
||||
return Err(location.new_unexpected_token_error(token.clone()));
|
||||
} else {
|
||||
return Ok(LengthPercentage::Length(NoCalcLength::from_px(value)));
|
||||
}
|
||||
},
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {
|
||||
let calc = input.parse_nested_block(|i| {
|
||||
CalcNode::parse_length_or_percentage(context, i, num_context)
|
||||
})?;
|
||||
Ok(LengthPercentage::Calc(Box::new(calc)))
|
||||
},
|
||||
_ => return Err(location.new_unexpected_token_error(token.clone())),
|
||||
}
|
||||
|
||||
let calc = input.parse_nested_block(|i| {
|
||||
CalcNode::parse_length_or_percentage(context, i, num_context)
|
||||
})?;
|
||||
Ok(LengthPercentage::Calc(Box::new(calc)))
|
||||
}
|
||||
|
||||
/// Parses allowing the unitless length quirk.
|
||||
|
|
|
@ -136,24 +136,22 @@ fn parse_number_with_clamping_mode<'i, 't>(
|
|||
clamping_mode: AllowedNumericType,
|
||||
) -> Result<Number, ParseError<'i>> {
|
||||
let location = input.current_source_location();
|
||||
// FIXME: remove early returns when lifetimes are non-lexical
|
||||
match *input.next()? {
|
||||
Token::Number { value, .. } if clamping_mode.is_ok(context.parsing_mode, value) => {
|
||||
return Ok(Number {
|
||||
Ok(Number {
|
||||
value: value.min(f32::MAX).max(f32::MIN),
|
||||
calc_clamping_mode: None,
|
||||
});
|
||||
})
|
||||
},
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {},
|
||||
ref t => return Err(location.new_unexpected_token_error(t.clone())),
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {
|
||||
let result = input.parse_nested_block(|i| CalcNode::parse_number(context, i))?;
|
||||
Ok(Number {
|
||||
value: result.min(f32::MAX).max(f32::MIN),
|
||||
calc_clamping_mode: Some(clamping_mode),
|
||||
})
|
||||
},
|
||||
ref t => Err(location.new_unexpected_token_error(t.clone())),
|
||||
}
|
||||
|
||||
let result = input.parse_nested_block(|i| CalcNode::parse_number(context, i))?;
|
||||
|
||||
Ok(Number {
|
||||
value: result.min(f32::MAX).max(f32::MIN),
|
||||
calc_clamping_mode: Some(clamping_mode),
|
||||
})
|
||||
}
|
||||
|
||||
/// A CSS `<number>` specified value.
|
||||
|
@ -540,19 +538,16 @@ impl Parse for Integer {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let location = input.current_source_location();
|
||||
|
||||
// FIXME: remove early returns when lifetimes are non-lexical
|
||||
match *input.next()? {
|
||||
Token::Number {
|
||||
int_value: Some(v), ..
|
||||
} => return Ok(Integer::new(v)),
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {},
|
||||
ref t => return Err(location.new_unexpected_token_error(t.clone())),
|
||||
} => Ok(Integer::new(v)),
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {
|
||||
let result = input.parse_nested_block(|i| CalcNode::parse_integer(context, i))?;
|
||||
Ok(Integer::from_calc(result))
|
||||
},
|
||||
ref t => Err(location.new_unexpected_token_error(t.clone())),
|
||||
}
|
||||
|
||||
let result = input.parse_nested_block(|i| CalcNode::parse_integer(context, i))?;
|
||||
|
||||
Ok(Integer::from_calc(result))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -111,25 +111,24 @@ impl Percentage {
|
|||
num_context: AllowedNumericType,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let location = input.current_source_location();
|
||||
// FIXME: remove early returns when lifetimes are non-lexical
|
||||
match *input.next()? {
|
||||
Token::Percentage { unit_value, .. }
|
||||
if num_context.is_ok(context.parsing_mode, unit_value) =>
|
||||
{
|
||||
return Ok(Percentage::new(unit_value));
|
||||
Ok(Percentage::new(unit_value))
|
||||
}
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {},
|
||||
ref t => return Err(location.new_unexpected_token_error(t.clone())),
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {
|
||||
let result = input.parse_nested_block(|i| CalcNode::parse_percentage(context, i))?;
|
||||
|
||||
// TODO(emilio): -moz-image-rect is the only thing that uses
|
||||
// the clamping mode... I guess we could disallow it...
|
||||
Ok(Percentage {
|
||||
value: result,
|
||||
calc_clamping_mode: Some(num_context),
|
||||
})
|
||||
},
|
||||
ref t => Err(location.new_unexpected_token_error(t.clone())),
|
||||
}
|
||||
|
||||
let result = input.parse_nested_block(|i| CalcNode::parse_percentage(context, i))?;
|
||||
|
||||
// TODO(emilio): -moz-image-rect is the only thing that uses
|
||||
// the clamping mode... I guess we could disallow it...
|
||||
Ok(Percentage {
|
||||
value: result,
|
||||
calc_clamping_mode: Some(num_context),
|
||||
})
|
||||
}
|
||||
|
||||
/// Parses a percentage token, but rejects it if it's negative.
|
||||
|
|
|
@ -83,27 +83,26 @@ impl Time {
|
|||
use style_traits::ParsingMode;
|
||||
|
||||
let location = input.current_source_location();
|
||||
// FIXME: remove early returns when lifetimes are non-lexical
|
||||
match input.next() {
|
||||
match *input.next()? {
|
||||
// Note that we generally pass ParserContext to is_ok() to check
|
||||
// that the ParserMode of the ParserContext allows all numeric
|
||||
// values for SMIL regardless of clamping_mode, but in this Time
|
||||
// value case, the value does not animate for SMIL at all, so we use
|
||||
// ParsingMode::DEFAULT directly.
|
||||
Ok(&Token::Dimension {
|
||||
Token::Dimension {
|
||||
value, ref unit, ..
|
||||
}) if clamping_mode.is_ok(ParsingMode::DEFAULT, value) => {
|
||||
return Time::parse_dimension(value, unit, /* from_calc = */ false).map_err(|()| {
|
||||
} if clamping_mode.is_ok(ParsingMode::DEFAULT, value) => {
|
||||
Time::parse_dimension(value, unit, /* from_calc = */ false).map_err(|()| {
|
||||
location.new_custom_error(StyleParseErrorKind::UnspecifiedError)
|
||||
});
|
||||
})
|
||||
},
|
||||
Ok(&Token::Function(ref name)) if name.eq_ignore_ascii_case("calc") => {},
|
||||
Ok(t) => return Err(location.new_unexpected_token_error(t.clone())),
|
||||
Err(e) => return Err(e.into()),
|
||||
}
|
||||
match input.parse_nested_block(|i| CalcNode::parse_time(context, i)) {
|
||||
Ok(time) if clamping_mode.is_ok(ParsingMode::DEFAULT, time.seconds) => Ok(time),
|
||||
_ => Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)),
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {
|
||||
match input.parse_nested_block(|i| CalcNode::parse_time(context, i)) {
|
||||
Ok(time) if clamping_mode.is_ok(ParsingMode::DEFAULT, time.seconds) => Ok(time),
|
||||
_ => Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)),
|
||||
}
|
||||
},
|
||||
ref t => return Err(location.new_unexpected_token_error(t.clone())),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue