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
|
@ -7,7 +7,7 @@
|
|||
use app_units::AU_PER_PX;
|
||||
use app_units::Au;
|
||||
use context::QuirksMode;
|
||||
use cssparser::{CssStringWriter, Parser, RGBA, Token, BasicParseError};
|
||||
use cssparser::{CssStringWriter, Parser, RGBA, Token, BasicParseErrorKind};
|
||||
use euclid::ScaleFactor;
|
||||
use euclid::Size2D;
|
||||
use font_metrics::get_metrics_provider_for_product;
|
||||
|
@ -30,7 +30,7 @@ use std::sync::atomic::{AtomicBool, AtomicIsize, AtomicUsize, Ordering};
|
|||
use str::starts_with_ignore_ascii_case;
|
||||
use string_cache::Atom;
|
||||
use style_traits::{CSSPixel, DevicePixel};
|
||||
use style_traits::{ToCss, ParseError, StyleParseError};
|
||||
use style_traits::{ToCss, ParseError, StyleParseErrorKind};
|
||||
use style_traits::viewport::ViewportConstraints;
|
||||
use stylesheets::Origin;
|
||||
use values::{CSSFloat, CustomIdent, serialize_dimension};
|
||||
|
@ -285,15 +285,16 @@ impl Resolution {
|
|||
}
|
||||
|
||||
fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||
let location = input.current_source_location();
|
||||
let (value, unit) = match *input.next()? {
|
||||
Token::Dimension { value, ref unit, .. } => {
|
||||
(value, unit)
|
||||
},
|
||||
ref t => return Err(BasicParseError::UnexpectedToken(t.clone()).into()),
|
||||
ref t => return Err(location.new_unexpected_token_error(t.clone())),
|
||||
};
|
||||
|
||||
if value <= 0. {
|
||||
return Err(StyleParseError::UnspecifiedError.into())
|
||||
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||
}
|
||||
|
||||
(match_ignore_ascii_case! { &unit,
|
||||
|
@ -301,7 +302,7 @@ impl Resolution {
|
|||
"dppx" => Ok(Resolution::Dppx(value)),
|
||||
"dpcm" => Ok(Resolution::Dpcm(value)),
|
||||
_ => Err(())
|
||||
}).map_err(|()| StyleParseError::UnexpectedDimension(unit.clone()).into())
|
||||
}).map_err(|()| location.new_custom_error(StyleParseErrorKind::UnexpectedDimension(unit.clone())))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -498,7 +499,7 @@ fn parse_feature_value<'i, 't>(feature: &nsMediaFeature,
|
|||
// for parity with gecko. We should remove this check when we want
|
||||
// to support it.
|
||||
if let Length::Calc(_) = length {
|
||||
return Err(StyleParseError::UnspecifiedError.into())
|
||||
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||
}
|
||||
MediaExpressionValue::Length(length)
|
||||
},
|
||||
|
@ -508,14 +509,14 @@ fn parse_feature_value<'i, 't>(feature: &nsMediaFeature,
|
|||
// supported in media queries per FIXME above.
|
||||
let i = input.expect_integer()?;
|
||||
if i < 0 {
|
||||
return Err(StyleParseError::UnspecifiedError.into())
|
||||
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||
}
|
||||
MediaExpressionValue::Integer(i as u32)
|
||||
}
|
||||
nsMediaFeature_ValueType::eBoolInteger => {
|
||||
let i = input.expect_integer()?;
|
||||
if i < 0 || i > 1 {
|
||||
return Err(StyleParseError::UnspecifiedError.into())
|
||||
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||
}
|
||||
MediaExpressionValue::BoolInteger(i == 1)
|
||||
}
|
||||
|
@ -525,14 +526,14 @@ fn parse_feature_value<'i, 't>(feature: &nsMediaFeature,
|
|||
nsMediaFeature_ValueType::eIntRatio => {
|
||||
let a = input.expect_integer()?;
|
||||
if a <= 0 {
|
||||
return Err(StyleParseError::UnspecifiedError.into())
|
||||
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||
}
|
||||
|
||||
input.expect_delim('/')?;
|
||||
|
||||
let b = input.expect_integer()?;
|
||||
if b <= 0 {
|
||||
return Err(StyleParseError::UnspecifiedError.into())
|
||||
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||
}
|
||||
MediaExpressionValue::IntRatio(a as u32, b as u32)
|
||||
}
|
||||
|
@ -540,28 +541,26 @@ fn parse_feature_value<'i, 't>(feature: &nsMediaFeature,
|
|||
MediaExpressionValue::Resolution(Resolution::parse(input)?)
|
||||
}
|
||||
nsMediaFeature_ValueType::eEnumerated => {
|
||||
let keyword = input.expect_ident()?;
|
||||
let keyword = unsafe {
|
||||
bindings::Gecko_LookupCSSKeyword(keyword.as_bytes().as_ptr(),
|
||||
keyword.len() as u32)
|
||||
};
|
||||
let location = input.current_source_location();
|
||||
let keyword = input.expect_ident()?;
|
||||
let keyword = unsafe {
|
||||
bindings::Gecko_LookupCSSKeyword(keyword.as_bytes().as_ptr(),
|
||||
keyword.len() as u32)
|
||||
};
|
||||
|
||||
let first_table_entry: *const nsCSSProps_KTableEntry = unsafe {
|
||||
*feature.mData.mKeywordTable.as_ref()
|
||||
};
|
||||
let first_table_entry: *const nsCSSProps_KTableEntry = unsafe {
|
||||
*feature.mData.mKeywordTable.as_ref()
|
||||
};
|
||||
|
||||
let value =
|
||||
match unsafe { find_in_table(first_table_entry, |kw, _| kw == keyword) } {
|
||||
Some((_kw, value)) => {
|
||||
value
|
||||
}
|
||||
None => return Err(StyleParseError::UnspecifiedError.into()),
|
||||
};
|
||||
let value = match unsafe { find_in_table(first_table_entry, |kw, _| kw == keyword) } {
|
||||
Some((_kw, value)) => value,
|
||||
None => return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError)),
|
||||
};
|
||||
|
||||
MediaExpressionValue::Enumerated(value)
|
||||
MediaExpressionValue::Enumerated(value)
|
||||
}
|
||||
nsMediaFeature_ValueType::eIdent => {
|
||||
MediaExpressionValue::Ident(input.expect_ident()?.as_ref().to_owned())
|
||||
MediaExpressionValue::Ident(input.expect_ident()?.as_ref().to_owned())
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -590,10 +589,10 @@ impl Expression {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
input.expect_parenthesis_block().map_err(|err|
|
||||
match err {
|
||||
BasicParseError::UnexpectedToken(t) => StyleParseError::ExpectedIdentifier(t),
|
||||
_ => StyleParseError::UnspecifiedError,
|
||||
}
|
||||
err.location.new_custom_error(match err.kind {
|
||||
BasicParseErrorKind::UnexpectedToken(t) => StyleParseErrorKind::ExpectedIdentifier(t),
|
||||
_ => StyleParseErrorKind::UnspecifiedError,
|
||||
})
|
||||
)?;
|
||||
|
||||
input.parse_nested_block(|input| {
|
||||
|
@ -601,11 +600,12 @@ impl Expression {
|
|||
let feature;
|
||||
let range;
|
||||
{
|
||||
let location = input.current_source_location();
|
||||
let ident = input.expect_ident().map_err(|err|
|
||||
match err {
|
||||
BasicParseError::UnexpectedToken(t) => StyleParseError::ExpectedIdentifier(t),
|
||||
_ => StyleParseError::UnspecifiedError,
|
||||
}
|
||||
err.location.new_custom_error(match err.kind {
|
||||
BasicParseErrorKind::UnexpectedToken(t) => StyleParseErrorKind::ExpectedIdentifier(t),
|
||||
_ => StyleParseErrorKind::UnspecifiedError,
|
||||
})
|
||||
)?;
|
||||
|
||||
let mut flags = 0;
|
||||
|
@ -648,19 +648,25 @@ impl Expression {
|
|||
Ok((f, r)) => {
|
||||
feature = f;
|
||||
range = r;
|
||||
},
|
||||
}
|
||||
Err(()) => {
|
||||
return Err(StyleParseError::MediaQueryExpectedFeatureName(ident.clone()).into())
|
||||
},
|
||||
return Err(location.new_custom_error(
|
||||
StyleParseErrorKind::MediaQueryExpectedFeatureName(ident.clone())
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
if (feature.mReqFlags & !flags) != 0 {
|
||||
return Err(StyleParseError::MediaQueryExpectedFeatureName(ident.clone()).into());
|
||||
return Err(location.new_custom_error(
|
||||
StyleParseErrorKind::MediaQueryExpectedFeatureName(ident.clone())
|
||||
))
|
||||
}
|
||||
|
||||
if range != nsMediaExpression_Range::eEqual &&
|
||||
feature.mRangeType != nsMediaFeature_RangeType::eMinMaxAllowed {
|
||||
return Err(StyleParseError::MediaQueryExpectedFeatureName(ident.clone()).into());
|
||||
return Err(location.new_custom_error(
|
||||
StyleParseErrorKind::MediaQueryExpectedFeatureName(ident.clone())
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -671,15 +677,15 @@ impl Expression {
|
|||
// reject them here too.
|
||||
if input.try(|i| i.expect_colon()).is_err() {
|
||||
if range != nsMediaExpression_Range::eEqual {
|
||||
return Err(StyleParseError::RangedExpressionWithNoValue.into())
|
||||
return Err(input.new_custom_error(StyleParseErrorKind::RangedExpressionWithNoValue))
|
||||
}
|
||||
return Ok(Expression::new(feature, None, range));
|
||||
}
|
||||
|
||||
let value = parse_feature_value(feature,
|
||||
feature.mValueType,
|
||||
context, input).map_err(|_|
|
||||
StyleParseError::MediaQueryExpectedFeatureValue
|
||||
context, input).map_err(|err|
|
||||
err.location.new_custom_error(StyleParseErrorKind::MediaQueryExpectedFeatureValue)
|
||||
)?;
|
||||
|
||||
Ok(Expression::new(feature, Some(value), range))
|
||||
|
|
|
@ -4,18 +4,18 @@
|
|||
|
||||
//! Gecko-specific bits for selector-parsing.
|
||||
|
||||
use cssparser::{BasicParseError, Parser, ToCss, Token, CowRcStr};
|
||||
use cssparser::{BasicParseError, BasicParseErrorKind, Parser, ToCss, Token, CowRcStr, SourceLocation};
|
||||
use element_state::ElementState;
|
||||
use gecko_bindings::structs::CSSPseudoClassType;
|
||||
use gecko_bindings::structs::RawServoSelectorList;
|
||||
use gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI};
|
||||
use selector_parser::{SelectorParser, PseudoElementCascadeType};
|
||||
use selectors::SelectorList;
|
||||
use selectors::parser::{Selector, SelectorMethods, SelectorParseError};
|
||||
use selectors::parser::{Selector, SelectorMethods, SelectorParseErrorKind};
|
||||
use selectors::visitor::SelectorVisitor;
|
||||
use std::fmt;
|
||||
use string_cache::{Atom, Namespace, WeakAtom, WeakNamespace};
|
||||
use style_traits::{ParseError, StyleParseError};
|
||||
use style_traits::{ParseError, StyleParseErrorKind};
|
||||
|
||||
pub use gecko::pseudo_element::{PseudoElement, EAGER_PSEUDOS, EAGER_PSEUDO_COUNT, SIMPLE_PSEUDO_COUNT};
|
||||
pub use gecko::snapshot::SnapshotMap;
|
||||
|
@ -298,14 +298,14 @@ impl<'a> SelectorParser<'a> {
|
|||
|
||||
impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
|
||||
type Impl = SelectorImpl;
|
||||
type Error = StyleParseError<'i>;
|
||||
type Error = StyleParseErrorKind<'i>;
|
||||
|
||||
fn is_pseudo_element_allows_single_colon(name: &CowRcStr<'i>) -> bool {
|
||||
::selectors::parser::is_css2_pseudo_element(name) ||
|
||||
name.starts_with("-moz-tree-") // tree pseudo-elements
|
||||
}
|
||||
|
||||
fn parse_non_ts_pseudo_class(&self, name: CowRcStr<'i>)
|
||||
fn parse_non_ts_pseudo_class(&self, location: SourceLocation, name: CowRcStr<'i>)
|
||||
-> Result<NonTSPseudoClass, ParseError<'i>> {
|
||||
macro_rules! pseudo_class_parse {
|
||||
(bare: [$(($css:expr, $name:ident, $gecko_type:tt, $state:tt, $flags:tt),)*],
|
||||
|
@ -313,8 +313,9 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
|
|||
keyword: [$(($k_css:expr, $k_name:ident, $k_gecko_type:tt, $k_state:tt, $k_flags:tt),)*]) => {
|
||||
match_ignore_ascii_case! { &name,
|
||||
$($css => NonTSPseudoClass::$name,)*
|
||||
_ => return Err(::selectors::parser::SelectorParseError::UnsupportedPseudoClassOrElement(
|
||||
name.clone()).into())
|
||||
_ => return Err(location.new_custom_error(
|
||||
SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name.clone())
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -322,7 +323,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
|
|||
if self.is_pseudo_class_enabled(&pseudo_class) {
|
||||
Ok(pseudo_class)
|
||||
} else {
|
||||
Err(SelectorParseError::UnsupportedPseudoClassOrElement(name).into())
|
||||
Err(location.new_custom_error(SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -355,11 +356,15 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
|
|||
})?;
|
||||
// Selectors inside `:-moz-any` may not include combinators.
|
||||
if selectors.iter().flat_map(|x| x.iter_raw_match_order()).any(|s| s.is_combinator()) {
|
||||
return Err(SelectorParseError::UnexpectedIdent("-moz-any".into()).into())
|
||||
return Err(parser.new_custom_error(
|
||||
SelectorParseErrorKind::UnexpectedIdent("-moz-any".into())
|
||||
))
|
||||
}
|
||||
NonTSPseudoClass::MozAny(selectors.into_boxed_slice())
|
||||
}
|
||||
_ => return Err(SelectorParseError::UnsupportedPseudoClassOrElement(name.clone()).into())
|
||||
_ => return Err(parser.new_custom_error(
|
||||
SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name.clone())
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -367,13 +372,14 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
|
|||
if self.is_pseudo_class_enabled(&pseudo_class) {
|
||||
Ok(pseudo_class)
|
||||
} else {
|
||||
Err(SelectorParseError::UnsupportedPseudoClassOrElement(name).into())
|
||||
Err(parser.new_custom_error(SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name)))
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_pseudo_element(&self, name: CowRcStr<'i>) -> Result<PseudoElement, ParseError<'i>> {
|
||||
fn parse_pseudo_element(&self, location: SourceLocation, name: CowRcStr<'i>)
|
||||
-> Result<PseudoElement, ParseError<'i>> {
|
||||
PseudoElement::from_slice(&name, self.in_user_agent_stylesheet())
|
||||
.ok_or(SelectorParseError::UnsupportedPseudoClassOrElement(name.clone()).into())
|
||||
.ok_or(location.new_custom_error(SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name.clone())))
|
||||
}
|
||||
|
||||
fn parse_functional_pseudo_element<'t>(&self, name: CowRcStr<'i>,
|
||||
|
@ -384,11 +390,12 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
|
|||
// separated by either comma or space.
|
||||
let mut args = Vec::new();
|
||||
loop {
|
||||
let location = parser.current_source_location();
|
||||
match parser.next() {
|
||||
Ok(&Token::Ident(ref ident)) => args.push(ident.as_ref().to_owned()),
|
||||
Ok(&Token::Comma) => {},
|
||||
Ok(t) => return Err(BasicParseError::UnexpectedToken(t.clone()).into()),
|
||||
Err(BasicParseError::EndOfInput) => break,
|
||||
Ok(t) => return Err(location.new_unexpected_token_error(t.clone())),
|
||||
Err(BasicParseError { kind: BasicParseErrorKind::EndOfInput, .. }) => break,
|
||||
_ => unreachable!("Parser::next() shouldn't return any other error"),
|
||||
}
|
||||
}
|
||||
|
@ -397,7 +404,7 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
|
|||
return Ok(pseudo);
|
||||
}
|
||||
}
|
||||
Err(SelectorParseError::UnsupportedPseudoClassOrElement(name.clone()).into())
|
||||
Err(parser.new_custom_error(SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name.clone())))
|
||||
}
|
||||
|
||||
fn default_namespace(&self) -> Option<Namespace> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue