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