mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Update to cssparser 0.22 (source location in error types)
This commit is contained in:
parent
056e599562
commit
c0f8f15f39
90 changed files with 974 additions and 790 deletions
|
@ -16,7 +16,7 @@ gecko = []
|
|||
[dependencies]
|
||||
app_units = "0.5"
|
||||
bitflags = "0.7"
|
||||
cssparser = "0.21.1"
|
||||
cssparser = "0.22.0"
|
||||
euclid = "0.15"
|
||||
heapsize = {version = "0.4", optional = true}
|
||||
heapsize_derive = {version = "0.1", optional = true}
|
||||
|
|
|
@ -30,7 +30,7 @@ extern crate servo_arc;
|
|||
#[cfg(feature = "servo")] pub use webrender_api::DevicePixel;
|
||||
|
||||
use cssparser::{CowRcStr, Token};
|
||||
use selectors::parser::SelectorParseError;
|
||||
use selectors::parser::SelectorParseErrorKind;
|
||||
#[cfg(feature = "servo")] use servo_atoms::Atom;
|
||||
|
||||
/// One hardware pixel.
|
||||
|
@ -85,11 +85,20 @@ pub mod viewport;
|
|||
pub use values::{Comma, CommaWithSpace, OneOrMoreSeparated, Separator, Space, ToCss};
|
||||
|
||||
/// The error type for all CSS parsing routines.
|
||||
pub type ParseError<'i> = cssparser::ParseError<'i, SelectorParseError<'i, StyleParseError<'i>>>;
|
||||
pub type ParseError<'i> = cssparser::ParseError<'i, SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>>;
|
||||
|
||||
/// Error emitted by the style crate
|
||||
pub type StyleParseError<'i> = cssparser::ParseError<'i, StyleParseErrorKind<'i>>;
|
||||
|
||||
/// Error in property value parsing
|
||||
pub type ValueParseError<'i> = cssparser::ParseError<'i, ValueParseErrorKind<'i>>;
|
||||
|
||||
/// Error in property parsing
|
||||
pub type PropertyDeclarationParseError<'i> = cssparser::ParseError<'i, PropertyDeclarationParseErrorKind<'i>>;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
/// Errors that can be encountered while parsing CSS values.
|
||||
pub enum StyleParseError<'i> {
|
||||
pub enum StyleParseErrorKind<'i> {
|
||||
/// A bad URL token in a DVB.
|
||||
BadUrlInDeclarationValueBlock(CowRcStr<'i>),
|
||||
/// A bad string token in a DVB.
|
||||
|
@ -101,7 +110,7 @@ pub enum StyleParseError<'i> {
|
|||
/// Unexpected closing curly bracket in a DVB.
|
||||
UnbalancedCloseCurlyBracketInDeclarationValueBlock,
|
||||
/// A property declaration parsing error.
|
||||
PropertyDeclaration(PropertyDeclarationParseError<'i>),
|
||||
PropertyDeclaration(PropertyDeclarationParseErrorKind<'i>),
|
||||
/// A property declaration value had input remaining after successfully parsing.
|
||||
PropertyDeclarationValueNotExhausted,
|
||||
/// An unexpected dimension token was encountered.
|
||||
|
@ -129,39 +138,33 @@ pub enum StyleParseError<'i> {
|
|||
/// An unexpected token was found within a namespace rule.
|
||||
UnexpectedTokenWithinNamespace(Token<'i>),
|
||||
/// An error was encountered while parsing a property value.
|
||||
ValueError(ValueParseError<'i>),
|
||||
ValueError(ValueParseErrorKind<'i>),
|
||||
}
|
||||
|
||||
impl<'i> From<ValueParseErrorKind<'i>> for SelectorParseErrorKind<'i, StyleParseErrorKind<'i>> {
|
||||
fn from(this: ValueParseErrorKind<'i>) -> Self {
|
||||
StyleParseErrorKind::ValueError(this).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'i> From<PropertyDeclarationParseErrorKind<'i>> for SelectorParseErrorKind<'i, StyleParseErrorKind<'i>> {
|
||||
fn from(this: PropertyDeclarationParseErrorKind<'i>) -> Self {
|
||||
StyleParseErrorKind::PropertyDeclaration(this).into()
|
||||
}
|
||||
}
|
||||
|
||||
/// Specific errors that can be encountered while parsing property values.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum ValueParseError<'i> {
|
||||
pub enum ValueParseErrorKind<'i> {
|
||||
/// An invalid token was encountered while parsing a color value.
|
||||
InvalidColor(Token<'i>),
|
||||
/// An invalid filter value was encountered.
|
||||
InvalidFilter(Token<'i>),
|
||||
}
|
||||
|
||||
impl<'a> From<ValueParseError<'a>> for ParseError<'a> {
|
||||
fn from(this: ValueParseError<'a>) -> Self {
|
||||
StyleParseError::ValueError(this).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'i> ValueParseError<'i> {
|
||||
/// Attempt to extract a ValueParseError value from a ParseError.
|
||||
pub fn from_parse_error(this: ParseError<'i>) -> Option<ValueParseError<'i>> {
|
||||
match this {
|
||||
cssparser::ParseError::Custom(
|
||||
SelectorParseError::Custom(
|
||||
StyleParseError::ValueError(e))) => Some(e),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The result of parsing a property declaration.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum PropertyDeclarationParseError<'i> {
|
||||
pub enum PropertyDeclarationParseErrorKind<'i> {
|
||||
/// The property declaration was for an unknown property.
|
||||
UnknownProperty(CowRcStr<'i>),
|
||||
/// An unknown vendor-specific identifier was encountered.
|
||||
|
@ -169,7 +172,7 @@ pub enum PropertyDeclarationParseError<'i> {
|
|||
/// The property declaration was for a disabled experimental property.
|
||||
ExperimentalProperty,
|
||||
/// The property declaration contained an invalid value.
|
||||
InvalidValue(CowRcStr<'i>, Option<ValueParseError<'i>>),
|
||||
InvalidValue(CowRcStr<'i>, Option<ValueParseErrorKind<'i>>),
|
||||
/// The declaration contained an animation property, and we were parsing
|
||||
/// this as a keyframe block (so that property should be ignored).
|
||||
///
|
||||
|
@ -179,15 +182,23 @@ pub enum PropertyDeclarationParseError<'i> {
|
|||
NotAllowedInPageRule,
|
||||
}
|
||||
|
||||
impl<'a> From<StyleParseError<'a>> for ParseError<'a> {
|
||||
fn from(this: StyleParseError<'a>) -> Self {
|
||||
cssparser::ParseError::Custom(SelectorParseError::Custom(this))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<PropertyDeclarationParseError<'a>> for ParseError<'a> {
|
||||
fn from(this: PropertyDeclarationParseError<'a>) -> Self {
|
||||
cssparser::ParseError::Custom(SelectorParseError::Custom(StyleParseError::PropertyDeclaration(this)))
|
||||
impl<'i> PropertyDeclarationParseErrorKind<'i> {
|
||||
/// Create an InvalidValue parse error
|
||||
pub fn new_invalid(name: CowRcStr<'i>, value_error: ParseError<'i>) -> PropertyDeclarationParseError<'i> {
|
||||
cssparser::ParseError {
|
||||
kind: cssparser::ParseErrorKind::Custom(PropertyDeclarationParseErrorKind::InvalidValue(
|
||||
name,
|
||||
match value_error.kind {
|
||||
cssparser::ParseErrorKind::Custom(
|
||||
SelectorParseErrorKind::Custom(
|
||||
StyleParseErrorKind::ValueError(e)
|
||||
)
|
||||
) => Some(e),
|
||||
_ => None,
|
||||
}
|
||||
)),
|
||||
location: value_error.location,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
//! Helper types and traits for the handling of CSS values.
|
||||
|
||||
use app_units::Au;
|
||||
use cssparser::{BasicParseError, ParseError, Parser, Token, UnicodeRange, serialize_string};
|
||||
use cssparser::{ParseError, Parser, Token, UnicodeRange, serialize_string};
|
||||
use cssparser::ToCss as CssparserToCss;
|
||||
use servo_arc::Arc;
|
||||
use std::fmt::{self, Write};
|
||||
|
@ -299,12 +299,13 @@ impl Separator for CommaWithSpace {
|
|||
let mut results = vec![parse_one(input)?];
|
||||
loop {
|
||||
input.skip_whitespace(); // Unnecessary for correctness, but may help try() rewind less.
|
||||
let comma_location = input.current_source_location();
|
||||
let comma = input.try(|i| i.expect_comma()).is_ok();
|
||||
input.skip_whitespace(); // Unnecessary for correctness, but may help try() rewind less.
|
||||
if let Ok(item) = input.try(&mut parse_one) {
|
||||
results.push(item);
|
||||
} else if comma {
|
||||
return Err(BasicParseError::UnexpectedToken(Token::Comma).into());
|
||||
return Err(comma_location.new_unexpected_token_error(Token::Comma));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
@ -449,11 +450,16 @@ macro_rules! __define_css_keyword_enum__actual {
|
|||
/// Parse this property from a CSS input stream.
|
||||
pub fn parse<'i, 't>(input: &mut ::cssparser::Parser<'i, 't>)
|
||||
-> Result<$name, $crate::ParseError<'i>> {
|
||||
let ident = input.expect_ident()?;
|
||||
Self::from_ident(&ident)
|
||||
.map_err(|()| ::cssparser::ParseError::Basic(
|
||||
::cssparser::BasicParseError::UnexpectedToken(
|
||||
::cssparser::Token::Ident(ident.clone()))))
|
||||
use cssparser::Token;
|
||||
let location = input.current_source_location();
|
||||
match *input.next()? {
|
||||
Token::Ident(ref ident) => {
|
||||
Self::from_ident(ident).map_err(|()| {
|
||||
location.new_unexpected_token_error(Token::Ident(ident.clone()))
|
||||
})
|
||||
}
|
||||
ref token => Err(location.new_unexpected_token_error(token.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse this property from an already-tokenized identifier.
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
//! Helper types for the `@viewport` rule.
|
||||
|
||||
use {CSSPixel, PinchZoomFactor, ParseError};
|
||||
use cssparser::{Parser, ToCss, ParseError as CssParseError, BasicParseError};
|
||||
use cssparser::{Parser, ToCss};
|
||||
use euclid::TypedSize2D;
|
||||
use std::ascii::AsciiExt;
|
||||
use std::fmt;
|
||||
|
@ -109,6 +109,7 @@ impl Zoom {
|
|||
use cssparser::Token;
|
||||
use values::specified::AllowedNumericType::NonNegative;
|
||||
|
||||
let location = input.current_source_location();
|
||||
match *input.next()? {
|
||||
// TODO: This parse() method should take ParserContext as an
|
||||
// argument, and pass ParsingMode owned by the ParserContext to
|
||||
|
@ -123,7 +124,7 @@ impl Zoom {
|
|||
Token::Ident(ref value) if value.eq_ignore_ascii_case("auto") => {
|
||||
Ok(Zoom::Auto)
|
||||
}
|
||||
ref t => Err(CssParseError::Basic(BasicParseError::UnexpectedToken(t.clone())))
|
||||
ref t => Err(location.new_unexpected_token_error(t.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue