CSS parsing error types: flatten nested enums somewhat

This commit is contained in:
Simon Sapin 2017-10-09 17:20:52 +02:00
parent c64374bc58
commit 46ea99d54b
11 changed files with 242 additions and 228 deletions

View file

@ -47,10 +47,10 @@ fn to_ascii_lowercase(s: &str) -> Cow<str> {
} }
} }
pub type SelectorParseError<'i, E> = ParseError<'i, SelectorParseErrorKind<'i, E>>; pub type SelectorParseError<'i> = ParseError<'i, SelectorParseErrorKind<'i>>;
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub enum SelectorParseErrorKind<'i, E> { pub enum SelectorParseErrorKind<'i> {
PseudoElementInComplexSelector, PseudoElementInComplexSelector,
NoQualifiedNameInAttributeSelector(Token<'i>), NoQualifiedNameInAttributeSelector(Token<'i>),
EmptySelector, EmptySelector,
@ -69,13 +69,6 @@ pub enum SelectorParseErrorKind<'i, E> {
ExplicitNamespaceUnexpectedToken(Token<'i>), ExplicitNamespaceUnexpectedToken(Token<'i>),
ClassNeedsIdent(Token<'i>), ClassNeedsIdent(Token<'i>),
EmptyNegation, EmptyNegation,
Custom(E),
}
impl<'i, E> From<E> for SelectorParseErrorKind<'i, E> {
fn from(custom: E) -> Self {
SelectorParseErrorKind::Custom(custom)
}
} }
macro_rules! with_all_bounds { macro_rules! with_all_bounds {
@ -131,7 +124,7 @@ with_bounds! {
pub trait Parser<'i> { pub trait Parser<'i> {
type Impl: SelectorImpl; type Impl: SelectorImpl;
type Error: 'i; type Error: 'i + From<SelectorParseErrorKind<'i>>;
/// Whether the name is a pseudo-element that can be specified with /// Whether the name is a pseudo-element that can be specified with
/// the single colon syntax in addition to the double-colon syntax. /// the single colon syntax in addition to the double-colon syntax.
@ -143,28 +136,29 @@ pub trait Parser<'i> {
/// pseudo-elements. /// pseudo-elements.
fn parse_non_ts_pseudo_class(&self, location: SourceLocation, name: CowRcStr<'i>) fn parse_non_ts_pseudo_class(&self, location: SourceLocation, name: CowRcStr<'i>)
-> Result<<Self::Impl as SelectorImpl>::NonTSPseudoClass, -> Result<<Self::Impl as SelectorImpl>::NonTSPseudoClass,
SelectorParseError<'i, Self::Error>> { ParseError<'i, Self::Error>>
{
Err(location.new_custom_error(SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name))) Err(location.new_custom_error(SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name)))
} }
fn parse_non_ts_functional_pseudo_class<'t> fn parse_non_ts_functional_pseudo_class<'t>
(&self, name: CowRcStr<'i>, arguments: &mut CssParser<'i, 't>) (&self, name: CowRcStr<'i>, arguments: &mut CssParser<'i, 't>)
-> Result<<Self::Impl as SelectorImpl>::NonTSPseudoClass, -> Result<<Self::Impl as SelectorImpl>::NonTSPseudoClass, ParseError<'i, Self::Error>>
SelectorParseError<'i, Self::Error>>
{ {
Err(arguments.new_custom_error(SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name))) Err(arguments.new_custom_error(SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name)))
} }
fn parse_pseudo_element(&self, location: SourceLocation, name: CowRcStr<'i>) fn parse_pseudo_element(&self, location: SourceLocation, name: CowRcStr<'i>)
-> Result<<Self::Impl as SelectorImpl>::PseudoElement, -> Result<<Self::Impl as SelectorImpl>::PseudoElement,
SelectorParseError<'i, Self::Error>> { ParseError<'i, Self::Error>>
{
Err(location.new_custom_error(SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name))) Err(location.new_custom_error(SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name)))
} }
fn parse_functional_pseudo_element<'t> fn parse_functional_pseudo_element<'t>
(&self, name: CowRcStr<'i>, arguments: &mut CssParser<'i, 't>) (&self, name: CowRcStr<'i>, arguments: &mut CssParser<'i, 't>)
-> Result<<Self::Impl as SelectorImpl>::PseudoElement, -> Result<<Self::Impl as SelectorImpl>::PseudoElement, ParseError<'i, Self::Error>>
SelectorParseError<'i, Self::Error>> { {
Err(arguments.new_custom_error(SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name))) Err(arguments.new_custom_error(SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name)))
} }
@ -186,9 +180,9 @@ impl<Impl: SelectorImpl> SelectorList<Impl> {
/// https://drafts.csswg.org/selectors/#grouping /// https://drafts.csswg.org/selectors/#grouping
/// ///
/// Return the Selectors or Err if there is an invalid selector. /// Return the Selectors or Err if there is an invalid selector.
pub fn parse<'i, 't, P, E>(parser: &P, input: &mut CssParser<'i, 't>) pub fn parse<'i, 't, P>(parser: &P, input: &mut CssParser<'i, 't>)
-> Result<Self, SelectorParseError<'i, E>> -> Result<Self, ParseError<'i, P::Error>>
where P: Parser<'i, Impl=Impl, Error=E> { where P: Parser<'i, Impl=Impl> {
let mut values = SmallVec::new(); let mut values = SmallVec::new();
loop { loop {
values.push(input.parse_until_before(Delimiter::Comma, |input| parse_selector(parser, input))?); values.push(input.parse_until_before(Delimiter::Comma, |input| parse_selector(parser, input))?);
@ -1055,25 +1049,28 @@ fn display_to_css_identifier<T: Display, W: fmt::Write>(x: &T, dest: &mut W) ->
/// selector : simple_selector_sequence [ combinator simple_selector_sequence ]* ; /// selector : simple_selector_sequence [ combinator simple_selector_sequence ]* ;
/// ///
/// `Err` means invalid selector. /// `Err` means invalid selector.
fn parse_selector<'i, 't, P, E, Impl>( fn parse_selector<'i, 't, P, Impl>(
parser: &P, parser: &P,
input: &mut CssParser<'i, 't>) input: &mut CssParser<'i, 't>)
-> Result<Selector<Impl>, SelectorParseError<'i, E>> -> Result<Selector<Impl>, ParseError<'i, P::Error>>
where P: Parser<'i, Impl=Impl, Error=E>, Impl: SelectorImpl where P: Parser<'i, Impl=Impl>, Impl: SelectorImpl
{ {
let mut builder = SelectorBuilder::default(); let mut builder = SelectorBuilder::default();
let mut parsed_pseudo_element; let mut has_pseudo_element;
'outer_loop: loop { 'outer_loop: loop {
// Parse a sequence of simple selectors. // Parse a sequence of simple selectors.
parsed_pseudo_element = match parse_compound_selector(parser, input, &mut builder) { has_pseudo_element = match parse_compound_selector(parser, input, &mut builder)? {
Ok(result) => result, Some(has_pseudo_element) => has_pseudo_element,
Err(ParseError { kind: ParseErrorKind::Custom(SelectorParseErrorKind::EmptySelector), .. }) None => {
if builder.has_combinators() => return Err(input.new_custom_error(if builder.has_combinators() {
return Err(input.new_custom_error(SelectorParseErrorKind::DanglingCombinator)), SelectorParseErrorKind::DanglingCombinator
Err(e) => return Err(e), } else {
SelectorParseErrorKind::EmptySelector
}))
}
}; };
if parsed_pseudo_element { if has_pseudo_element {
break; break;
} }
@ -1111,14 +1108,14 @@ fn parse_selector<'i, 't, P, E, Impl>(
builder.push_combinator(combinator); builder.push_combinator(combinator);
} }
Ok(Selector(builder.build(parsed_pseudo_element))) Ok(Selector(builder.build(has_pseudo_element)))
} }
impl<Impl: SelectorImpl> Selector<Impl> { impl<Impl: SelectorImpl> Selector<Impl> {
/// Parse a selector, without any pseudo-element. /// Parse a selector, without any pseudo-element.
pub fn parse<'i, 't, P, E>(parser: &P, input: &mut CssParser<'i, 't>) pub fn parse<'i, 't, P>(parser: &P, input: &mut CssParser<'i, 't>)
-> Result<Self, SelectorParseError<'i, E>> -> Result<Self, ParseError<'i, P::Error>>
where P: Parser<'i, Impl=Impl, Error=E> where P: Parser<'i, Impl=Impl>
{ {
let selector = parse_selector(parser, input)?; let selector = parse_selector(parser, input)?;
if selector.has_pseudo_element() { if selector.has_pseudo_element() {
@ -1131,9 +1128,9 @@ impl<Impl: SelectorImpl> Selector<Impl> {
/// * `Err(())`: Invalid selector, abort /// * `Err(())`: Invalid selector, abort
/// * `Ok(false)`: Not a type selector, could be something else. `input` was not consumed. /// * `Ok(false)`: Not a type selector, could be something else. `input` was not consumed.
/// * `Ok(true)`: Length 0 (`*|*`), 1 (`*|E` or `ns|*`) or 2 (`|E` or `ns|E`) /// * `Ok(true)`: Length 0 (`*|*`), 1 (`*|E` or `ns|*`) or 2 (`|E` or `ns|E`)
fn parse_type_selector<'i, 't, P, E, Impl, S>(parser: &P, input: &mut CssParser<'i, 't>, sink: &mut S) fn parse_type_selector<'i, 't, P, Impl, S>(parser: &P, input: &mut CssParser<'i, 't>, sink: &mut S)
-> Result<bool, SelectorParseError<'i, E>> -> Result<bool, ParseError<'i, P::Error>>
where P: Parser<'i, Impl=Impl, Error=E>, where P: Parser<'i, Impl=Impl>,
Impl: SelectorImpl, Impl: SelectorImpl,
S: Push<Component<Impl>>, S: Push<Component<Impl>>,
{ {
@ -1218,11 +1215,11 @@ enum OptionalQName<'i, Impl: SelectorImpl> {
/// * `Ok(None(token))`: Not a simple selector, could be something else. `input` was not consumed, /// * `Ok(None(token))`: Not a simple selector, could be something else. `input` was not consumed,
/// but the token is still returned. /// but the token is still returned.
/// * `Ok(Some(namespace, local_name))`: `None` for the local name means a `*` universal selector /// * `Ok(Some(namespace, local_name))`: `None` for the local name means a `*` universal selector
fn parse_qualified_name<'i, 't, P, E, Impl> fn parse_qualified_name<'i, 't, P, Impl>
(parser: &P, input: &mut CssParser<'i, 't>, (parser: &P, input: &mut CssParser<'i, 't>,
in_attr_selector: bool) in_attr_selector: bool)
-> Result<OptionalQName<'i, Impl>, SelectorParseError<'i, E>> -> Result<OptionalQName<'i, Impl>, ParseError<'i, P::Error>>
where P: Parser<'i, Impl=Impl, Error=E>, Impl: SelectorImpl where P: Parser<'i, Impl=Impl>, Impl: SelectorImpl
{ {
let default_namespace = |local_name| { let default_namespace = |local_name| {
let namespace = match parser.default_namespace() { let namespace = match parser.default_namespace() {
@ -1315,9 +1312,9 @@ fn parse_qualified_name<'i, 't, P, E, Impl>
} }
fn parse_attribute_selector<'i, 't, P, E, Impl>(parser: &P, input: &mut CssParser<'i, 't>) fn parse_attribute_selector<'i, 't, P, Impl>(parser: &P, input: &mut CssParser<'i, 't>)
-> Result<Component<Impl>, SelectorParseError<'i, E>> -> Result<Component<Impl>, ParseError<'i, P::Error>>
where P: Parser<'i, Impl=Impl, Error=E>, Impl: SelectorImpl where P: Parser<'i, Impl=Impl>, Impl: SelectorImpl
{ {
let namespace; let namespace;
let local_name; let local_name;
@ -1451,8 +1448,9 @@ fn parse_attribute_selector<'i, 't, P, E, Impl>(parser: &P, input: &mut CssParse
} }
fn parse_attribute_flags<'i, 't, E>(input: &mut CssParser<'i, 't>) fn parse_attribute_flags<'i, 't>(input: &mut CssParser<'i, 't>)
-> Result<ParsedCaseSensitivity, SelectorParseError<'i, E>> { -> Result<ParsedCaseSensitivity, BasicParseError<'i>>
{
let location = input.current_source_location(); let location = input.current_source_location();
match input.next() { match input.next() {
Err(_) => { Err(_) => {
@ -1462,17 +1460,17 @@ fn parse_attribute_flags<'i, 't, E>(input: &mut CssParser<'i, 't>)
Ok(&Token::Ident(ref value)) if value.eq_ignore_ascii_case("i") => { Ok(&Token::Ident(ref value)) if value.eq_ignore_ascii_case("i") => {
Ok(ParsedCaseSensitivity::AsciiCaseInsensitive) Ok(ParsedCaseSensitivity::AsciiCaseInsensitive)
} }
Ok(t) => Err(location.new_unexpected_token_error(t.clone())) Ok(t) => Err(location.new_basic_unexpected_token_error(t.clone()))
} }
} }
/// Level 3: Parse **one** simple_selector. (Though we might insert a second /// Level 3: Parse **one** simple_selector. (Though we might insert a second
/// implied "<defaultns>|*" type selector.) /// implied "<defaultns>|*" type selector.)
fn parse_negation<'i, 't, P, E, Impl>(parser: &P, fn parse_negation<'i, 't, P, Impl>(parser: &P,
input: &mut CssParser<'i, 't>) input: &mut CssParser<'i, 't>)
-> Result<Component<Impl>, SelectorParseError<'i, E>> -> Result<Component<Impl>, ParseError<'i, P::Error>>
where P: Parser<'i, Impl=Impl, Error=E>, Impl: SelectorImpl where P: Parser<'i, Impl=Impl>, Impl: SelectorImpl
{ {
// We use a sequence because a type selector may be represented as two Components. // We use a sequence because a type selector may be represented as two Components.
let mut sequence = SmallVec::<[Component<Impl>; 2]>::new(); let mut sequence = SmallVec::<[Component<Impl>; 2]>::new();
@ -1511,14 +1509,15 @@ fn parse_negation<'i, 't, P, E, Impl>(parser: &P,
/// | [ HASH | class | attrib | pseudo | negation ]+ /// | [ HASH | class | attrib | pseudo | negation ]+
/// ///
/// `Err(())` means invalid selector. /// `Err(())` means invalid selector.
/// `Ok(None)` is an empty selector
/// ///
/// The boolean represent whether a pseudo-element has been parsed. /// The boolean represent whether a pseudo-element has been parsed.
fn parse_compound_selector<'i, 't, P, E, Impl>( fn parse_compound_selector<'i, 't, P, Impl>(
parser: &P, parser: &P,
input: &mut CssParser<'i, 't>, input: &mut CssParser<'i, 't>,
builder: &mut SelectorBuilder<Impl>) builder: &mut SelectorBuilder<Impl>)
-> Result<bool, SelectorParseError<'i, E>> -> Result<Option<bool>, ParseError<'i, P::Error>>
where P: Parser<'i, Impl=Impl, Error=E>, Impl: SelectorImpl where P: Parser<'i, Impl=Impl>, Impl: SelectorImpl
{ {
input.skip_whitespace(); input.skip_whitespace();
@ -1595,24 +1594,24 @@ fn parse_compound_selector<'i, 't, P, E, Impl>(
} }
if empty { if empty {
// An empty selector is invalid. // An empty selector is invalid.
Err(input.new_custom_error(SelectorParseErrorKind::EmptySelector)) Ok(None)
} else { } else {
Ok(pseudo) Ok(Some(pseudo))
} }
} }
fn parse_functional_pseudo_class<'i, 't, P, E, Impl>(parser: &P, fn parse_functional_pseudo_class<'i, 't, P, Impl>(parser: &P,
input: &mut CssParser<'i, 't>, input: &mut CssParser<'i, 't>,
name: CowRcStr<'i>, name: CowRcStr<'i>,
inside_negation: bool) inside_negation: bool)
-> Result<Component<Impl>, SelectorParseError<'i, E>> -> Result<Component<Impl>, ParseError<'i, P::Error>>
where P: Parser<'i, Impl=Impl, Error=E>, Impl: SelectorImpl where P: Parser<'i, Impl=Impl>, Impl: SelectorImpl
{ {
match_ignore_ascii_case! { &name, match_ignore_ascii_case! { &name,
"nth-child" => return parse_nth_pseudo_class(input, Component::NthChild), "nth-child" => return Ok(parse_nth_pseudo_class(input, Component::NthChild)?),
"nth-of-type" => return parse_nth_pseudo_class(input, Component::NthOfType), "nth-of-type" => return Ok(parse_nth_pseudo_class(input, Component::NthOfType)?),
"nth-last-child" => return parse_nth_pseudo_class(input, Component::NthLastChild), "nth-last-child" => return Ok(parse_nth_pseudo_class(input, Component::NthLastChild)?),
"nth-last-of-type" => return parse_nth_pseudo_class(input, Component::NthLastOfType), "nth-last-of-type" => return Ok(parse_nth_pseudo_class(input, Component::NthLastOfType)?),
"not" => { "not" => {
if inside_negation { if inside_negation {
return Err(input.new_custom_error( return Err(input.new_custom_error(
@ -1628,8 +1627,8 @@ fn parse_functional_pseudo_class<'i, 't, P, E, Impl>(parser: &P,
} }
fn parse_nth_pseudo_class<'i, 't, Impl, F, E>(input: &mut CssParser<'i, 't>, selector: F) fn parse_nth_pseudo_class<'i, 't, Impl, F>(input: &mut CssParser<'i, 't>, selector: F)
-> Result<Component<Impl>, SelectorParseError<'i, E>> -> Result<Component<Impl>, BasicParseError<'i>>
where Impl: SelectorImpl, F: FnOnce(i32, i32) -> Component<Impl> { where Impl: SelectorImpl, F: FnOnce(i32, i32) -> Component<Impl> {
let (a, b) = parse_nth(input)?; let (a, b) = parse_nth(input)?;
Ok(selector(a, b)) Ok(selector(a, b))
@ -1652,12 +1651,12 @@ pub fn is_css2_pseudo_element<'i>(name: &CowRcStr<'i>) -> bool {
/// * `Err(())`: Invalid selector, abort /// * `Err(())`: Invalid selector, abort
/// * `Ok(None)`: Not a simple selector, could be something else. `input` was not consumed. /// * `Ok(None)`: Not a simple selector, could be something else. `input` was not consumed.
/// * `Ok(Some(_))`: Parsed a simple selector or pseudo-element /// * `Ok(Some(_))`: Parsed a simple selector or pseudo-element
fn parse_one_simple_selector<'i, 't, P, E, Impl>(parser: &P, fn parse_one_simple_selector<'i, 't, P, Impl>(parser: &P,
input: &mut CssParser<'i, 't>, input: &mut CssParser<'i, 't>,
inside_negation: bool) inside_negation: bool)
-> Result<Option<SimpleSelectorParseResult<Impl>>, -> Result<Option<SimpleSelectorParseResult<Impl>>,
SelectorParseError<'i, E>> ParseError<'i, P::Error>>
where P: Parser<'i, Impl=Impl, Error=E>, Impl: SelectorImpl where P: Parser<'i, Impl=Impl>, Impl: SelectorImpl
{ {
let start = input.state(); let start = input.state();
// FIXME: remove clone() when lifetimes are non-lexical // FIXME: remove clone() when lifetimes are non-lexical
@ -1724,10 +1723,10 @@ fn parse_one_simple_selector<'i, 't, P, E, Impl>(parser: &P,
} }
} }
fn parse_simple_pseudo_class<'i, P, E, Impl>(parser: &P, location: SourceLocation, fn parse_simple_pseudo_class<'i, P, Impl>(parser: &P, location: SourceLocation,
name: CowRcStr<'i>) name: CowRcStr<'i>)
-> Result<Component<Impl>, SelectorParseError<'i, E>> -> Result<Component<Impl>, ParseError<'i, P::Error>>
where P: Parser<'i, Impl=Impl, Error=E>, Impl: SelectorImpl where P: Parser<'i, Impl=Impl>, Impl: SelectorImpl
{ {
(match_ignore_ascii_case! { &name, (match_ignore_ascii_case! { &name,
"first-child" => Ok(Component::FirstChild), "first-child" => Ok(Component::FirstChild),
@ -1877,34 +1876,37 @@ pub mod tests {
impl<'i> Parser<'i> for DummyParser { impl<'i> Parser<'i> for DummyParser {
type Impl = DummySelectorImpl; type Impl = DummySelectorImpl;
type Error = (); type Error = SelectorParseErrorKind<'i>;
fn parse_non_ts_pseudo_class(&self, location: SourceLocation, name: CowRcStr<'i>) fn parse_non_ts_pseudo_class(&self, location: SourceLocation, name: CowRcStr<'i>)
-> Result<PseudoClass, SelectorParseError<'i, ()>> { -> Result<PseudoClass, SelectorParseError<'i>> {
match_ignore_ascii_case! { &name, match_ignore_ascii_case! { &name,
"hover" => Ok(PseudoClass::Hover), "hover" => return Ok(PseudoClass::Hover),
"active" => Ok(PseudoClass::Active), "active" => return Ok(PseudoClass::Active),
_ => Err(location.new_custom_error(SelectorParseErrorKind::Custom(()))) _ => {}
} }
Err(location.new_custom_error(SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name)))
} }
fn parse_non_ts_functional_pseudo_class<'t>(&self, name: CowRcStr<'i>, fn parse_non_ts_functional_pseudo_class<'t>(&self, name: CowRcStr<'i>,
parser: &mut CssParser<'i, 't>) parser: &mut CssParser<'i, 't>)
-> Result<PseudoClass, SelectorParseError<'i, ()>> { -> Result<PseudoClass, SelectorParseError<'i>> {
match_ignore_ascii_case! { &name, match_ignore_ascii_case! { &name,
"lang" => Ok(PseudoClass::Lang(parser.expect_ident_or_string()?.as_ref().to_owned())), "lang" => return Ok(PseudoClass::Lang(parser.expect_ident_or_string()?.as_ref().to_owned())),
_ => Err(parser.new_custom_error(SelectorParseErrorKind::Custom(()))) _ => {}
} }
Err(parser.new_custom_error(SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name)))
} }
fn parse_pseudo_element(&self, location: SourceLocation, name: CowRcStr<'i>) fn parse_pseudo_element(&self, location: SourceLocation, name: CowRcStr<'i>)
-> Result<PseudoElement, -> Result<PseudoElement,
SelectorParseError<'i, ()>> { SelectorParseError<'i>> {
match_ignore_ascii_case! { &name, match_ignore_ascii_case! { &name,
"before" => Ok(PseudoElement::Before), "before" => return Ok(PseudoElement::Before),
"after" => Ok(PseudoElement::After), "after" => return Ok(PseudoElement::After),
_ => Err(location.new_custom_error(SelectorParseErrorKind::Custom(()))) _ => {}
} }
Err(location.new_custom_error(SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name)))
} }
fn default_namespace(&self) -> Option<DummyAtom> { fn default_namespace(&self) -> Option<DummyAtom> {
@ -1917,17 +1919,17 @@ pub mod tests {
} }
fn parse<'i>(input: &'i str) fn parse<'i>(input: &'i str)
-> Result<SelectorList<DummySelectorImpl>, SelectorParseError<'i, ()>> { -> Result<SelectorList<DummySelectorImpl>, SelectorParseError<'i>> {
parse_ns(input, &DummyParser::default()) parse_ns(input, &DummyParser::default())
} }
fn parse_expected<'i, 'a>(input: &'i str, expected: Option<&'a str>) fn parse_expected<'i, 'a>(input: &'i str, expected: Option<&'a str>)
-> Result<SelectorList<DummySelectorImpl>, SelectorParseError<'i, ()>> { -> Result<SelectorList<DummySelectorImpl>, SelectorParseError<'i>> {
parse_ns_expected(input, &DummyParser::default(), expected) parse_ns_expected(input, &DummyParser::default(), expected)
} }
fn parse_ns<'i>(input: &'i str, parser: &DummyParser) fn parse_ns<'i>(input: &'i str, parser: &DummyParser)
-> Result<SelectorList<DummySelectorImpl>, SelectorParseError<'i, ()>> { -> Result<SelectorList<DummySelectorImpl>, SelectorParseError<'i>> {
parse_ns_expected(input, parser, None) parse_ns_expected(input, parser, None)
} }
@ -1935,7 +1937,7 @@ pub mod tests {
input: &'i str, input: &'i str,
parser: &DummyParser, parser: &DummyParser,
expected: Option<&'a str> expected: Option<&'a str>
) -> Result<SelectorList<DummySelectorImpl>, SelectorParseError<'i, ()>> { ) -> Result<SelectorList<DummySelectorImpl>, SelectorParseError<'i>> {
let mut parser_input = ParserInput::new(input); let mut parser_input = ParserInput::new(input);
let result = SelectorList::parse(parser, &mut CssParser::new(&mut parser_input)); let result = SelectorList::parse(parser, &mut CssParser::new(&mut parser_input));
if let Ok(ref selectors) = result { if let Ok(ref selectors) = result {

View file

@ -119,7 +119,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for CounterStyleRuleParser<'a, 'b> {
type PreludeNoBlock = (); type PreludeNoBlock = ();
type PreludeBlock = (); type PreludeBlock = ();
type AtRule = (); type AtRule = ();
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>; type Error = StyleParseErrorKind<'i>;
} }
macro_rules! accessor { macro_rules! accessor {
@ -188,7 +188,7 @@ macro_rules! counter_style_descriptors {
impl<'a, 'b, 'i> DeclarationParser<'i> for CounterStyleRuleParser<'a, 'b> { impl<'a, 'b, 'i> DeclarationParser<'i> for CounterStyleRuleParser<'a, 'b> {
type Declaration = (); 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>) fn parse_value<'t>(&mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>)
-> Result<(), ParseError<'i>> { -> Result<(), ParseError<'i>> {

View file

@ -187,7 +187,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for FontFaceRuleParser<'a, 'b> {
type PreludeNoBlock = (); type PreludeNoBlock = ();
type PreludeBlock = (); type PreludeBlock = ();
type AtRule = (); type AtRule = ();
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>; type Error = StyleParseErrorKind<'i>;
} }
impl Parse for Source { impl Parse for Source {
@ -288,7 +288,7 @@ macro_rules! font_face_descriptors_common {
impl<'a, 'b, 'i> DeclarationParser<'i> for FontFaceRuleParser<'a, 'b> { impl<'a, 'b, 'i> DeclarationParser<'i> for FontFaceRuleParser<'a, 'b> {
type Declaration = (); 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>) fn parse_value<'t>(&mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>)
-> Result<(), ParseError<'i>> { -> Result<(), ParseError<'i>> {

View file

@ -13,7 +13,6 @@ use custom_properties::CustomPropertiesBuilder;
use error_reporting::{ParseErrorReporter, ContextualParseError}; use error_reporting::{ParseErrorReporter, ContextualParseError};
use parser::{ParserContext, ParserErrorContext}; use parser::{ParserContext, ParserErrorContext};
use properties::animated_properties::AnimationValue; use properties::animated_properties::AnimationValue;
use selectors::parser::SelectorParseErrorKind;
use shared_lock::Locked; use shared_lock::Locked;
use smallbitvec::{self, SmallBitVec}; use smallbitvec::{self, SmallBitVec};
use smallvec::SmallVec; use smallvec::SmallVec;
@ -1060,7 +1059,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for PropertyDeclarationParser<'a, 'b> {
type PreludeNoBlock = (); type PreludeNoBlock = ();
type PreludeBlock = (); type PreludeBlock = ();
type AtRule = Importance; type AtRule = Importance;
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>; type Error = StyleParseErrorKind<'i>;
} }
/// Based on NonMozillaVendorIdentifier from Gecko's CSS parser. /// 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> { impl<'a, 'b, 'i> DeclarationParser<'i> for PropertyDeclarationParser<'a, 'b> {
type Declaration = Importance; 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>) fn parse_value<'t>(&mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>)
-> Result<Importance, ParseError<'i>> { -> 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, // If the unrecognized property looks like a vendor-specific property,
// silently ignore it instead of polluting the error output. // silently ignore it instead of polluting the error output.
if let ParseErrorKind::Custom(SelectorParseErrorKind::Custom( if let ParseErrorKind::Custom(
StyleParseErrorKind::PropertyDeclaration( StyleParseErrorKind::PropertyDeclaration(
PropertyDeclarationParseErrorKind::UnknownVendorProperty))) = error.kind { PropertyDeclarationParseErrorKind::UnknownVendorProperty)) = error.kind {
continue; continue;
} }

View file

@ -16,7 +16,6 @@ use gecko_bindings::bindings::Gecko_AppendFeatureValueHashEntry;
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
use gecko_bindings::structs::{self, gfxFontFeatureValueSet, nsTArray}; use gecko_bindings::structs::{self, gfxFontFeatureValueSet, nsTArray};
use parser::{ParserContext, ParserErrorContext, Parse}; use parser::{ParserContext, ParserErrorContext, Parse};
use selectors::parser::SelectorParseErrorKind;
use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard}; use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard};
use std::fmt; use std::fmt;
use style_traits::{ParseError, StyleParseErrorKind, ToCss}; 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 PreludeNoBlock = ();
type PreludeBlock = (); type PreludeBlock = ();
type AtRule = (); type AtRule = ();
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>; type Error = StyleParseErrorKind<'i>;
} }
impl<'a, 'b, 'i, T> DeclarationParser<'i> for FFVDeclarationsParser<'a, 'b, T> impl<'a, 'b, 'i, T> DeclarationParser<'i> for FFVDeclarationsParser<'a, 'b, T>
where T: Parse where T: Parse
{ {
type Declaration = (); 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>) fn parse_value<'t>(&mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>)
-> Result<(), ParseError<'i>> { -> Result<(), ParseError<'i>> {
@ -392,14 +391,14 @@ macro_rules! font_feature_values_blocks {
impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for FontFeatureValuesRuleParser<'a, R> { impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for FontFeatureValuesRuleParser<'a, R> {
type Prelude = (); type Prelude = ();
type QualifiedRule = (); type QualifiedRule = ();
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>; type Error = StyleParseErrorKind<'i>;
} }
impl<'a, 'i, R: ParseErrorReporter> AtRuleParser<'i> for FontFeatureValuesRuleParser<'a, R> { impl<'a, 'i, R: ParseErrorReporter> AtRuleParser<'i> for FontFeatureValuesRuleParser<'a, R> {
type PreludeNoBlock = (); type PreludeNoBlock = ();
type PreludeBlock = BlockType; type PreludeBlock = BlockType;
type AtRule = (); type AtRule = ();
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>; type Error = StyleParseErrorKind<'i>;
fn parse_prelude<'t>(&mut self, fn parse_prelude<'t>(&mut self,
name: CowRcStr<'i>, name: CowRcStr<'i>,

View file

@ -12,7 +12,6 @@ use properties::{Importance, PropertyDeclaration, PropertyDeclarationBlock, Prop
use properties::{PropertyDeclarationId, LonghandId, SourcePropertyDeclaration}; use properties::{PropertyDeclarationId, LonghandId, SourcePropertyDeclaration};
use properties::LonghandIdSet; use properties::LonghandIdSet;
use properties::longhands::transition_timing_function::single_value::SpecifiedValue as SpecifiedTimingFunction; use properties::longhands::transition_timing_function::single_value::SpecifiedValue as SpecifiedTimingFunction;
use selectors::parser::SelectorParseErrorKind;
use servo_arc::Arc; use servo_arc::Arc;
use shared_lock::{DeepCloneParams, DeepCloneWithLock, SharedRwLock, SharedRwLockReadGuard, Locked, ToCssWithGuard}; use shared_lock::{DeepCloneParams, DeepCloneWithLock, SharedRwLock, SharedRwLockReadGuard, Locked, ToCssWithGuard};
use std::fmt; use std::fmt;
@ -500,7 +499,7 @@ impl<'a, 'i, R> AtRuleParser<'i> for KeyframeListParser<'a, R> {
type PreludeNoBlock = (); type PreludeNoBlock = ();
type PreludeBlock = (); type PreludeBlock = ();
type AtRule = Arc<Locked<Keyframe>>; 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 /// 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> { impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for KeyframeListParser<'a, R> {
type Prelude = KeyframeSelectorParserPrelude; type Prelude = KeyframeSelectorParserPrelude;
type QualifiedRule = Arc<Locked<Keyframe>>; 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>> { fn parse_prelude<'t>(&mut self, input: &mut Parser<'i, 't>) -> Result<Self::Prelude, ParseError<'i>> {
let start_position = input.position(); let start_position = input.position();
@ -580,12 +579,12 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for KeyframeDeclarationParser<'a, 'b> {
type PreludeNoBlock = (); type PreludeNoBlock = ();
type PreludeBlock = (); type PreludeBlock = ();
type AtRule = (); type AtRule = ();
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>; type Error = StyleParseErrorKind<'i>;
} }
impl<'a, 'b, 'i> DeclarationParser<'i> for KeyframeDeclarationParser<'a, 'b> { impl<'a, 'b, 'i> DeclarationParser<'i> for KeyframeDeclarationParser<'a, 'b> {
type Declaration = (); 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>) fn parse_value<'t>(&mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>)
-> Result<(), ParseError<'i>> { -> Result<(), ParseError<'i>> {

View file

@ -16,7 +16,6 @@ use parser::{Parse, ParserContext, ParserErrorContext};
use properties::parse_property_declaration_list; use properties::parse_property_declaration_list;
use selector_parser::{SelectorImpl, SelectorParser}; use selector_parser::{SelectorImpl, SelectorParser};
use selectors::SelectorList; use selectors::SelectorList;
use selectors::parser::SelectorParseErrorKind;
use servo_arc::Arc; use servo_arc::Arc;
use shared_lock::{Locked, SharedRwLock}; use shared_lock::{Locked, SharedRwLock};
use str::starts_with_ignore_ascii_case; 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 PreludeNoBlock = AtRuleNonBlockPrelude;
type PreludeBlock = AtRuleBlockPrelude; type PreludeBlock = AtRuleBlockPrelude;
type AtRule = CssRule; type AtRule = CssRule;
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>; type Error = StyleParseErrorKind<'i>;
fn parse_prelude<'t>( fn parse_prelude<'t>(
&mut self, &mut self,
@ -280,7 +279,7 @@ pub struct QualifiedRuleParserPrelude {
impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for TopLevelRuleParser<'a, R> { impl<'a, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for TopLevelRuleParser<'a, R> {
type Prelude = QualifiedRuleParserPrelude; type Prelude = QualifiedRuleParserPrelude;
type QualifiedRule = CssRule; type QualifiedRule = CssRule;
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>; type Error = StyleParseErrorKind<'i>;
#[inline] #[inline]
fn parse_prelude<'t>( fn parse_prelude<'t>(
@ -347,7 +346,7 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a
type PreludeNoBlock = AtRuleNonBlockPrelude; type PreludeNoBlock = AtRuleNonBlockPrelude;
type PreludeBlock = AtRuleBlockPrelude; type PreludeBlock = AtRuleBlockPrelude;
type AtRule = CssRule; type AtRule = CssRule;
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>; type Error = StyleParseErrorKind<'i>;
fn parse_prelude<'t>( fn parse_prelude<'t>(
&mut self, &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> { impl<'a, 'b, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for NestedRuleParser<'a, 'b, R> {
type Prelude = QualifiedRuleParserPrelude; type Prelude = QualifiedRuleParserPrelude;
type QualifiedRule = CssRule; type QualifiedRule = CssRule;
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>; type Error = StyleParseErrorKind<'i>;
fn parse_prelude<'t>( fn parse_prelude<'t>(
&mut self, &mut self,

View file

@ -276,12 +276,12 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for ViewportRuleParser<'a, 'b> {
type PreludeNoBlock = (); type PreludeNoBlock = ();
type PreludeBlock = (); type PreludeBlock = ();
type AtRule = Vec<ViewportDescriptorDeclaration>; type AtRule = Vec<ViewportDescriptorDeclaration>;
type Error = SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>; type Error = StyleParseErrorKind<'i>;
} }
impl<'a, 'b, 'i> DeclarationParser<'i> for ViewportRuleParser<'a, 'b> { impl<'a, 'b, 'i> DeclarationParser<'i> for ViewportRuleParser<'a, 'b> {
type Declaration = Vec<ViewportDescriptorDeclaration>; 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>) fn parse_value<'t>(&mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>)
-> Result<Vec<ViewportDescriptorDeclaration>, ParseError<'i>> { -> Result<Vec<ViewportDescriptorDeclaration>, ParseError<'i>> {

View file

@ -85,10 +85,7 @@ pub mod viewport;
pub use values::{Comma, CommaWithSpace, OneOrMoreSeparated, Separator, Space, ToCss}; pub use values::{Comma, CommaWithSpace, OneOrMoreSeparated, Separator, Space, ToCss};
/// The error type for all CSS parsing routines. /// The error type for all CSS parsing routines.
pub type ParseError<'i> = cssparser::ParseError<'i, SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>>; pub type ParseError<'i> = cssparser::ParseError<'i, StyleParseErrorKind<'i>>;
/// Error emitted by the style crate
pub type StyleParseError<'i> = cssparser::ParseError<'i, StyleParseErrorKind<'i>>;
/// Error in property value parsing /// Error in property value parsing
pub type ValueParseError<'i> = cssparser::ParseError<'i, ValueParseErrorKind<'i>>; pub type ValueParseError<'i> = cssparser::ParseError<'i, ValueParseErrorKind<'i>>;
@ -139,17 +136,25 @@ pub enum StyleParseErrorKind<'i> {
UnexpectedTokenWithinNamespace(Token<'i>), UnexpectedTokenWithinNamespace(Token<'i>),
/// An error was encountered while parsing a property value. /// An error was encountered while parsing a property value.
ValueError(ValueParseErrorKind<'i>), 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 { fn from(this: ValueParseErrorKind<'i>) -> Self {
StyleParseErrorKind::ValueError(this).into() StyleParseErrorKind::ValueError(this)
} }
} }
impl<'i> From<PropertyDeclarationParseErrorKind<'i>> for SelectorParseErrorKind<'i, StyleParseErrorKind<'i>> { impl<'i> From<SelectorParseErrorKind<'i>> for StyleParseErrorKind<'i> {
fn from(this: SelectorParseErrorKind<'i>) -> Self {
StyleParseErrorKind::SelectorError(this)
}
}
impl<'i> From<PropertyDeclarationParseErrorKind<'i>> for StyleParseErrorKind<'i> {
fn from(this: PropertyDeclarationParseErrorKind<'i>) -> Self { 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( kind: cssparser::ParseErrorKind::Custom(PropertyDeclarationParseErrorKind::InvalidValue(
name, name,
match value_error.kind { match value_error.kind {
cssparser::ParseErrorKind::Custom( cssparser::ParseErrorKind::Custom(StyleParseErrorKind::ValueError(e)) => Some(e),
SelectorParseErrorKind::Custom(
StyleParseErrorKind::ValueError(e)
)
) => Some(e),
_ => None, _ => None,
} }
)), )),

View file

@ -20,7 +20,7 @@ use style::gecko_bindings::sugar::refptr::RefPtr;
use style::stylesheets::UrlExtraData; use style::stylesheets::UrlExtraData;
use style_traits::{StyleParseErrorKind, PropertyDeclarationParseErrorKind, ValueParseErrorKind}; use style_traits::{StyleParseErrorKind, PropertyDeclarationParseErrorKind, ValueParseErrorKind};
pub type ErrorKind<'i> = ParseErrorKind<'i, SelectorParseErrorKind<'i, StyleParseErrorKind<'i>>>; pub type ErrorKind<'i> = ParseErrorKind<'i, StyleParseErrorKind<'i>>;
/// Wrapper around an instance of Gecko's CSS error reporter. /// Wrapper around an instance of Gecko's CSS error reporter.
pub struct ErrorReporter(*mut GeckoErrorReporter); pub struct ErrorReporter(*mut GeckoErrorReporter);
@ -84,37 +84,39 @@ fn extract_error_param<'a>(err: ErrorKind<'a>) -> Option<ErrorString<'a>> {
} }
ParseErrorKind::Basic(BasicParseErrorKind::AtRuleInvalid(i)) | ParseErrorKind::Basic(BasicParseErrorKind::AtRuleInvalid(i)) |
ParseErrorKind::Custom(SelectorParseErrorKind::Custom( ParseErrorKind::Custom(StyleParseErrorKind::UnsupportedAtRule(i)) => {
StyleParseErrorKind::UnsupportedAtRule(i)
)) => {
let mut s = String::from("@"); let mut s = String::from("@");
serialize_identifier(&i, &mut s).unwrap(); serialize_identifier(&i, &mut s).unwrap();
ErrorString::Snippet(s.into()) ErrorString::Snippet(s.into())
} }
ParseErrorKind::Custom(SelectorParseErrorKind::Custom( ParseErrorKind::Custom(
StyleParseErrorKind::PropertyDeclaration( StyleParseErrorKind::PropertyDeclaration(
PropertyDeclarationParseErrorKind::InvalidValue(property, None) PropertyDeclarationParseErrorKind::InvalidValue(property, None)
) )
)) => { ) => {
ErrorString::Snippet(property) ErrorString::Snippet(property)
} }
ParseErrorKind::Custom(SelectorParseErrorKind::UnexpectedIdent(ident)) => { ParseErrorKind::Custom(
StyleParseErrorKind::SelectorError(
SelectorParseErrorKind::UnexpectedIdent(ident)
)
) => {
ErrorString::Ident(ident) ErrorString::Ident(ident)
} }
ParseErrorKind::Custom(SelectorParseErrorKind::Custom( ParseErrorKind::Custom(
StyleParseErrorKind::PropertyDeclaration( StyleParseErrorKind::PropertyDeclaration(
PropertyDeclarationParseErrorKind::UnknownProperty(property) PropertyDeclarationParseErrorKind::UnknownProperty(property)
) )
)) => { ) => {
ErrorString::Ident(property) ErrorString::Ident(property)
} }
ParseErrorKind::Custom(SelectorParseErrorKind::Custom( ParseErrorKind::Custom(
StyleParseErrorKind::UnexpectedTokenWithinNamespace(token) StyleParseErrorKind::UnexpectedTokenWithinNamespace(token)
)) => { ) => {
ErrorString::UnexpectedToken(token) ErrorString::UnexpectedToken(token)
} }
@ -138,51 +140,57 @@ struct ErrorParams<'a> {
/// a second parameter if it exists, for use in the prefix for the eventual error message. /// a second parameter if it exists, for use in the prefix for the eventual error message.
fn extract_error_params<'a>(err: ErrorKind<'a>) -> Option<ErrorParams<'a>> { fn extract_error_params<'a>(err: ErrorKind<'a>) -> Option<ErrorParams<'a>> {
let (main, prefix) = match err { let (main, prefix) = match err {
ParseErrorKind::Custom(SelectorParseErrorKind::Custom( ParseErrorKind::Custom(
StyleParseErrorKind::PropertyDeclaration( StyleParseErrorKind::PropertyDeclaration(
PropertyDeclarationParseErrorKind::InvalidValue(property, Some(e)) PropertyDeclarationParseErrorKind::InvalidValue(property, Some(e))
) )
)) => { ) => {
(Some(ErrorString::Snippet(property.into())), Some(extract_value_error_param(e))) (Some(ErrorString::Snippet(property.into())), Some(extract_value_error_param(e)))
} }
ParseErrorKind::Custom(SelectorParseErrorKind::Custom( ParseErrorKind::Custom(
StyleParseErrorKind::MediaQueryExpectedFeatureName(ident) StyleParseErrorKind::MediaQueryExpectedFeatureName(ident)
)) => { ) => {
(Some(ErrorString::Ident(ident)), None) (Some(ErrorString::Ident(ident)), None)
} }
ParseErrorKind::Custom(SelectorParseErrorKind::Custom( ParseErrorKind::Custom(
StyleParseErrorKind::ExpectedIdentifier(token) StyleParseErrorKind::ExpectedIdentifier(token)
)) => { ) => {
(Some(ErrorString::UnexpectedToken(token)), None) (Some(ErrorString::UnexpectedToken(token)), None)
} }
ParseErrorKind::Custom(SelectorParseErrorKind::UnexpectedTokenInAttributeSelector(t)) | ParseErrorKind::Custom(StyleParseErrorKind::SelectorError(err)) => match err {
ParseErrorKind::Custom(SelectorParseErrorKind::BadValueInAttr(t)) | SelectorParseErrorKind::UnexpectedTokenInAttributeSelector(t) |
ParseErrorKind::Custom(SelectorParseErrorKind::ExpectedBarInAttr(t)) | SelectorParseErrorKind::BadValueInAttr(t) |
ParseErrorKind::Custom(SelectorParseErrorKind::NoQualifiedNameInAttributeSelector(t)) | SelectorParseErrorKind::ExpectedBarInAttr(t) |
ParseErrorKind::Custom(SelectorParseErrorKind::InvalidQualNameInAttr(t)) | SelectorParseErrorKind::NoQualifiedNameInAttributeSelector(t) |
ParseErrorKind::Custom(SelectorParseErrorKind::ExplicitNamespaceUnexpectedToken(t)) | SelectorParseErrorKind::InvalidQualNameInAttr(t) |
ParseErrorKind::Custom(SelectorParseErrorKind::PseudoElementExpectedIdent(t)) | SelectorParseErrorKind::ExplicitNamespaceUnexpectedToken(t) |
ParseErrorKind::Custom(SelectorParseErrorKind::NoIdentForPseudo(t)) | SelectorParseErrorKind::PseudoElementExpectedIdent(t) |
ParseErrorKind::Custom(SelectorParseErrorKind::ClassNeedsIdent(t)) | SelectorParseErrorKind::NoIdentForPseudo(t) |
ParseErrorKind::Custom(SelectorParseErrorKind::PseudoElementExpectedColon(t)) => { SelectorParseErrorKind::ClassNeedsIdent(t) |
SelectorParseErrorKind::PseudoElementExpectedColon(t) => {
(None, Some(ErrorString::UnexpectedToken(t))) (None, Some(ErrorString::UnexpectedToken(t)))
} }
ParseErrorKind::Custom(SelectorParseErrorKind::ExpectedNamespace(namespace)) => { SelectorParseErrorKind::ExpectedNamespace(namespace) => {
(None, Some(ErrorString::Ident(namespace))) (None, Some(ErrorString::Ident(namespace)))
} }
ParseErrorKind::Custom(SelectorParseErrorKind::UnsupportedPseudoClassOrElement(p)) => { SelectorParseErrorKind::UnsupportedPseudoClassOrElement(p) => {
(None, Some(ErrorString::Ident(p))) (None, Some(ErrorString::Ident(p)))
} }
ParseErrorKind::Custom(SelectorParseErrorKind::EmptySelector) | SelectorParseErrorKind::EmptySelector |
ParseErrorKind::Custom(SelectorParseErrorKind::DanglingCombinator) => { SelectorParseErrorKind::DanglingCombinator => {
(None, None) (None, None)
} }
ParseErrorKind::Custom(SelectorParseErrorKind::EmptyNegation) => { SelectorParseErrorKind::EmptyNegation => {
(None, Some(ErrorString::Snippet(")".into()))) (None, Some(ErrorString::Snippet(")".into())))
} }
err => match extract_error_param(ParseErrorKind::Custom(StyleParseErrorKind::SelectorError(err))) {
Some(e) => (Some(e), None),
None => return None,
}
},
err => match extract_error_param(err) { err => match extract_error_param(err) {
Some(e) => (Some(e), None), Some(e) => (Some(e), None),
None => return None, None => return None,
@ -241,10 +249,10 @@ impl<'a> ErrorHelpers<'a> for ContextualParseError<'a> {
(b"PEParseDeclarationDeclExpected\0", Action::Skip) (b"PEParseDeclarationDeclExpected\0", Action::Skip)
} }
ContextualParseError::UnsupportedPropertyDeclaration( ContextualParseError::UnsupportedPropertyDeclaration(
_, ParseError { kind: ParseErrorKind::Custom(SelectorParseErrorKind::Custom( _, ParseError { kind: ParseErrorKind::Custom(
StyleParseErrorKind::PropertyDeclaration( StyleParseErrorKind::PropertyDeclaration(
PropertyDeclarationParseErrorKind::InvalidValue(_, ref err) PropertyDeclarationParseErrorKind::InvalidValue(_, ref err)
)) )
), .. } ), .. }
) => { ) => {
let prefix = match *err { let prefix = match *err {
@ -263,9 +271,9 @@ impl<'a> ErrorHelpers<'a> for ContextualParseError<'a> {
ContextualParseError::UnsupportedKeyframePropertyDeclaration(..) => ContextualParseError::UnsupportedKeyframePropertyDeclaration(..) =>
(b"PEBadSelectorKeyframeRuleIgnored\0", Action::Nothing), (b"PEBadSelectorKeyframeRuleIgnored\0", Action::Nothing),
ContextualParseError::InvalidRule( ContextualParseError::InvalidRule(
_, ParseError { kind: ParseErrorKind::Custom(SelectorParseErrorKind::Custom( _, ParseError { kind: ParseErrorKind::Custom(
StyleParseErrorKind::UnexpectedTokenWithinNamespace(_) StyleParseErrorKind::UnexpectedTokenWithinNamespace(_)
)), .. } ), .. }
) => { ) => {
(b"PEAtNSUnexpected\0", Action::Nothing) (b"PEAtNSUnexpected\0", Action::Nothing)
} }
@ -273,68 +281,78 @@ impl<'a> ErrorHelpers<'a> for ContextualParseError<'a> {
_, ParseError { kind: ParseErrorKind::Basic(BasicParseErrorKind::AtRuleInvalid(_)), .. } _, ParseError { kind: ParseErrorKind::Basic(BasicParseErrorKind::AtRuleInvalid(_)), .. }
) | ) |
ContextualParseError::InvalidRule( ContextualParseError::InvalidRule(
_, ParseError { kind: ParseErrorKind::Custom(SelectorParseErrorKind::Custom( _, ParseError { kind: ParseErrorKind::Custom(
StyleParseErrorKind::UnsupportedAtRule(_) StyleParseErrorKind::UnsupportedAtRule(_)
)), .. } ), .. }
) => { ) => {
(b"PEUnknownAtRule\0", Action::Nothing) (b"PEUnknownAtRule\0", Action::Nothing)
} }
ContextualParseError::InvalidRule(_, ref err) => { ContextualParseError::InvalidRule(_, ref err) => {
let prefix = match err.kind { let prefix = match err.kind {
ParseErrorKind::Custom(SelectorParseErrorKind::UnexpectedTokenInAttributeSelector(_)) => ParseErrorKind::Custom(StyleParseErrorKind::SelectorError(ref err)) => match *err {
Some(&b"PEAttSelUnexpected\0"[..]), SelectorParseErrorKind::UnexpectedTokenInAttributeSelector(_) => {
ParseErrorKind::Custom(SelectorParseErrorKind::ExpectedBarInAttr(_)) => Some(&b"PEAttSelUnexpected\0"[..])
Some(&b"PEAttSelNoBar\0"[..]), }
ParseErrorKind::Custom(SelectorParseErrorKind::BadValueInAttr(_)) => SelectorParseErrorKind::ExpectedBarInAttr(_) => {
Some(&b"PEAttSelBadValue\0"[..]), Some(&b"PEAttSelNoBar\0"[..])
ParseErrorKind::Custom(SelectorParseErrorKind::NoQualifiedNameInAttributeSelector(_)) => }
Some(&b"PEAttributeNameOrNamespaceExpected\0"[..]), SelectorParseErrorKind::BadValueInAttr(_) => {
ParseErrorKind::Custom(SelectorParseErrorKind::InvalidQualNameInAttr(_)) => Some(&b"PEAttSelBadValue\0"[..])
Some(&b"PEAttributeNameExpected\0"[..]), }
ParseErrorKind::Custom(SelectorParseErrorKind::ExplicitNamespaceUnexpectedToken(_)) => SelectorParseErrorKind::NoQualifiedNameInAttributeSelector(_) => {
Some(&b"PETypeSelNotType\0"[..]), Some(&b"PEAttributeNameOrNamespaceExpected\0"[..])
ParseErrorKind::Custom(SelectorParseErrorKind::ExpectedNamespace(_)) => }
Some(&b"PEUnknownNamespacePrefix\0"[..]), SelectorParseErrorKind::InvalidQualNameInAttr(_) => {
ParseErrorKind::Custom(SelectorParseErrorKind::EmptySelector) => Some(&b"PEAttributeNameExpected\0"[..])
Some(&b"PESelectorGroupNoSelector\0"[..]), }
ParseErrorKind::Custom(SelectorParseErrorKind::DanglingCombinator) => SelectorParseErrorKind::ExplicitNamespaceUnexpectedToken(_) => {
Some(&b"PESelectorGroupExtraCombinator\0"[..]), Some(&b"PETypeSelNotType\0"[..])
ParseErrorKind::Custom(SelectorParseErrorKind::UnsupportedPseudoClassOrElement(_)) => }
Some(&b"PEPseudoSelUnknown\0"[..]), SelectorParseErrorKind::ExpectedNamespace(_) => {
ParseErrorKind::Custom(SelectorParseErrorKind::PseudoElementExpectedColon(_)) => Some(&b"PEUnknownNamespacePrefix\0"[..])
Some(&b"PEPseudoSelEndOrUserActionPC\0"[..]), }
ParseErrorKind::Custom(SelectorParseErrorKind::NoIdentForPseudo(_)) => SelectorParseErrorKind::EmptySelector => {
Some(&b"PEPseudoClassArgNotIdent\0"[..]), Some(&b"PESelectorGroupNoSelector\0"[..])
ParseErrorKind::Custom(SelectorParseErrorKind::PseudoElementExpectedIdent(_)) => }
Some(&b"PEPseudoSelBadName\0"[..]), SelectorParseErrorKind::DanglingCombinator => {
ParseErrorKind::Custom(SelectorParseErrorKind::ClassNeedsIdent(_)) => Some(&b"PESelectorGroupExtraCombinator\0"[..])
Some(&b"PEClassSelNotIdent\0"[..]), }
ParseErrorKind::Custom(SelectorParseErrorKind::EmptyNegation) => SelectorParseErrorKind::UnsupportedPseudoClassOrElement(_) => {
Some(&b"PENegationBadArg\0"[..]), Some(&b"PEPseudoSelUnknown\0"[..])
}
SelectorParseErrorKind::PseudoElementExpectedColon(_) => {
Some(&b"PEPseudoSelEndOrUserActionPC\0"[..])
}
SelectorParseErrorKind::NoIdentForPseudo(_) => {
Some(&b"PEPseudoClassArgNotIdent\0"[..])
}
SelectorParseErrorKind::PseudoElementExpectedIdent(_) => {
Some(&b"PEPseudoSelBadName\0"[..])
}
SelectorParseErrorKind::ClassNeedsIdent(_) => {
Some(&b"PEClassSelNotIdent\0"[..])
}
SelectorParseErrorKind::EmptyNegation => {
Some(&b"PENegationBadArg\0"[..])
}
_ => None,
},
_ => None, _ => None,
}; };
return (prefix, b"PEBadSelectorRSIgnored\0", Action::Nothing); return (prefix, b"PEBadSelectorRSIgnored\0", Action::Nothing);
} }
ContextualParseError::InvalidMediaRule(_, ref err) => { ContextualParseError::InvalidMediaRule(_, ref err) => {
let err: &[u8] = match err.kind { let err: &[u8] = match err.kind {
ParseErrorKind::Custom(SelectorParseErrorKind::Custom( ParseErrorKind::Custom(StyleParseErrorKind::ExpectedIdentifier(..)) => {
StyleParseErrorKind::ExpectedIdentifier(..)
)) => {
b"PEGatherMediaNotIdent\0" b"PEGatherMediaNotIdent\0"
}, },
ParseErrorKind::Custom(SelectorParseErrorKind::Custom( ParseErrorKind::Custom(StyleParseErrorKind::MediaQueryExpectedFeatureName(..)) => {
StyleParseErrorKind::MediaQueryExpectedFeatureName(..)
)) => {
b"PEMQExpectedFeatureName\0" b"PEMQExpectedFeatureName\0"
}, },
ParseErrorKind::Custom(SelectorParseErrorKind::Custom( ParseErrorKind::Custom(StyleParseErrorKind::MediaQueryExpectedFeatureValue) => {
StyleParseErrorKind::MediaQueryExpectedFeatureValue
)) => {
b"PEMQExpectedFeatureValue\0" b"PEMQExpectedFeatureValue\0"
}, },
ParseErrorKind::Custom(SelectorParseErrorKind::Custom( ParseErrorKind::Custom(StyleParseErrorKind::RangedExpressionWithNoValue) => {
StyleParseErrorKind::RangedExpressionWithNoValue
)) => {
b"PEMQNoMinMaxWithoutValue\0" b"PEMQNoMinMaxWithoutValue\0"
}, },
_ => { _ => {

View file

@ -14,15 +14,12 @@ size_of_test!(test_size_of_property_declaration, properties::PropertyDeclaration
// we only pass `&mut SourcePropertyDeclaration` references around. // we only pass `&mut SourcePropertyDeclaration` references around.
size_of_test!(test_size_of_parsed_declaration, properties::SourcePropertyDeclaration, 576); size_of_test!(test_size_of_parsed_declaration, properties::SourcePropertyDeclaration, 576);
size_of_test!(test_size_of_selector_parse_error_kind_with_unit, SelectorParseErrorKind<()>, 40); size_of_test!(test_size_of_selector_parse_error_kind, SelectorParseErrorKind, 40);
size_of_test!(test_size_of_style_parse_error_kind, ::style_traits::StyleParseErrorKind, 80); size_of_test!(test_size_of_style_parse_error_kind, ::style_traits::StyleParseErrorKind, 80);
size_of_test!(test_size_of_value_parse_error_kind, ::style_traits::ValueParseErrorKind, 40); size_of_test!(test_size_of_value_parse_error_kind, ::style_traits::ValueParseErrorKind, 40);
size_of_test!(test_size_of_declaration_parse_error_kind, ::style_traits::PropertyDeclarationParseErrorKind, 72); size_of_test!(test_size_of_declaration_parse_error_kind, ::style_traits::PropertyDeclarationParseErrorKind, 72);
size_of_test!(test_size_of_style_traits_parse_error_kind,
SelectorParseErrorKind<::style_traits::StyleParseErrorKind>, 88);
size_of_test!(test_size_of_selector_parse_error_with_unit, SelectorParseError<()>, 56); size_of_test!(test_size_of_selector_parse_error, SelectorParseError, 56);
size_of_test!(test_size_of_style_parse_error, ::style_traits::StyleParseError, 96); size_of_test!(test_size_of_style_traits_parse_error, ::style_traits::ParseError, 96);
size_of_test!(test_size_of_value_parse_error, ::style_traits::ValueParseError, 56); size_of_test!(test_size_of_value_parse_error, ::style_traits::ValueParseError, 56);
size_of_test!(test_size_of_declaration_parse_error, ::style_traits::PropertyDeclarationParseError, 88); size_of_test!(test_size_of_declaration_parse_error, ::style_traits::PropertyDeclarationParseError, 88);
size_of_test!(test_size_of_style_traits_parse_error, ::style_traits::ParseError, 104);