1use cssparser::{BasicParseErrorKind, ParseErrorKind, Token};
5use selectors::parser::SelectorParseErrorKind;
6
7#[derive(Debug, Clone)]
9pub enum SelectorErrorKind<'a> {
10 UnexpectedToken(Token<'a>),
12
13 EndOfLine,
15
16 InvalidAtRule(String),
18
19 InvalidAtRuleBody,
21
22 QualRuleInvalid,
24
25 ExpectedColonOnPseudoElement(Token<'a>),
27
28 ExpectedIdentityOnPseudoElement(Token<'a>),
30
31 UnexpectedSelectorParseError(SelectorParseErrorKind<'a>),
33}
34
35impl<'a> From<cssparser::ParseError<'a, SelectorParseErrorKind<'a>>> for SelectorErrorKind<'a> {
36 fn from(original: cssparser::ParseError<'a, SelectorParseErrorKind<'a>>) -> Self {
37 match original.kind {
40 ParseErrorKind::Basic(err) => SelectorErrorKind::from(err),
41 ParseErrorKind::Custom(err) => SelectorErrorKind::from(err),
42 }
43 }
44}
45
46impl<'a> From<BasicParseErrorKind<'a>> for SelectorErrorKind<'a> {
47 fn from(err: BasicParseErrorKind<'a>) -> Self {
48 match err {
49 BasicParseErrorKind::UnexpectedToken(token) => Self::UnexpectedToken(token),
50 BasicParseErrorKind::EndOfInput => Self::EndOfLine,
51 BasicParseErrorKind::AtRuleInvalid(rule) => Self::InvalidAtRule(rule.to_string()),
52 BasicParseErrorKind::AtRuleBodyInvalid => Self::InvalidAtRuleBody,
53 BasicParseErrorKind::QualifiedRuleInvalid => Self::QualRuleInvalid,
54 }
55 }
56}
57
58impl<'a> From<SelectorParseErrorKind<'a>> for SelectorErrorKind<'a> {
59 fn from(err: SelectorParseErrorKind<'a>) -> Self {
60 match err {
61 SelectorParseErrorKind::PseudoElementExpectedColon(token) => {
62 Self::ExpectedColonOnPseudoElement(token)
63 }
64 SelectorParseErrorKind::PseudoElementExpectedIdent(token) => {
65 Self::ExpectedIdentityOnPseudoElement(token)
66 }
67 other => Self::UnexpectedSelectorParseError(other),
68 }
69 }
70}