Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the current parser location for CSS error #18585

Closed
wants to merge 9 commits into from

CSS parsing error types: flatten nested enums somewhat

  • Loading branch information
SimonSapin committed Oct 10, 2017
commit 46ea99d54b0c7c2ece0aec961756e9f01d050cfc

Large diffs are not rendered by default.

@@ -119,7 +119,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for CounterStyleRuleParser<'a, 'b> {
type PreludeNoBlock = ();
type PreludeBlock = ();
type AtRule = ();
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
type Error = StyleParseErrorKind<'i>;
}

macro_rules! accessor {
@@ -188,7 +188,7 @@ macro_rules! counter_style_descriptors {

impl<'a, 'b, 'i> DeclarationParser<'i> for CounterStyleRuleParser<'a, 'b> {
type Declaration = ();
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
type Error = StyleParseErrorKind<'i>;

fn parse_value<'t>(&mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>)
-> Result<(), ParseError<'i>> {
@@ -187,7 +187,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for FontFaceRuleParser<'a, 'b> {
type PreludeNoBlock = ();
type PreludeBlock = ();
type AtRule = ();
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
type Error = StyleParseErrorKind<'i>;
}

impl Parse for Source {
@@ -288,7 +288,7 @@ macro_rules! font_face_descriptors_common {

impl<'a, 'b, 'i> DeclarationParser<'i> for FontFaceRuleParser<'a, 'b> {
type Declaration = ();
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
type Error = StyleParseErrorKind<'i>;

fn parse_value<'t>(&mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>)
-> Result<(), ParseError<'i>> {
@@ -13,7 +13,6 @@ use custom_properties::CustomPropertiesBuilder;
use error_reporting::{ParseErrorReporter, ContextualParseError};
use parser::{ParserContext, ParserErrorContext};
use properties::animated_properties::AnimationValue;
use selectors::parser::SelectorParseErrorKind;
use shared_lock::Locked;
use smallbitvec::{self, SmallBitVec};
use smallvec::SmallVec;
@@ -1060,7 +1059,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for PropertyDeclarationParser<'a, 'b> {
type PreludeNoBlock = ();
type PreludeBlock = ();
type AtRule = Importance;
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
type Error = StyleParseErrorKind<'i>;
}

/// Based on NonMozillaVendorIdentifier from Gecko's CSS parser.
@@ -1071,7 +1070,7 @@ fn is_non_mozilla_vendor_identifier(name: &str) -> bool {

impl<'a, 'b, 'i> DeclarationParser<'i> for PropertyDeclarationParser<'a, 'b> {
type Declaration = Importance;
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
type Error = StyleParseErrorKind<'i>;

fn parse_value<'t>(&mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>)
-> Result<Importance, ParseError<'i>> {
@@ -1126,9 +1125,9 @@ pub fn parse_property_declaration_list<R>(context: &ParserContext,

// If the unrecognized property looks like a vendor-specific property,
// silently ignore it instead of polluting the error output.
if let ParseErrorKind::Custom(SelectorParseErrorKind::Custom(
if let ParseErrorKind::Custom(
StyleParseErrorKind::PropertyDeclaration(
PropertyDeclarationParseErrorKind::UnknownVendorProperty))) = error.kind {
PropertyDeclarationParseErrorKind::UnknownVendorProperty)) = error.kind {
continue;
}

@@ -16,7 +16,6 @@ use gecko_bindings::bindings::Gecko_AppendFeatureValueHashEntry;
#[cfg(feature = "gecko")]
use gecko_bindings::structs::{self, gfxFontFeatureValueSet, nsTArray};
use parser::{ParserContext, ParserErrorContext, Parse};
use selectors::parser::SelectorParseErrorKind;
use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard};
use std::fmt;
use style_traits::{ParseError, StyleParseErrorKind, ToCss};
@@ -201,14 +200,14 @@ impl<'a, 'b, 'i, T> AtRuleParser<'i> for FFVDeclarationsParser<'a, 'b, T> {
type PreludeNoBlock = ();
type PreludeBlock = ();
type AtRule = ();
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
type Error = StyleParseErrorKind<'i>;
}

impl<'a, 'b, 'i, T> DeclarationParser<'i> for FFVDeclarationsParser<'a, 'b, T>
where T: Parse
{
type Declaration = ();
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
type Error = StyleParseErrorKind<'i>;

fn parse_value<'t>(&mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>)
-> Result<(), ParseError<'i>> {
@@ -392,14 +391,14 @@ macro_rules! font_feature_values_blocks {
impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for FontFeatureValuesRuleParser<'a, R> {
type Prelude = ();
type QualifiedRule = ();
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
type Error = StyleParseErrorKind<'i>;
}

impl<'a, 'i, R: ParseErrorReporter> AtRuleParser<'i> for FontFeatureValuesRuleParser<'a, R> {
type PreludeNoBlock = ();
type PreludeBlock = BlockType;
type AtRule = ();
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
type Error = StyleParseErrorKind<'i>;

fn parse_prelude<'t>(&mut self,
name: CowRcStr<'i>,
@@ -12,7 +12,6 @@ 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::SelectorParseErrorKind;
use servo_arc::Arc;
use shared_lock::{DeepCloneParams, DeepCloneWithLock, SharedRwLock, SharedRwLockReadGuard, Locked, ToCssWithGuard};
use std::fmt;
@@ -500,7 +499,7 @@ impl<'a, 'i, R> AtRuleParser<'i> for KeyframeListParser<'a, R> {
type PreludeNoBlock = ();
type PreludeBlock = ();
type AtRule = Arc<Locked<Keyframe>>;
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
type Error = StyleParseErrorKind<'i>;
}

/// A wrapper to wraps the KeyframeSelector with its source location
@@ -512,7 +511,7 @@ struct KeyframeSelectorParserPrelude {
impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for KeyframeListParser<'a, R> {
type Prelude = KeyframeSelectorParserPrelude;
type QualifiedRule = Arc<Locked<Keyframe>>;
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
type Error = StyleParseErrorKind<'i>;

fn parse_prelude<'t>(&mut self, input: &mut Parser<'i, 't>) -> Result<Self::Prelude, ParseError<'i>> {
let start_position = input.position();
@@ -580,12 +579,12 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for KeyframeDeclarationParser<'a, 'b> {
type PreludeNoBlock = ();
type PreludeBlock = ();
type AtRule = ();
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
type Error = StyleParseErrorKind<'i>;
}

impl<'a, 'b, 'i> DeclarationParser<'i> for KeyframeDeclarationParser<'a, 'b> {
type Declaration = ();
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
type Error = StyleParseErrorKind<'i>;

fn parse_value<'t>(&mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>)
-> Result<(), ParseError<'i>> {
@@ -16,7 +16,6 @@ use parser::{Parse, ParserContext, ParserErrorContext};
use properties::parse_property_declaration_list;
use selector_parser::{SelectorImpl, SelectorParser};
use selectors::SelectorList;
use selectors::parser::SelectorParseErrorKind;
use servo_arc::Arc;
use shared_lock::{Locked, SharedRwLock};
use str::starts_with_ignore_ascii_case;
@@ -160,7 +159,7 @@ impl<'a, 'i, R: ParseErrorReporter> AtRuleParser<'i> for TopLevelRuleParser<'a,
type PreludeNoBlock = AtRuleNonBlockPrelude;
type PreludeBlock = AtRuleBlockPrelude;
type AtRule = CssRule;
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
type Error = StyleParseErrorKind<'i>;

fn parse_prelude<'t>(
&mut self,
@@ -280,7 +279,7 @@ pub struct QualifiedRuleParserPrelude {
impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for TopLevelRuleParser<'a, R> {
type Prelude = QualifiedRuleParserPrelude;
type QualifiedRule = CssRule;
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
type Error = StyleParseErrorKind<'i>;

#[inline]
fn parse_prelude<'t>(
@@ -347,7 +346,7 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a
type PreludeNoBlock = AtRuleNonBlockPrelude;
type PreludeBlock = AtRuleBlockPrelude;
type AtRule = CssRule;
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
type Error = StyleParseErrorKind<'i>;

fn parse_prelude<'t>(
&mut self,
@@ -550,7 +549,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 = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
type Error = StyleParseErrorKind<'i>;

fn parse_prelude<'t>(
&mut self,
@@ -276,12 +276,12 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for ViewportRuleParser<'a, 'b> {
type PreludeNoBlock = ();
type PreludeBlock = ();
type AtRule = Vec<ViewportDescriptorDeclaration>;
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
type Error = StyleParseErrorKind<'i>;
}

impl<'a, 'b, 'i> DeclarationParser<'i> for ViewportRuleParser<'a, 'b> {
type Declaration = Vec<ViewportDescriptorDeclaration>;
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>;
type Error = StyleParseErrorKind<'i>;

fn parse_value<'t>(&mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>)
-> Result<Vec<ViewportDescriptorDeclaration>, ParseError<'i>> {
@@ -85,10 +85,7 @@ 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, SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>>;

/// Error emitted by the style crate
pub type StyleParseError<'i> = cssparser::ParseError<'i, StyleParseErrorKind<'i>>;
pub type ParseError<'i> = cssparser::ParseError<'i, StyleParseErrorKind<'i>>;

/// Error in property value parsing
pub type ValueParseError<'i> = cssparser::ParseError<'i, ValueParseErrorKind<'i>>;
@@ -139,17 +136,25 @@ pub enum StyleParseErrorKind<'i> {
UnexpectedTokenWithinNamespace(Token<'i>),
/// An error was encountered while parsing a property value.
ValueError(ValueParseErrorKind<'i>),
/// An error was encountered while parsing a selector
SelectorError(SelectorParseErrorKind<'i>),
}

impl<'i> From<ValueParseErrorKind<'i>> for SelectorParseErrorKind<'i, StyleParseErrorKind<'i>> {
impl<'i> From<ValueParseErrorKind<'i>> for StyleParseErrorKind<'i> {
fn from(this: ValueParseErrorKind<'i>) -> Self {
StyleParseErrorKind::ValueError(this).into()
StyleParseErrorKind::ValueError(this)
}
}

impl<'i> From<SelectorParseErrorKind<'i>> for StyleParseErrorKind<'i> {
fn from(this: SelectorParseErrorKind<'i>) -> Self {
StyleParseErrorKind::SelectorError(this)
}
}

impl<'i> From<PropertyDeclarationParseErrorKind<'i>> for SelectorParseErrorKind<'i, StyleParseErrorKind<'i>> {
impl<'i> From<PropertyDeclarationParseErrorKind<'i>> for StyleParseErrorKind<'i> {
fn from(this: PropertyDeclarationParseErrorKind<'i>) -> Self {
StyleParseErrorKind::PropertyDeclaration(this).into()
StyleParseErrorKind::PropertyDeclaration(this)
}
}

@@ -189,11 +194,7 @@ impl<'i> PropertyDeclarationParseErrorKind<'i> {
kind: cssparser::ParseErrorKind::Custom(PropertyDeclarationParseErrorKind::InvalidValue(
name,
match value_error.kind {
cssparser::ParseErrorKind::Custom(
SelectorParseErrorKind::Custom(
StyleParseErrorKind::ValueError(e)
)
) => Some(e),
cssparser::ParseErrorKind::Custom(StyleParseErrorKind::ValueError(e)) => Some(e),
_ => None,
}
)),
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.