mirror of
https://github.com/servo/servo.git
synced 2025-10-17 16:59:27 +01:00
Update cssparser to 0.18
https://github.com/servo/rust-cssparser/pull/171
This commit is contained in:
parent
30d6d6024b
commit
eb98ae6e04
64 changed files with 541 additions and 512 deletions
|
@ -374,7 +374,8 @@ fn parse_normal_or_baseline<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignF
|
|||
|
||||
// <baseline-position>
|
||||
fn parse_baseline<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> {
|
||||
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
|
||||
// FIXME: remove clone() when lifetimes are non-lexical
|
||||
try_match_ident_ignore_ascii_case! { input.expect_ident()?.clone(),
|
||||
"baseline" => Ok(ALIGN_BASELINE),
|
||||
"first" => {
|
||||
input.expect_ident_matching("baseline")?;
|
||||
|
@ -471,7 +472,7 @@ fn parse_self_position<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags,
|
|||
|
||||
// [ legacy && [ left | right | center ] ]
|
||||
fn parse_legacy<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseError<'i>> {
|
||||
let a = input.expect_ident()?;
|
||||
let a = input.expect_ident()?.clone();
|
||||
let b = input.expect_ident()?;
|
||||
if a.eq_ignore_ascii_case("legacy") {
|
||||
(match_ignore_ascii_case! { &b,
|
||||
|
@ -479,7 +480,7 @@ fn parse_legacy<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseE
|
|||
"right" => Ok(ALIGN_LEGACY | ALIGN_RIGHT),
|
||||
"center" => Ok(ALIGN_LEGACY | ALIGN_CENTER),
|
||||
_ => Err(())
|
||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(b).into())
|
||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(b.clone()).into())
|
||||
} else if b.eq_ignore_ascii_case("legacy") {
|
||||
(match_ignore_ascii_case! { &a,
|
||||
"left" => Ok(ALIGN_LEGACY | ALIGN_LEFT),
|
||||
|
|
|
@ -27,6 +27,6 @@ impl Parse for BackgroundSize {
|
|||
"cover" => Ok(GenericBackgroundSize::Cover),
|
||||
"contain" => Ok(GenericBackgroundSize::Contain),
|
||||
_ => Err(()),
|
||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
|
||||
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident.clone()).into())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ impl Parse for GeometryBox {
|
|||
|
||||
impl Parse for BasicShape {
|
||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||
let function = input.expect_function()?;
|
||||
let function = input.expect_function()?.clone();
|
||||
input.parse_nested_block(move |i| {
|
||||
(match_ignore_ascii_case! { &function,
|
||||
"inset" => return InsetRect::parse_function_arguments(context, i).map(GenericBasicShape::Inset),
|
||||
|
@ -109,7 +109,7 @@ impl Parse for BasicShape {
|
|||
"ellipse" => return Ellipse::parse_function_arguments(context, i).map(GenericBasicShape::Ellipse),
|
||||
"polygon" => return Polygon::parse_function_arguments(context, i).map(GenericBasicShape::Polygon),
|
||||
_ => Err(())
|
||||
}).map_err(|()| StyleParseError::UnexpectedFunction(function).into())
|
||||
}).map_err(|()| StyleParseError::UnexpectedFunction(function.clone()).into())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -72,7 +72,7 @@ impl Parse for Color {
|
|||
// specified value.
|
||||
let start_position = input.position();
|
||||
let authored = match input.next() {
|
||||
Ok(Token::Ident(s)) => Some(s.to_lowercase().into_boxed_str()),
|
||||
Ok(&Token::Ident(ref s)) => Some(s.to_lowercase().into_boxed_str()),
|
||||
_ => None,
|
||||
};
|
||||
input.reset(start_position);
|
||||
|
@ -173,22 +173,22 @@ impl Color {
|
|||
///
|
||||
/// https://quirks.spec.whatwg.org/#the-hashless-hex-color-quirk
|
||||
fn parse_quirky_color<'i, 't>(input: &mut Parser<'i, 't>) -> Result<RGBA, ParseError<'i>> {
|
||||
let (value, unit) = match input.next()? {
|
||||
let (value, unit) = match *input.next()? {
|
||||
Token::Number { int_value: Some(integer), .. } => {
|
||||
(integer, None)
|
||||
},
|
||||
Token::Dimension { int_value: Some(integer), unit, .. } => {
|
||||
Token::Dimension { int_value: Some(integer), ref unit, .. } => {
|
||||
(integer, Some(unit))
|
||||
},
|
||||
Token::Ident(ident) => {
|
||||
Token::Ident(ref ident) => {
|
||||
if ident.len() != 3 && ident.len() != 6 {
|
||||
return Err(StyleParseError::UnspecifiedError.into());
|
||||
}
|
||||
return parse_hash_color(ident.as_bytes())
|
||||
.map_err(|()| StyleParseError::UnspecifiedError.into());
|
||||
}
|
||||
t => {
|
||||
return Err(BasicParseError::UnexpectedToken(t).into());
|
||||
ref t => {
|
||||
return Err(BasicParseError::UnexpectedToken(t.clone()).into());
|
||||
},
|
||||
};
|
||||
if value < 0 {
|
||||
|
|
|
@ -159,7 +159,7 @@ impl Parse for Filter {
|
|||
return Ok(GenericFilter::Url(url));
|
||||
}
|
||||
}
|
||||
let function = input.expect_function()?;
|
||||
let function = input.expect_function()?.clone();
|
||||
input.parse_nested_block(|i| {
|
||||
try_match_ident_ignore_ascii_case! { function,
|
||||
"blur" => Ok(GenericFilter::Blur(Length::parse_non_negative(context, i)?)),
|
||||
|
|
|
@ -18,10 +18,10 @@ use values::specified::LengthOrPercentage;
|
|||
|
||||
/// Parse a single flexible length.
|
||||
pub fn parse_flex<'i, 't>(input: &mut Parser<'i, 't>) -> Result<CSSFloat, ParseError<'i>> {
|
||||
match input.next()? {
|
||||
match *input.next()? {
|
||||
Token::Dimension { value, ref unit, .. } if unit.eq_ignore_ascii_case("fr") && value.is_sign_positive()
|
||||
=> Ok(value),
|
||||
t => Err(BasicParseError::UnexpectedToken(t).into()),
|
||||
ref t => Err(BasicParseError::UnexpectedToken(t.clone()).into()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,8 +85,8 @@ pub fn parse_line_names<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Box<[Custo
|
|||
input.expect_square_bracket_block()?;
|
||||
input.parse_nested_block(|input| {
|
||||
let mut values = vec![];
|
||||
while let Ok(ident) = input.try(|i| i.expect_ident()) {
|
||||
let ident = CustomIdent::from_ident(ident, &["span"])?;
|
||||
while let Ok(ident) = input.try(|i| i.expect_ident_cloned()) {
|
||||
let ident = CustomIdent::from_ident(&ident, &["span"])?;
|
||||
values.push(ident);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ use parser::{Parse, ParserContext};
|
|||
use selectors::parser::SelectorParseError;
|
||||
#[cfg(feature = "servo")]
|
||||
use servo_url::ServoUrl;
|
||||
use std::borrow::Cow;
|
||||
use std::cmp::Ordering;
|
||||
use std::f32::consts::PI;
|
||||
use std::fmt;
|
||||
|
@ -169,9 +168,9 @@ impl Image {
|
|||
fn parse_element<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Atom, ParseError<'i>> {
|
||||
input.try(|i| i.expect_function_matching("-moz-element"))?;
|
||||
input.parse_nested_block(|i| {
|
||||
match i.next()? {
|
||||
Token::IDHash(id) => Ok(Atom::from(Cow::from(id))),
|
||||
t => Err(BasicParseError::UnexpectedToken(t).into()),
|
||||
match *i.next()? {
|
||||
Token::IDHash(ref id) => Ok(Atom::from(id.as_ref())),
|
||||
ref t => Err(BasicParseError::UnexpectedToken(t.clone()).into()),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -184,7 +183,8 @@ impl Parse for Gradient {
|
|||
Radial,
|
||||
}
|
||||
|
||||
let func = input.expect_function()?;
|
||||
// FIXME: remove clone() when lifetimes are non-lexical
|
||||
let func = input.expect_function()?.clone();
|
||||
let result = match_ignore_ascii_case! { &func,
|
||||
"linear-gradient" => {
|
||||
Some((Shape::Linear, false, CompatMode::Modern))
|
||||
|
@ -234,7 +234,7 @@ impl Parse for Gradient {
|
|||
|
||||
let (shape, repeating, mut compat_mode) = match result {
|
||||
Some(result) => result,
|
||||
None => return Err(StyleParseError::UnexpectedFunction(func).into()),
|
||||
None => return Err(StyleParseError::UnexpectedFunction(func.clone()).into()),
|
||||
};
|
||||
|
||||
let (kind, items) = input.parse_nested_block(|i| {
|
||||
|
@ -389,7 +389,7 @@ impl Gradient {
|
|||
}
|
||||
}
|
||||
|
||||
let ident = input.expect_ident()?;
|
||||
let ident = input.expect_ident_cloned()?;
|
||||
input.expect_comma()?;
|
||||
|
||||
let (kind, reverse_stops) = match_ignore_ascii_case! { &ident,
|
||||
|
@ -439,7 +439,7 @@ impl Gradient {
|
|||
let mut items = input.try(|i| {
|
||||
i.expect_comma()?;
|
||||
i.parse_comma_separated(|i| {
|
||||
let function = i.expect_function()?;
|
||||
let function = i.expect_function()?.clone();
|
||||
let (color, mut p) = i.parse_nested_block(|i| {
|
||||
let p = match_ignore_ascii_case! { &function,
|
||||
"color-stop" => {
|
||||
|
@ -879,7 +879,7 @@ impl Parse for PaintWorklet {
|
|||
input.parse_nested_block(|i| {
|
||||
let name = i.expect_ident()?;
|
||||
Ok(PaintWorklet {
|
||||
name: Atom::from(Cow::from(name)),
|
||||
name: Atom::from(name.as_ref()),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -890,7 +890,7 @@ impl Parse for MozImageRect {
|
|||
input.try(|i| i.expect_function_matching("-moz-image-rect"))?;
|
||||
input.parse_nested_block(|i| {
|
||||
let string = i.expect_url_or_string()?;
|
||||
let url = SpecifiedUrl::parse_from_string(string.into_owned(), context)?;
|
||||
let url = SpecifiedUrl::parse_from_string(string.as_ref().to_owned(), context)?;
|
||||
i.expect_comma()?;
|
||||
let top = NumberOrPercentage::parse_non_negative(context, i)?;
|
||||
i.expect_comma()?;
|
||||
|
|
|
@ -619,26 +619,29 @@ impl Length {
|
|||
num_context: AllowedLengthType,
|
||||
allow_quirks: AllowQuirks)
|
||||
-> Result<Length, ParseError<'i>> {
|
||||
let token = input.next()?;
|
||||
match token {
|
||||
Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => {
|
||||
Length::parse_dimension(context, value, unit)
|
||||
}
|
||||
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(StyleParseError::UnspecifiedError.into())
|
||||
// FIXME: remove early returns when lifetimes are non-lexical
|
||||
{
|
||||
let token = input.next()?;
|
||||
match *token {
|
||||
Token::Dimension { value, ref unit, .. } if num_context.is_ok(context.parsing_mode, value) => {
|
||||
return Length::parse_dimension(context, value, unit)
|
||||
.map_err(|()| BasicParseError::UnexpectedToken(token.clone()).into())
|
||||
}
|
||||
Ok(Length::NoCalc(NoCalcLength::Absolute(AbsoluteLength::Px(value))))
|
||||
},
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {
|
||||
return input.parse_nested_block(|input| {
|
||||
CalcNode::parse_length(context, input, num_context).map(|calc| Length::Calc(Box::new(calc)))
|
||||
})
|
||||
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(StyleParseError::UnspecifiedError.into())
|
||||
}
|
||||
return Ok(Length::NoCalc(NoCalcLength::Absolute(AbsoluteLength::Px(value))))
|
||||
},
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {}
|
||||
ref token => return Err(BasicParseError::UnexpectedToken(token.clone()).into())
|
||||
}
|
||||
_ => Err(())
|
||||
}.map_err(|()| BasicParseError::UnexpectedToken(token).into())
|
||||
}
|
||||
input.parse_nested_block(|input| {
|
||||
CalcNode::parse_length(context, input, num_context).map(|calc| Length::Calc(Box::new(calc)))
|
||||
})
|
||||
}
|
||||
|
||||
/// Parse a non-negative length
|
||||
|
@ -761,24 +764,25 @@ impl Percentage {
|
|||
input: &mut Parser<'i, 't>,
|
||||
num_context: AllowedNumericType,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
match input.next()? {
|
||||
// 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) => {
|
||||
Ok(Percentage::new(unit_value))
|
||||
return Ok(Percentage::new(unit_value))
|
||||
}
|
||||
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),
|
||||
})
|
||||
}
|
||||
t => Err(BasicParseError::UnexpectedToken(t).into())
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {}
|
||||
ref t => return Err(BasicParseError::UnexpectedToken(t.clone()).into())
|
||||
}
|
||||
|
||||
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.
|
||||
|
@ -877,31 +881,36 @@ impl LengthOrPercentage {
|
|||
allow_quirks: AllowQuirks)
|
||||
-> Result<LengthOrPercentage, ParseError<'i>>
|
||||
{
|
||||
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(LengthOrPercentage::Length)
|
||||
}
|
||||
Token::Percentage { unit_value, .. } if num_context.is_ok(context.parsing_mode, unit_value) => {
|
||||
return Ok(LengthOrPercentage::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) {
|
||||
Err(())
|
||||
} else {
|
||||
return Ok(LengthOrPercentage::Length(NoCalcLength::from_px(value)))
|
||||
// FIXME: remove early returns when lifetimes are non-lexical
|
||||
{
|
||||
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(LengthOrPercentage::Length)
|
||||
.map_err(|()| BasicParseError::UnexpectedToken(token.clone()).into())
|
||||
}
|
||||
Token::Percentage { unit_value, .. } if num_context.is_ok(context.parsing_mode, unit_value) => {
|
||||
return Ok(LengthOrPercentage::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(BasicParseError::UnexpectedToken(token.clone()).into())
|
||||
} else {
|
||||
return Ok(LengthOrPercentage::Length(NoCalcLength::from_px(value)))
|
||||
}
|
||||
}
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {}
|
||||
_ => return Err(BasicParseError::UnexpectedToken(token.clone()).into())
|
||||
}
|
||||
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)
|
||||
})?;
|
||||
return Ok(LengthOrPercentage::Calc(Box::new(calc)))
|
||||
}
|
||||
_ => Err(())
|
||||
}.map_err(|()| BasicParseError::UnexpectedToken(token).into())
|
||||
}
|
||||
|
||||
let calc = input.parse_nested_block(|i| {
|
||||
CalcNode::parse_length_or_percentage(context, i, num_context)
|
||||
})?;
|
||||
Ok(LengthOrPercentage::Calc(Box::new(calc)))
|
||||
}
|
||||
|
||||
/// Parse a non-negative length.
|
||||
|
@ -1013,35 +1022,40 @@ impl LengthOrPercentageOrAuto {
|
|||
num_context: AllowedLengthType,
|
||||
allow_quirks: AllowQuirks)
|
||||
-> Result<Self, ParseError<'i>> {
|
||||
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(LengthOrPercentageOrAuto::Length)
|
||||
}
|
||||
Token::Percentage { unit_value, .. } if num_context.is_ok(context.parsing_mode, unit_value) => {
|
||||
Ok(LengthOrPercentageOrAuto::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(StyleParseError::UnspecifiedError.into())
|
||||
// FIXME: remove early returns when lifetimes are non-lexical
|
||||
{
|
||||
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(LengthOrPercentageOrAuto::Length)
|
||||
.map_err(|()| BasicParseError::UnexpectedToken(token.clone()).into())
|
||||
}
|
||||
Ok(LengthOrPercentageOrAuto::Length(
|
||||
NoCalcLength::Absolute(AbsoluteLength::Px(value))
|
||||
))
|
||||
Token::Percentage { unit_value, .. } if num_context.is_ok(context.parsing_mode, unit_value) => {
|
||||
return Ok(LengthOrPercentageOrAuto::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(StyleParseError::UnspecifiedError.into())
|
||||
}
|
||||
return Ok(LengthOrPercentageOrAuto::Length(
|
||||
NoCalcLength::Absolute(AbsoluteLength::Px(value))
|
||||
))
|
||||
}
|
||||
Token::Ident(ref value) if value.eq_ignore_ascii_case("auto") => {
|
||||
return Ok(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {}
|
||||
_ => return Err(BasicParseError::UnexpectedToken(token.clone()).into())
|
||||
}
|
||||
Token::Ident(ref value) if value.eq_ignore_ascii_case("auto") => {
|
||||
Ok(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
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(LengthOrPercentageOrAuto::Calc(Box::new(calc)))
|
||||
}
|
||||
_ => Err(())
|
||||
}.map_err(|()| BasicParseError::UnexpectedToken(token).into())
|
||||
}
|
||||
|
||||
let calc = input.parse_nested_block(|i| {
|
||||
CalcNode::parse_length_or_percentage(context, i, num_context)
|
||||
})?;
|
||||
Ok(LengthOrPercentageOrAuto::Calc(Box::new(calc)))
|
||||
}
|
||||
|
||||
/// Parse a non-negative length, percentage, or auto.
|
||||
|
@ -1112,33 +1126,39 @@ impl LengthOrPercentageOrNone {
|
|||
allow_quirks: AllowQuirks)
|
||||
-> Result<LengthOrPercentageOrNone, ParseError<'i>>
|
||||
{
|
||||
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(LengthOrPercentageOrNone::Length)
|
||||
}
|
||||
Token::Percentage { unit_value, .. } if num_context.is_ok(context.parsing_mode, unit_value) => {
|
||||
Ok(LengthOrPercentageOrNone::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(StyleParseError::UnspecifiedError.into())
|
||||
// FIXME: remove early returns when lifetimes are non-lexical
|
||||
{
|
||||
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(LengthOrPercentageOrNone::Length)
|
||||
.map_err(|()| BasicParseError::UnexpectedToken(token.clone()).into())
|
||||
}
|
||||
Ok(LengthOrPercentageOrNone::Length(
|
||||
NoCalcLength::Absolute(AbsoluteLength::Px(value))
|
||||
))
|
||||
Token::Percentage { unit_value, .. } if num_context.is_ok(context.parsing_mode, unit_value) => {
|
||||
return Ok(LengthOrPercentageOrNone::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(StyleParseError::UnspecifiedError.into())
|
||||
}
|
||||
return Ok(LengthOrPercentageOrNone::Length(
|
||||
NoCalcLength::Absolute(AbsoluteLength::Px(value))
|
||||
))
|
||||
}
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {}
|
||||
Token::Ident(ref value) if value.eq_ignore_ascii_case("none") => {
|
||||
return Ok(LengthOrPercentageOrNone::None)
|
||||
}
|
||||
_ => return Err(BasicParseError::UnexpectedToken(token.clone()).into())
|
||||
}
|
||||
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(LengthOrPercentageOrNone::Calc(Box::new(calc)))
|
||||
}
|
||||
Token::Ident(ref value) if value.eq_ignore_ascii_case("none") =>
|
||||
Ok(LengthOrPercentageOrNone::None),
|
||||
_ => Err(())
|
||||
}.map_err(|()| BasicParseError::UnexpectedToken(token).into())
|
||||
}
|
||||
|
||||
let calc = input.parse_nested_block(|i| {
|
||||
CalcNode::parse_length_or_percentage(context, i, num_context)
|
||||
})?;
|
||||
Ok(LengthOrPercentageOrNone::Calc(Box::new(calc)))
|
||||
}
|
||||
|
||||
/// Parse a non-negative LengthOrPercentageOrNone.
|
||||
|
|
|
@ -12,7 +12,6 @@ use cssparser::{Parser, Token, serialize_identifier, BasicParseError};
|
|||
use parser::{ParserContext, Parse};
|
||||
use self::url::SpecifiedUrl;
|
||||
use std::ascii::AsciiExt;
|
||||
use std::borrow::Cow;
|
||||
use std::f32;
|
||||
use std::fmt;
|
||||
use style_traits::{ToCss, ParseError, StyleParseError};
|
||||
|
@ -83,7 +82,7 @@ pub use ::gecko::url::*;
|
|||
impl Parse for SpecifiedUrl {
|
||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||
let url = input.expect_url()?;
|
||||
Self::parse_from_string(url.into_owned(), context)
|
||||
Self::parse_from_string(url.as_ref().to_owned(), context)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,17 +97,18 @@ no_viewport_percentage!(SpecifiedUrl);
|
|||
/// Parse an `<integer>` value, handling `calc()` correctly.
|
||||
pub fn parse_integer<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<Integer, ParseError<'i>> {
|
||||
match input.next()? {
|
||||
Token::Number { int_value: Some(v), .. } => 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))
|
||||
}
|
||||
t => Err(BasicParseError::UnexpectedToken(t).into())
|
||||
// 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(BasicParseError::UnexpectedToken(t.clone()).into())
|
||||
}
|
||||
|
||||
let result = input.parse_nested_block(|i| {
|
||||
CalcNode::parse_integer(context, i)
|
||||
})?;
|
||||
|
||||
Ok(Integer::from_calc(result))
|
||||
}
|
||||
|
||||
/// Parse a `<number>` value, handling `calc()` correctly, and without length
|
||||
|
@ -123,25 +123,26 @@ pub fn parse_number_with_clamping_mode<'i, 't>(context: &ParserContext,
|
|||
input: &mut Parser<'i, 't>,
|
||||
clamping_mode: AllowedNumericType)
|
||||
-> Result<Number, ParseError<'i>> {
|
||||
match input.next()? {
|
||||
// FIXME: remove early returns when lifetimes are non-lexical
|
||||
match *input.next()? {
|
||||
Token::Number { value, .. } if clamping_mode.is_ok(context.parsing_mode, value) => {
|
||||
Ok(Number {
|
||||
return 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") => {
|
||||
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),
|
||||
})
|
||||
}
|
||||
t => Err(BasicParseError::UnexpectedToken(t).into())
|
||||
Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {}
|
||||
ref t => return Err(BasicParseError::UnexpectedToken(t.clone()).into())
|
||||
}
|
||||
|
||||
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),
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq)]
|
||||
|
@ -228,7 +229,8 @@ impl Angle {
|
|||
impl Parse for Angle {
|
||||
/// Parses an angle according to CSS-VALUES § 6.1.
|
||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||
let token = input.next()?;
|
||||
// FIXME: remove clone() when lifetimes are non-lexical
|
||||
let token = input.next()?.clone();
|
||||
match token {
|
||||
Token::Dimension { value, ref unit, .. } => {
|
||||
Angle::parse_dimension(value, unit, /* from_calc = */ false)
|
||||
|
@ -237,7 +239,7 @@ impl Parse for Angle {
|
|||
return input.parse_nested_block(|i| CalcNode::parse_angle(context, i))
|
||||
}
|
||||
_ => Err(())
|
||||
}.map_err(|()| BasicParseError::UnexpectedToken(token).into())
|
||||
}.map_err(|()| BasicParseError::UnexpectedToken(token.clone()).into())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -268,7 +270,8 @@ impl Angle {
|
|||
/// https://github.com/w3c/csswg-drafts/issues/1162 is resolved.
|
||||
pub fn parse_with_unitless<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<Self, ParseError<'i>> {
|
||||
let token = input.next()?;
|
||||
// FIXME: remove clone() when lifetimes are non-lexical
|
||||
let token = input.next()?.clone();
|
||||
match token {
|
||||
Token::Dimension { value, ref unit, .. } => {
|
||||
Angle::parse_dimension(value, unit, /* from_calc = */ false)
|
||||
|
@ -278,7 +281,7 @@ impl Angle {
|
|||
return input.parse_nested_block(|i| CalcNode::parse_angle(context, i))
|
||||
}
|
||||
_ => Err(())
|
||||
}.map_err(|()| BasicParseError::UnexpectedToken(token).into())
|
||||
}.map_err(|()| BasicParseError::UnexpectedToken(token.clone()).into())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -366,24 +369,24 @@ impl Time {
|
|||
-> Result<Self, ParseError<'i>> {
|
||||
use style_traits::PARSING_MODE_DEFAULT;
|
||||
|
||||
// FIXME: remove early returns when lifetimes are non-lexical
|
||||
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
|
||||
// PARSING_MODE_DEFAULT directly.
|
||||
Ok(Token::Dimension { value, ref unit, .. }) if clamping_mode.is_ok(PARSING_MODE_DEFAULT, value) => {
|
||||
Time::parse_dimension(value, unit, /* from_calc = */ false)
|
||||
Ok(&Token::Dimension { value, ref unit, .. }) if clamping_mode.is_ok(PARSING_MODE_DEFAULT, value) => {
|
||||
return Time::parse_dimension(value, unit, /* from_calc = */ false)
|
||||
.map_err(|()| StyleParseError::UnspecifiedError.into())
|
||||
}
|
||||
Ok(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(PARSING_MODE_DEFAULT, time.seconds) => Ok(time),
|
||||
_ => Err(StyleParseError::UnspecifiedError.into()),
|
||||
}
|
||||
}
|
||||
Ok(t) => Err(BasicParseError::UnexpectedToken(t).into()),
|
||||
Err(e) => Err(e.into())
|
||||
Ok(&Token::Function(ref name)) if name.eq_ignore_ascii_case("calc") => {}
|
||||
Ok(t) => return Err(BasicParseError::UnexpectedToken(t.clone()).into()),
|
||||
Err(e) => return Err(e.into())
|
||||
}
|
||||
match input.parse_nested_block(|i| CalcNode::parse_time(context, i)) {
|
||||
Ok(time) if clamping_mode.is_ok(PARSING_MODE_DEFAULT, time.seconds) => Ok(time),
|
||||
_ => Err(StyleParseError::UnspecifiedError.into()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -814,10 +817,7 @@ impl ClipRect {
|
|||
}
|
||||
}
|
||||
|
||||
let func = input.expect_function()?;
|
||||
if !func.eq_ignore_ascii_case("rect") {
|
||||
return Err(StyleParseError::UnexpectedFunction(func).into())
|
||||
}
|
||||
input.expect_function_matching("rect")?;
|
||||
|
||||
input.parse_nested_block(|input| {
|
||||
let top = parse_argument(context, input, allow_quirks)?;
|
||||
|
@ -939,20 +939,20 @@ impl Attr {
|
|||
-> Result<Attr, ParseError<'i>> {
|
||||
// Syntax is `[namespace? `|`]? ident`
|
||||
// no spaces allowed
|
||||
let first = input.try(|i| i.expect_ident()).ok();
|
||||
if let Ok(token) = input.try(|i| i.next_including_whitespace()) {
|
||||
let first = input.try(|i| i.expect_ident_cloned()).ok();
|
||||
if let Ok(token) = input.try(|i| i.next_including_whitespace().map(|t| t.clone())) {
|
||||
match token {
|
||||
Token::Delim('|') => {}
|
||||
t => return Err(BasicParseError::UnexpectedToken(t).into()),
|
||||
ref t => return Err(BasicParseError::UnexpectedToken(t.clone()).into()),
|
||||
}
|
||||
// must be followed by an ident
|
||||
let second_token = match input.next_including_whitespace()? {
|
||||
Token::Ident(second) => second,
|
||||
t => return Err(BasicParseError::UnexpectedToken(t).into()),
|
||||
let second_token = match *input.next_including_whitespace()? {
|
||||
Token::Ident(ref second) => second,
|
||||
ref t => return Err(BasicParseError::UnexpectedToken(t.clone()).into()),
|
||||
};
|
||||
|
||||
let ns_with_id = if let Some(ns) = first {
|
||||
let ns = Namespace::from(Cow::from(ns));
|
||||
let ns = Namespace::from(ns.as_ref());
|
||||
let id: Result<_, ParseError> =
|
||||
get_id_for_namespace(&ns, context)
|
||||
.map_err(|()| StyleParseError::UnspecifiedError.into());
|
||||
|
@ -962,14 +962,14 @@ impl Attr {
|
|||
};
|
||||
return Ok(Attr {
|
||||
namespace: ns_with_id,
|
||||
attribute: second_token.into_owned(),
|
||||
attribute: second_token.as_ref().to_owned(),
|
||||
})
|
||||
}
|
||||
|
||||
if let Some(first) = first {
|
||||
Ok(Attr {
|
||||
namespace: None,
|
||||
attribute: first.into_owned(),
|
||||
attribute: first.as_ref().to_owned(),
|
||||
})
|
||||
} else {
|
||||
Err(StyleParseError::UnspecifiedError.into())
|
||||
|
|
|
@ -73,7 +73,7 @@ impl Parse for LineHeight {
|
|||
ref ident if ident.eq_ignore_ascii_case("-moz-block-height") => {
|
||||
Ok(GenericLineHeight::MozBlockHeight)
|
||||
},
|
||||
ident => Err(SelectorParseError::UnexpectedIdent(ident).into()),
|
||||
ident => Err(SelectorParseError::UnexpectedIdent(ident.clone()).into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -147,7 +147,7 @@ impl Parse for TimingFunction {
|
|||
if let Ok(keyword) = input.try(TimingKeyword::parse) {
|
||||
return Ok(GenericTimingFunction::Keyword(keyword));
|
||||
}
|
||||
if let Ok(ident) = input.try(|i| i.expect_ident()) {
|
||||
if let Ok(ident) = input.try(|i| i.expect_ident_cloned()) {
|
||||
let position = match_ignore_ascii_case! { &ident,
|
||||
"step-start" => StepPosition::Start,
|
||||
"step-end" => StepPosition::End,
|
||||
|
@ -155,7 +155,7 @@ impl Parse for TimingFunction {
|
|||
};
|
||||
return Ok(GenericTimingFunction::Steps(Integer::new(1), position));
|
||||
}
|
||||
let function = input.expect_function()?;
|
||||
let function = input.expect_function()?.clone();
|
||||
input.parse_nested_block(move |i| {
|
||||
(match_ignore_ascii_case! { &function,
|
||||
"cubic-bezier" => {
|
||||
|
@ -190,7 +190,7 @@ impl Parse for TimingFunction {
|
|||
}
|
||||
},
|
||||
_ => Err(()),
|
||||
}).map_err(|()| StyleParseError::UnexpectedFunction(function).into())
|
||||
}).map_err(|()| StyleParseError::UnexpectedFunction(function.clone()).into())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue