mirror of
https://github.com/servo/servo.git
synced 2025-08-09 07:25:35 +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
|
@ -6,7 +6,7 @@
|
|||
//! initially in CSS Conditional Rules Module Level 3, @document has been postponed to the level 4.
|
||||
//! We implement the prefixed `@-moz-document`.
|
||||
|
||||
use cssparser::{Parser, Token, SourceLocation, BasicParseError};
|
||||
use cssparser::{Parser, Token, SourceLocation};
|
||||
#[cfg(feature = "gecko")]
|
||||
use malloc_size_of::{MallocSizeOfOps, MallocUnconditionalShallowSizeOf};
|
||||
use media_queries::Device;
|
||||
|
@ -14,7 +14,7 @@ use parser::{Parse, ParserContext};
|
|||
use servo_arc::Arc;
|
||||
use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard};
|
||||
use std::fmt;
|
||||
use style_traits::{ToCss, ParseError, StyleParseError};
|
||||
use style_traits::{ToCss, ParseError, StyleParseErrorKind};
|
||||
use stylesheets::CssRules;
|
||||
use values::specified::url::SpecifiedUrl;
|
||||
|
||||
|
@ -100,10 +100,11 @@ macro_rules! parse_quoted_or_unquoted_string {
|
|||
$input.parse_nested_block(|input| {
|
||||
let start = input.position();
|
||||
input.parse_entirely(|input| {
|
||||
let location = input.current_source_location();
|
||||
match input.next() {
|
||||
Ok(&Token::QuotedString(ref value)) =>
|
||||
Ok($url_matching_function(value.as_ref().to_owned())),
|
||||
Ok(t) => Err(BasicParseError::UnexpectedToken(t.clone()).into()),
|
||||
Ok(t) => Err(location.new_unexpected_token_error(t.clone())),
|
||||
Err(e) => Err(e.into()),
|
||||
}
|
||||
}).or_else(|_: ParseError| {
|
||||
|
@ -129,7 +130,7 @@ impl UrlMatchingFunction {
|
|||
} else if let Ok(url) = input.try(|input| SpecifiedUrl::parse(context, input)) {
|
||||
Ok(UrlMatchingFunction::Url(url))
|
||||
} else {
|
||||
Err(StyleParseError::UnspecifiedError.into())
|
||||
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
use Atom;
|
||||
use computed_values::font_family::FamilyName;
|
||||
use cssparser::{AtRuleParser, AtRuleType, BasicParseError, DeclarationListParser, DeclarationParser, Parser};
|
||||
use cssparser::{AtRuleParser, AtRuleType, BasicParseErrorKind, DeclarationListParser, DeclarationParser, Parser};
|
||||
use cssparser::{CowRcStr, RuleListParser, SourceLocation, QualifiedRuleParser, Token, serialize_identifier};
|
||||
use error_reporting::{ContextualParseError, ParseErrorReporter};
|
||||
#[cfg(feature = "gecko")]
|
||||
|
@ -16,10 +16,10 @@ use gecko_bindings::bindings::Gecko_AppendFeatureValueHashEntry;
|
|||
#[cfg(feature = "gecko")]
|
||||
use gecko_bindings::structs::{self, gfxFontFeatureValueSet, nsTArray};
|
||||
use parser::{ParserContext, ParserErrorContext, Parse};
|
||||
use selectors::parser::SelectorParseError;
|
||||
use selectors::parser::SelectorParseErrorKind;
|
||||
use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard};
|
||||
use std::fmt;
|
||||
use style_traits::{ParseError, StyleParseError, ToCss};
|
||||
use style_traits::{ParseError, StyleParseErrorKind, ToCss};
|
||||
use stylesheets::CssRuleType;
|
||||
|
||||
/// A @font-feature-values block declaration.
|
||||
|
@ -59,9 +59,10 @@ pub struct SingleValue(pub u32);
|
|||
impl Parse for SingleValue {
|
||||
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<SingleValue, ParseError<'i>> {
|
||||
let location = input.current_source_location();
|
||||
match *input.next()? {
|
||||
Token::Number { int_value: Some(v), .. } if v >= 0 => Ok(SingleValue(v as u32)),
|
||||
ref t => Err(BasicParseError::UnexpectedToken(t.clone()).into()),
|
||||
ref t => Err(location.new_unexpected_token_error(t.clone())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,16 +88,18 @@ pub struct PairValues(pub u32, pub Option<u32>);
|
|||
impl Parse for PairValues {
|
||||
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<PairValues, ParseError<'i>> {
|
||||
let location = input.current_source_location();
|
||||
let first = match *input.next()? {
|
||||
Token::Number { int_value: Some(a), .. } if a >= 0 => a as u32,
|
||||
ref t => return Err(BasicParseError::UnexpectedToken(t.clone()).into()),
|
||||
ref t => return Err(location.new_unexpected_token_error(t.clone())),
|
||||
};
|
||||
let location = input.current_source_location();
|
||||
match input.next() {
|
||||
Ok(&Token::Number { int_value: Some(b), .. }) if b >= 0 => {
|
||||
Ok(PairValues(first, Some(b as u32)))
|
||||
}
|
||||
// It can't be anything other than number.
|
||||
Ok(t) => Err(BasicParseError::UnexpectedToken(t.clone()).into()),
|
||||
Ok(t) => Err(location.new_unexpected_token_error(t.clone())),
|
||||
// It can be just one value.
|
||||
Err(_) => Ok(PairValues(first, None))
|
||||
}
|
||||
|
@ -136,18 +139,19 @@ impl Parse for VectorValues {
|
|||
-> Result<VectorValues, ParseError<'i>> {
|
||||
let mut vec = vec![];
|
||||
loop {
|
||||
let location = input.current_source_location();
|
||||
match input.next() {
|
||||
Ok(&Token::Number { int_value: Some(a), .. }) if a >= 0 => {
|
||||
vec.push(a as u32);
|
||||
},
|
||||
// It can't be anything other than number.
|
||||
Ok(t) => return Err(BasicParseError::UnexpectedToken(t.clone()).into()),
|
||||
Ok(t) => return Err(location.new_unexpected_token_error(t.clone())),
|
||||
Err(_) => break,
|
||||
}
|
||||
}
|
||||
|
||||
if vec.len() == 0 {
|
||||
return Err(BasicParseError::EndOfInput.into());
|
||||
return Err(input.new_error(BasicParseErrorKind::EndOfInput));
|
||||
}
|
||||
|
||||
Ok(VectorValues(vec))
|
||||
|
@ -197,14 +201,14 @@ impl<'a, 'b, 'i, T> AtRuleParser<'i> for FFVDeclarationsParser<'a, 'b, T> {
|
|||
type PreludeNoBlock = ();
|
||||
type PreludeBlock = ();
|
||||
type AtRule = ();
|
||||
type Error = SelectorParseError<'i, StyleParseError<'i>>;
|
||||
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'i, T> DeclarationParser<'i> for FFVDeclarationsParser<'a, 'b, T>
|
||||
where T: Parse
|
||||
{
|
||||
type Declaration = ();
|
||||
type Error = SelectorParseError<'i, StyleParseError<'i>>;
|
||||
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
|
||||
|
||||
fn parse_value<'t>(&mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>)
|
||||
-> Result<(), ParseError<'i>> {
|
||||
|
@ -271,8 +275,8 @@ macro_rules! font_feature_values_blocks {
|
|||
rule: &mut rule,
|
||||
});
|
||||
while let Some(result) = iter.next() {
|
||||
if let Err(err) = result {
|
||||
let error = ContextualParseError::UnsupportedRule(err.slice, err.error);
|
||||
if let Err((error, slice)) = result {
|
||||
let error = ContextualParseError::UnsupportedRule(slice, error);
|
||||
let location = iter.input.current_source_location();
|
||||
context.log_css_error(error_context, location, error);
|
||||
}
|
||||
|
@ -388,24 +392,24 @@ macro_rules! font_feature_values_blocks {
|
|||
impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for FontFeatureValuesRuleParser<'a, R> {
|
||||
type Prelude = ();
|
||||
type QualifiedRule = ();
|
||||
type Error = SelectorParseError<'i, StyleParseError<'i>>;
|
||||
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
|
||||
}
|
||||
|
||||
impl<'a, 'i, R: ParseErrorReporter> AtRuleParser<'i> for FontFeatureValuesRuleParser<'a, R> {
|
||||
type PreludeNoBlock = ();
|
||||
type PreludeBlock = BlockType;
|
||||
type AtRule = ();
|
||||
type Error = SelectorParseError<'i, StyleParseError<'i>>;
|
||||
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
|
||||
|
||||
fn parse_prelude<'t>(&mut self,
|
||||
name: CowRcStr<'i>,
|
||||
_input: &mut Parser<'i, 't>)
|
||||
input: &mut Parser<'i, 't>)
|
||||
-> Result<AtRuleType<(), BlockType>, ParseError<'i>> {
|
||||
match_ignore_ascii_case! { &*name,
|
||||
$(
|
||||
$name => Ok(AtRuleType::WithBlock(BlockType::$ident_camel)),
|
||||
)*
|
||||
_ => Err(BasicParseError::AtRuleBodyInvalid.into()),
|
||||
_ => Err(input.new_error(BasicParseErrorKind::AtRuleBodyInvalid)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -425,9 +429,10 @@ macro_rules! font_feature_values_blocks {
|
|||
|
||||
let mut iter = DeclarationListParser::new(input, parser);
|
||||
while let Some(declaration) = iter.next() {
|
||||
if let Err(err) = declaration {
|
||||
if let Err((error, slice)) = declaration {
|
||||
let error = ContextualParseError::UnsupportedKeyframePropertyDeclaration(
|
||||
err.slice, err.error);
|
||||
slice, error
|
||||
);
|
||||
let location = iter.input.current_source_location();
|
||||
self.context.log_css_error(self.error_context, location, error);
|
||||
}
|
||||
|
|
|
@ -12,12 +12,12 @@ use properties::{Importance, PropertyDeclaration, PropertyDeclarationBlock, Prop
|
|||
use properties::{PropertyDeclarationId, LonghandId, SourcePropertyDeclaration};
|
||||
use properties::LonghandIdSet;
|
||||
use properties::longhands::transition_timing_function::single_value::SpecifiedValue as SpecifiedTimingFunction;
|
||||
use selectors::parser::SelectorParseError;
|
||||
use selectors::parser::SelectorParseErrorKind;
|
||||
use servo_arc::Arc;
|
||||
use shared_lock::{DeepCloneParams, DeepCloneWithLock, SharedRwLock, SharedRwLockReadGuard, Locked, ToCssWithGuard};
|
||||
use std::fmt;
|
||||
use style_traits::{PARSING_MODE_DEFAULT, ToCss, ParseError, StyleParseError};
|
||||
use style_traits::PropertyDeclarationParseError;
|
||||
use style_traits::{PARSING_MODE_DEFAULT, ToCss, ParseError, StyleParseErrorKind};
|
||||
use style_traits::PropertyDeclarationParseErrorKind;
|
||||
use stylesheets::{CssRuleType, StylesheetContents};
|
||||
use stylesheets::rule_parser::VendorPrefix;
|
||||
use values::{KeyframesName, serialize_percentage};
|
||||
|
@ -137,7 +137,7 @@ impl KeyframePercentage {
|
|||
if percentage >= 0. && percentage <= 1. {
|
||||
KeyframePercentage::new(percentage)
|
||||
} else {
|
||||
return Err(StyleParseError::UnspecifiedError.into());
|
||||
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -500,7 +500,7 @@ impl<'a, 'i, R> AtRuleParser<'i> for KeyframeListParser<'a, R> {
|
|||
type PreludeNoBlock = ();
|
||||
type PreludeBlock = ();
|
||||
type AtRule = Arc<Locked<Keyframe>>;
|
||||
type Error = SelectorParseError<'i, StyleParseError<'i>>;
|
||||
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
|
||||
}
|
||||
|
||||
/// A wrapper to wraps the KeyframeSelector with its source location
|
||||
|
@ -512,7 +512,7 @@ struct KeyframeSelectorParserPrelude {
|
|||
impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for KeyframeListParser<'a, R> {
|
||||
type Prelude = KeyframeSelectorParserPrelude;
|
||||
type QualifiedRule = Arc<Locked<Keyframe>>;
|
||||
type Error = SelectorParseError<'i, StyleParseError<'i>>;
|
||||
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
|
||||
|
||||
fn parse_prelude<'t>(&mut self, input: &mut Parser<'i, 't>) -> Result<Self::Prelude, ParseError<'i>> {
|
||||
let start_position = input.position();
|
||||
|
@ -552,9 +552,9 @@ impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for KeyframeListPars
|
|||
Ok(()) => {
|
||||
block.extend(iter.parser.declarations.drain(), Importance::Normal);
|
||||
}
|
||||
Err(err) => {
|
||||
Err((error, slice)) => {
|
||||
iter.parser.declarations.clear();
|
||||
let error = ContextualParseError::UnsupportedKeyframePropertyDeclaration(err.slice, err.error);
|
||||
let error = ContextualParseError::UnsupportedKeyframePropertyDeclaration(slice, error);
|
||||
context.log_css_error(self.error_context, iter.input.current_source_location(), error);
|
||||
}
|
||||
}
|
||||
|
@ -578,25 +578,26 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for KeyframeDeclarationParser<'a, 'b> {
|
|||
type PreludeNoBlock = ();
|
||||
type PreludeBlock = ();
|
||||
type AtRule = ();
|
||||
type Error = SelectorParseError<'i, StyleParseError<'i>>;
|
||||
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'i> DeclarationParser<'i> for KeyframeDeclarationParser<'a, 'b> {
|
||||
type Declaration = ();
|
||||
type Error = SelectorParseError<'i, StyleParseError<'i>>;
|
||||
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
|
||||
|
||||
fn parse_value<'t>(&mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>)
|
||||
-> Result<(), ParseError<'i>> {
|
||||
let property_context = PropertyParserContext::new(self.context);
|
||||
|
||||
let id = PropertyId::parse(&name, Some(&property_context))
|
||||
.map_err(|()| PropertyDeclarationParseError::UnknownProperty(name.clone()))?;
|
||||
let id = PropertyId::parse(&name, Some(&property_context)).map_err(|()| {
|
||||
input.new_custom_error(PropertyDeclarationParseErrorKind::UnknownProperty(name.clone()))
|
||||
})?;
|
||||
match PropertyDeclaration::parse_into(self.declarations, id, name, self.context, input) {
|
||||
Ok(()) => {
|
||||
// In case there is still unparsed text in the declaration, we should roll back.
|
||||
input.expect_exhausted().map_err(|e| e.into())
|
||||
}
|
||||
Err(_e) => Err(StyleParseError::UnspecifiedError.into())
|
||||
Err(e) => Err(e.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ use {Namespace, Prefix};
|
|||
use computed_values::font_family::FamilyName;
|
||||
use counter_style::{parse_counter_style_body, parse_counter_style_name};
|
||||
use cssparser::{AtRuleParser, AtRuleType, Parser, QualifiedRuleParser, RuleListParser};
|
||||
use cssparser::{CowRcStr, SourceLocation, BasicParseError};
|
||||
use cssparser::{CowRcStr, SourceLocation, BasicParseError, BasicParseErrorKind};
|
||||
use error_reporting::{ContextualParseError, ParseErrorReporter};
|
||||
use font_face::parse_font_face_block;
|
||||
use media_queries::{parse_media_query_list, MediaList};
|
||||
|
@ -16,11 +16,11 @@ use parser::{Parse, ParserContext, ParserErrorContext};
|
|||
use properties::parse_property_declaration_list;
|
||||
use selector_parser::{SelectorImpl, SelectorParser};
|
||||
use selectors::SelectorList;
|
||||
use selectors::parser::SelectorParseError;
|
||||
use selectors::parser::SelectorParseErrorKind;
|
||||
use servo_arc::Arc;
|
||||
use shared_lock::{Locked, SharedRwLock};
|
||||
use str::starts_with_ignore_ascii_case;
|
||||
use style_traits::{StyleParseError, ParseError};
|
||||
use style_traits::{StyleParseErrorKind, ParseError};
|
||||
use stylesheets::{CssRule, CssRules, CssRuleType, Origin, StylesheetLoader};
|
||||
use stylesheets::{DocumentRule, FontFeatureValuesRule, KeyframesRule, MediaRule};
|
||||
use stylesheets::{NamespaceRule, PageRule, StyleRule, SupportsRule, ViewportRule};
|
||||
|
@ -160,7 +160,7 @@ impl<'a, 'i, R: ParseErrorReporter> AtRuleParser<'i> for TopLevelRuleParser<'a,
|
|||
type PreludeNoBlock = AtRuleNonBlockPrelude;
|
||||
type PreludeBlock = AtRuleBlockPrelude;
|
||||
type AtRule = CssRule;
|
||||
type Error = SelectorParseError<'i, StyleParseError<'i>>;
|
||||
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
|
||||
|
||||
fn parse_prelude<'t>(
|
||||
&mut self,
|
||||
|
@ -173,7 +173,7 @@ impl<'a, 'i, R: ParseErrorReporter> AtRuleParser<'i> for TopLevelRuleParser<'a,
|
|||
if self.state > State::Imports {
|
||||
// "@import must be before any rule but @charset"
|
||||
self.had_hierarchy_error = true;
|
||||
return Err(StyleParseError::UnexpectedImportRule.into())
|
||||
return Err(input.new_custom_error(StyleParseErrorKind::UnexpectedImportRule))
|
||||
}
|
||||
|
||||
let url_string = input.expect_url_or_string()?.as_ref().to_owned();
|
||||
|
@ -190,15 +190,16 @@ impl<'a, 'i, R: ParseErrorReporter> AtRuleParser<'i> for TopLevelRuleParser<'a,
|
|||
if self.state > State::Namespaces {
|
||||
// "@namespace must be before any rule but @charset and @import"
|
||||
self.had_hierarchy_error = true;
|
||||
return Err(StyleParseError::UnexpectedNamespaceRule.into())
|
||||
return Err(input.new_custom_error(StyleParseErrorKind::UnexpectedNamespaceRule))
|
||||
}
|
||||
|
||||
let prefix = input.try(|i| i.expect_ident_cloned())
|
||||
.map(|s| Prefix::from(s.as_ref())).ok();
|
||||
let maybe_namespace = match input.expect_url_or_string() {
|
||||
Ok(url_or_string) => url_or_string,
|
||||
Err(BasicParseError::UnexpectedToken(t)) =>
|
||||
return Err(StyleParseError::UnexpectedTokenWithinNamespace(t).into()),
|
||||
Err(BasicParseError { kind: BasicParseErrorKind::UnexpectedToken(t), location }) => {
|
||||
return Err(location.new_custom_error(StyleParseErrorKind::UnexpectedTokenWithinNamespace(t)))
|
||||
}
|
||||
Err(e) => return Err(e.into()),
|
||||
};
|
||||
let url = Namespace::from(maybe_namespace.as_ref());
|
||||
|
@ -209,7 +210,7 @@ impl<'a, 'i, R: ParseErrorReporter> AtRuleParser<'i> for TopLevelRuleParser<'a,
|
|||
// anything left is invalid.
|
||||
"charset" => {
|
||||
self.had_hierarchy_error = true;
|
||||
return Err(StyleParseError::UnexpectedCharsetRule.into())
|
||||
return Err(input.new_custom_error(StyleParseErrorKind::UnexpectedCharsetRule))
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
@ -279,7 +280,7 @@ pub struct QualifiedRuleParserPrelude {
|
|||
impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for TopLevelRuleParser<'a, R> {
|
||||
type Prelude = QualifiedRuleParserPrelude;
|
||||
type QualifiedRule = CssRule;
|
||||
type Error = SelectorParseError<'i, StyleParseError<'i>>;
|
||||
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
|
||||
|
||||
#[inline]
|
||||
fn parse_prelude<'t>(
|
||||
|
@ -331,8 +332,8 @@ impl<'a, 'b, R: ParseErrorReporter> NestedRuleParser<'a, 'b, R> {
|
|||
while let Some(result) = iter.next() {
|
||||
match result {
|
||||
Ok(rule) => rules.push(rule),
|
||||
Err(err) => {
|
||||
let error = ContextualParseError::UnsupportedRule(err.slice, err.error);
|
||||
Err((error, slice)) => {
|
||||
let error = ContextualParseError::UnsupportedRule(slice, error);
|
||||
let location = iter.input.current_source_location();
|
||||
self.context.log_css_error(self.error_context, location, error);
|
||||
}
|
||||
|
@ -346,7 +347,7 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a
|
|||
type PreludeNoBlock = AtRuleNonBlockPrelude;
|
||||
type PreludeBlock = AtRuleBlockPrelude;
|
||||
type AtRule = CssRule;
|
||||
type Error = SelectorParseError<'i, StyleParseError<'i>>;
|
||||
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
|
||||
|
||||
fn parse_prelude<'t>(
|
||||
&mut self,
|
||||
|
@ -372,7 +373,7 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a
|
|||
"font-feature-values" => {
|
||||
if !cfg!(feature = "gecko") {
|
||||
// Support for this rule is not fully implemented in Servo yet.
|
||||
return Err(StyleParseError::UnsupportedAtRule(name.clone()).into())
|
||||
return Err(input.new_custom_error(StyleParseErrorKind::UnsupportedAtRule(name.clone())))
|
||||
}
|
||||
let family_names = parse_family_name_list(self.context, input)?;
|
||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::FontFeatureValues(family_names, location)))
|
||||
|
@ -380,14 +381,14 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a
|
|||
"counter-style" => {
|
||||
if !cfg!(feature = "gecko") {
|
||||
// Support for this rule is not fully implemented in Servo yet.
|
||||
return Err(StyleParseError::UnsupportedAtRule(name.clone()).into())
|
||||
return Err(input.new_custom_error(StyleParseErrorKind::UnsupportedAtRule(name.clone())))
|
||||
}
|
||||
let name = parse_counter_style_name(input)?;
|
||||
// ASCII-case-insensitive matches for "decimal" and "disc".
|
||||
// The name is already lower-cased by `parse_counter_style_name`
|
||||
// so we can use == here.
|
||||
if name.0 == atom!("decimal") || name.0 == atom!("disc") {
|
||||
return Err(StyleParseError::UnspecifiedError.into())
|
||||
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||
}
|
||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::CounterStyle(name)))
|
||||
},
|
||||
|
@ -395,7 +396,7 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a
|
|||
if viewport_rule::enabled() {
|
||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Viewport))
|
||||
} else {
|
||||
Err(StyleParseError::UnsupportedAtRule(name.clone()).into())
|
||||
Err(input.new_custom_error(StyleParseErrorKind::UnsupportedAtRule(name.clone())))
|
||||
}
|
||||
},
|
||||
"keyframes" | "-webkit-keyframes" | "-moz-keyframes" => {
|
||||
|
@ -409,7 +410,7 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a
|
|||
if cfg!(feature = "servo") &&
|
||||
prefix.as_ref().map_or(false, |p| matches!(*p, VendorPrefix::Moz)) {
|
||||
// Servo should not support @-moz-keyframes.
|
||||
return Err(StyleParseError::UnsupportedAtRule(name.clone()).into())
|
||||
return Err(input.new_custom_error(StyleParseErrorKind::UnsupportedAtRule(name.clone())))
|
||||
}
|
||||
let name = KeyframesName::parse(self.context, input)?;
|
||||
|
||||
|
@ -419,7 +420,7 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a
|
|||
if cfg!(feature = "gecko") {
|
||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Page(location)))
|
||||
} else {
|
||||
Err(StyleParseError::UnsupportedAtRule(name.clone()).into())
|
||||
Err(input.new_custom_error(StyleParseErrorKind::UnsupportedAtRule(name.clone())))
|
||||
}
|
||||
},
|
||||
"-moz-document" => {
|
||||
|
@ -427,10 +428,10 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a
|
|||
let cond = DocumentCondition::parse(self.context, input)?;
|
||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Document(cond, location)))
|
||||
} else {
|
||||
Err(StyleParseError::UnsupportedAtRule(name.clone()).into())
|
||||
Err(input.new_custom_error(StyleParseErrorKind::UnsupportedAtRule(name.clone())))
|
||||
}
|
||||
},
|
||||
_ => Err(StyleParseError::UnsupportedAtRule(name.clone()).into())
|
||||
_ => Err(input.new_custom_error(StyleParseErrorKind::UnsupportedAtRule(name.clone())))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -549,7 +550,7 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a
|
|||
impl<'a, 'b, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for NestedRuleParser<'a, 'b, R> {
|
||||
type Prelude = QualifiedRuleParserPrelude;
|
||||
type QualifiedRule = CssRule;
|
||||
type Error = SelectorParseError<'i, StyleParseError<'i>>;
|
||||
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
|
||||
|
||||
fn parse_prelude<'t>(
|
||||
&mut self,
|
||||
|
|
|
@ -394,8 +394,8 @@ impl Stylesheet {
|
|||
break;
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
let error = ContextualParseError::InvalidRule(err.slice, err.error);
|
||||
Err((error, slice)) => {
|
||||
let error = ContextualParseError::InvalidRule(slice, error);
|
||||
let location = iter.input.current_source_location();
|
||||
iter.parser.context.log_css_error(&iter.parser.error_context,
|
||||
location, error);
|
||||
|
|
|
@ -4,17 +4,17 @@
|
|||
|
||||
//! [@supports rules](https://drafts.csswg.org/css-conditional-3/#at-supports)
|
||||
|
||||
use cssparser::{BasicParseError, ParseError as CssParseError, ParserInput};
|
||||
use cssparser::{Delimiter, parse_important, Parser, SourceLocation, Token};
|
||||
use cssparser::{ParseError as CssParseError, ParserInput};
|
||||
#[cfg(feature = "gecko")]
|
||||
use malloc_size_of::{MallocSizeOfOps, MallocUnconditionalShallowSizeOf};
|
||||
use parser::ParserContext;
|
||||
use properties::{PropertyId, PropertyDeclaration, PropertyParserContext, SourcePropertyDeclaration};
|
||||
use selectors::parser::SelectorParseError;
|
||||
use selectors::parser::SelectorParseErrorKind;
|
||||
use servo_arc::Arc;
|
||||
use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard};
|
||||
use std::fmt;
|
||||
use style_traits::{ToCss, ParseError, StyleParseError};
|
||||
use style_traits::{ToCss, ParseError};
|
||||
use stylesheets::{CssRuleType, CssRules};
|
||||
|
||||
/// An [`@supports`][supports] rule.
|
||||
|
@ -104,6 +104,7 @@ impl SupportsCondition {
|
|||
|
||||
let in_parens = SupportsCondition::parse_in_parens(input)?;
|
||||
|
||||
let location = input.current_source_location();
|
||||
let (keyword, wrapper) = match input.next() {
|
||||
Err(_) => {
|
||||
// End of input
|
||||
|
@ -113,10 +114,10 @@ impl SupportsCondition {
|
|||
match_ignore_ascii_case! { &ident,
|
||||
"and" => ("and", SupportsCondition::And as fn(_) -> _),
|
||||
"or" => ("or", SupportsCondition::Or as fn(_) -> _),
|
||||
_ => return Err(SelectorParseError::UnexpectedIdent(ident.clone()).into())
|
||||
_ => return Err(location.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone())))
|
||||
}
|
||||
}
|
||||
Ok(t) => return Err(CssParseError::Basic(BasicParseError::UnexpectedToken(t.clone())))
|
||||
Ok(t) => return Err(location.new_unexpected_token_error(t.clone()))
|
||||
};
|
||||
|
||||
let mut conditions = Vec::with_capacity(2);
|
||||
|
@ -138,6 +139,7 @@ impl SupportsCondition {
|
|||
// but we want to not include it in `pos` for the SupportsCondition::FutureSyntax cases.
|
||||
while input.try(Parser::expect_whitespace).is_ok() {}
|
||||
let pos = input.position();
|
||||
let location = input.current_source_location();
|
||||
// FIXME: remove clone() when lifetimes are non-lexical
|
||||
match input.next()?.clone() {
|
||||
Token::ParenthesisBlock => {
|
||||
|
@ -149,7 +151,7 @@ impl SupportsCondition {
|
|||
}
|
||||
}
|
||||
Token::Function(_) => {}
|
||||
t => return Err(CssParseError::Basic(BasicParseError::UnexpectedToken(t))),
|
||||
t => return Err(location.new_unexpected_token_error(t)),
|
||||
}
|
||||
input.parse_nested_block(|i| consume_any_value(i))?;
|
||||
Ok(SupportsCondition::FutureSyntax(input.slice_from(pos).to_owned()))
|
||||
|
@ -258,18 +260,18 @@ impl Declaration {
|
|||
|
||||
let mut input = ParserInput::new(&self.0);
|
||||
let mut input = Parser::new(&mut input);
|
||||
input.parse_entirely(|input| {
|
||||
input.parse_entirely(|input| -> Result<(), CssParseError<()>> {
|
||||
let prop = input.expect_ident().unwrap().as_ref().to_owned();
|
||||
input.expect_colon().unwrap();
|
||||
|
||||
let property_context = PropertyParserContext::new(&context);
|
||||
let id = PropertyId::parse(&prop, Some(&property_context))
|
||||
.map_err(|_| StyleParseError::UnspecifiedError)?;
|
||||
.map_err(|()| input.new_custom_error(()))?;
|
||||
|
||||
let mut declarations = SourcePropertyDeclaration::new();
|
||||
input.parse_until_before(Delimiter::Bang, |input| {
|
||||
PropertyDeclaration::parse_into(&mut declarations, id, prop.into(), &context, input)
|
||||
.map_err(|e| StyleParseError::PropertyDeclaration(e).into())
|
||||
.map_err(|_| input.new_custom_error(()))
|
||||
})?;
|
||||
let _ = input.try(parse_important);
|
||||
Ok(())
|
||||
|
|
|
@ -18,7 +18,7 @@ use media_queries::Device;
|
|||
use parser::{ParserContext, ParserErrorContext};
|
||||
use properties::StyleBuilder;
|
||||
use rule_cache::RuleCacheConditions;
|
||||
use selectors::parser::SelectorParseError;
|
||||
use selectors::parser::SelectorParseErrorKind;
|
||||
use shared_lock::{SharedRwLockReadGuard, StylesheetGuards, ToCssWithGuard};
|
||||
use std::ascii::AsciiExt;
|
||||
use std::borrow::Cow;
|
||||
|
@ -26,7 +26,7 @@ use std::cell::RefCell;
|
|||
use std::fmt;
|
||||
use std::iter::Enumerate;
|
||||
use std::str::Chars;
|
||||
use style_traits::{PinchZoomFactor, ToCss, ParseError, StyleParseError};
|
||||
use style_traits::{PinchZoomFactor, ToCss, ParseError, StyleParseErrorKind};
|
||||
use style_traits::viewport::{Orientation, UserZoom, ViewportConstraints, Zoom};
|
||||
use stylesheets::{StylesheetInDocument, Origin};
|
||||
use values::computed::{Context, ToComputedValue};
|
||||
|
@ -276,12 +276,12 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for ViewportRuleParser<'a, 'b> {
|
|||
type PreludeNoBlock = ();
|
||||
type PreludeBlock = ();
|
||||
type AtRule = Vec<ViewportDescriptorDeclaration>;
|
||||
type Error = SelectorParseError<'i, StyleParseError<'i>>;
|
||||
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'i> DeclarationParser<'i> for ViewportRuleParser<'a, 'b> {
|
||||
type Declaration = Vec<ViewportDescriptorDeclaration>;
|
||||
type Error = SelectorParseError<'i, StyleParseError<'i>>;
|
||||
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
|
||||
|
||||
fn parse_value<'t>(&mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>)
|
||||
-> Result<Vec<ViewportDescriptorDeclaration>, ParseError<'i>> {
|
||||
|
@ -323,7 +323,7 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for ViewportRuleParser<'a, 'b> {
|
|||
"max-zoom" => ok!(MaxZoom(Zoom::parse)),
|
||||
"user-zoom" => ok!(UserZoom(UserZoom::parse)),
|
||||
"orientation" => ok!(Orientation(Orientation::parse)),
|
||||
_ => Err(SelectorParseError::UnexpectedIdent(name.clone()).into()),
|
||||
_ => Err(input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(name.clone()))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -368,8 +368,8 @@ impl ViewportRule {
|
|||
cascade.add(Cow::Owned(declarations))
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
let error = ContextualParseError::UnsupportedViewportDescriptorDeclaration(err.slice, err.error);
|
||||
Err((error, slice)) => {
|
||||
let error = ContextualParseError::UnsupportedViewportDescriptorDeclaration(slice, error);
|
||||
context.log_css_error(error_context, parser.input.current_source_location(), error);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue