Update cssparser to 0.18

https://github.com/servo/rust-cssparser/pull/171
This commit is contained in:
Simon Sapin 2017-07-20 21:03:53 +02:00
parent 30d6d6024b
commit eb98ae6e04
64 changed files with 541 additions and 512 deletions

View file

@ -150,40 +150,36 @@ impl CalcNode {
input: &mut Parser<'i, 't>,
expected_unit: CalcUnit
) -> Result<Self, ParseError<'i>> {
// FIXME: remove early returns when lifetimes are non-lexical
match (input.next()?, expected_unit) {
(Token::Number { value, .. }, _) => Ok(CalcNode::Number(value)),
(Token::Dimension { value, ref unit, .. }, CalcUnit::Length) |
(Token::Dimension { value, ref unit, .. }, CalcUnit::LengthOrPercentage) => {
NoCalcLength::parse_dimension(context, value, unit)
(&Token::Number { value, .. }, _) => return Ok(CalcNode::Number(value)),
(&Token::Dimension { value, ref unit, .. }, CalcUnit::Length) |
(&Token::Dimension { value, ref unit, .. }, CalcUnit::LengthOrPercentage) => {
return NoCalcLength::parse_dimension(context, value, unit)
.map(CalcNode::Length)
.map_err(|()| StyleParseError::UnspecifiedError.into())
}
(Token::Dimension { value, ref unit, .. }, CalcUnit::Angle) => {
Angle::parse_dimension(value, unit, /* from_calc = */ true)
(&Token::Dimension { value, ref unit, .. }, CalcUnit::Angle) => {
return Angle::parse_dimension(value, unit, /* from_calc = */ true)
.map(CalcNode::Angle)
.map_err(|()| StyleParseError::UnspecifiedError.into())
}
(Token::Dimension { value, ref unit, .. }, CalcUnit::Time) => {
Time::parse_dimension(value, unit, /* from_calc = */ true)
(&Token::Dimension { value, ref unit, .. }, CalcUnit::Time) => {
return Time::parse_dimension(value, unit, /* from_calc = */ true)
.map(CalcNode::Time)
.map_err(|()| StyleParseError::UnspecifiedError.into())
}
(Token::Percentage { unit_value, .. }, CalcUnit::LengthOrPercentage) |
(Token::Percentage { unit_value, .. }, CalcUnit::Percentage) => {
Ok(CalcNode::Percentage(unit_value))
(&Token::Percentage { unit_value, .. }, CalcUnit::LengthOrPercentage) |
(&Token::Percentage { unit_value, .. }, CalcUnit::Percentage) => {
return Ok(CalcNode::Percentage(unit_value))
}
(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(BasicParseError::UnexpectedToken(t).into())
(&Token::ParenthesisBlock, _) => {}
(&Token::Function(ref name), _) if name.eq_ignore_ascii_case("calc") => {}
(t, _) => return Err(BasicParseError::UnexpectedToken(t.clone()).into())
}
input.parse_nested_block(|i| {
CalcNode::parse(context, i, expected_unit)
})
}
/// Parse a top-level `calc` expression, with all nested sub-expressions.
@ -200,11 +196,12 @@ impl CalcNode {
loop {
let position = input.position();
match input.next_including_whitespace() {
Ok(Token::WhiteSpace(_)) => {
Ok(&Token::WhiteSpace(_)) => {
if input.is_exhausted() {
break; // allow trailing whitespace
}
match input.next()? {
// FIXME: remove clone() when lifetimes are non-lexical
match input.next()?.clone() {
Token::Delim('+') => {
let rhs =
Self::parse_product(context, input, expected_unit)?;
@ -252,13 +249,13 @@ impl CalcNode {
loop {
let position = input.position();
match input.next() {
Ok(Token::Delim('*')) => {
Ok(&Token::Delim('*')) => {
let rhs = Self::parse_one(context, input, expected_unit)?;
let new_root = CalcNode::Mul(Box::new(root), Box::new(rhs));
root = new_root;
}
// TODO(emilio): Figure out why the `Integer` check.
Ok(Token::Delim('/')) if expected_unit != CalcUnit::Integer => {
Ok(&Token::Delim('/')) if expected_unit != CalcUnit::Integer => {
let rhs = Self::parse_one(context, input, expected_unit)?;
let new_root = CalcNode::Div(Box::new(root), Box::new(rhs));
root = new_root;