1use {
5 crate::domain::at_rules::counter_style::System,
6 cssparser::{
7 BasicParseErrorKind,
8 CowRcStr,
9 ParseError,
10 ParseErrorKind,
11 SourceLocation,
12 Token,
13 },
14 selectors::parser::{SelectorParseError, SelectorParseErrorKind},
15};
16
17#[derive(Debug)]
19pub enum CustomParseError<'i> {
20 UnsupportedAtRule(CowRcStr<'i>),
22 InvalidParseState,
23
24 UnexpectedCharsetAtRule,
26
27 UnsupportedCounterStyleProperty(CowRcStr<'i>),
29 InvalidCounterStyleWithoutSymbols(System),
30 InvalidCounterStyleNotEnoughSymbols(System),
31 InvalidCounterStyleWithoutAdditiveSymbols,
32 InvalidCounterStyleExtendsWithSymbols,
33 InvalidCounterStyleExtendsWithAdditiveSymbols,
34 CounterStyleSystemIsNotKnown(CowRcStr<'i>),
35 CounterStyleSymbolsCanNotBeEmpty,
36 CounterStyleRangesCanNotHaveStartGreaterThanEnd(i32, i32),
37 CounterStylePadMinLengthCanNotBeNegative(i32),
38 CounterStyleAdditiveTupleWeightCanNotBeNegative(i32),
39 CounterStyleAdditiveSymbolsCanNotHaveASecondWeightEqualToOrGreaterThanTheFirst,
40 DecimalOrDiscIsNotAllowedInACounterStyleIdentInACounterStyleAtRule,
41 NoneIsNotAllowedInACounterStyleIdent,
42
43 DocumentAtRuleUrlMatchingFunctionWasInvalid,
45 BadUrlInDeclarationValueBlock(CowRcStr<'i>),
46 BadStringInDeclarationValueBlock(CowRcStr<'i>),
47 UnbalancedCloseParenthesisInDeclarationValueBlock,
48 UnbalancedCloseSquareBracketInDeclarationValueBlock,
49 UnbalancedCloseCurlyBracketInDeclarationValueBlock,
50
51 UnsupportedFontFaceProperty(CowRcStr<'i>),
53
54 InvalidFontLanguageOverrideIdentifier(CowRcStr<'i>),
56 InvalidFontLanguageOverrideOpenTypeLanguageTag(CowRcStr<'i>),
57 FontFeatureSettingOpenTypeFeatureTagMustBeFourCharacters(CowRcStr<'i>),
58 FontFeatureSettingOpenTypeFeatureTagMustBePrintableAscii(CowRcStr<'i>),
59 FontFeatureSettingIfNotAnIntegerMustBeOnOrOff(CowRcStr<'i>),
60 FontFeatureSettingIntegerMustBePositive(i32),
61 FontFaceAtRuleFontWeightWasNotAValidIdentifierOrInteger,
62 FontFaceAtRuleFontFamilyCanNotBeGeneric,
63
64 AtRuleImportMustBeBeforeAnyRuleExceptAtRuleCharset,
66
67 KeyframePercentageWasNotBetweenZeroAndOneInclusive(f32),
69 ImportantIsNotAllowedInKeyframePropertyDeclarationValues,
70 UnexpectedTokenWhenParsingZoom(Token<'i>),
71
72 InvalidMediaType(CowRcStr<'i>),
74 DeprecatedMediaType(CowRcStr<'i>),
75 UnrecognisedMediaType(CowRcStr<'i>),
76 DeprecatedMediaQueryExpression(CowRcStr<'i>),
77 UnsupportedMediaQueryExpression(CowRcStr<'i>),
78 RatioNumeratorCanNotBeNegativeOrZero(i32),
79 RatioDivisorCanNotBeNegativeOrZero(i32),
80 MediaGridMustBeEitherZeroOrOne(i32),
81 MediaTransform3DMustBeEitherZeroOrOne(i32),
82 MediaTypeIsOnlyOptionalIfQualifiedIsNotSpecified,
83
84 AtRuleNamespaceMustBeBeforeAnyRuleExceptAtRuleCharsetAndAtRuleImport,
86 UnexpectedTokenForAtNamespaceRuleNamespaceValue(Token<'i>),
87
88 InvalidPageSelectorPseudoClass(CowRcStr<'i>),
90 FontRelativeLengthsAreNotAllowedInAPageAtRule,
91 ViewportLengthsAreNotAllowedInAPageAtRule,
92
93 InvalidSupportsCondition(CowRcStr<'i>),
95
96 UnexpectedViewportProperty(CowRcStr<'i>),
98
99 SpecificSelectorParseError(Box<SelectorParseError<'i>>),
101 ThereAreNoSelectors,
102 SelectorIsInvalidInContext(String),
103 UnsupportedPseudoClassOrElement(String),
104 NonTreeStructuralPseudoClassScopeIsObsoleteAsOfFirefox55,
105
106 UnexpectedCustomIdent(CowRcStr<'i>),
108 CustomIdentWasExcluded(CowRcStr<'i>),
109
110 CouldNotParseCssSignedNumber(
112 crate::domain::numbers::CssNumberConversionError,
113 f32,
114 ),
115 CouldNotParseCssUnsignedNumber(
116 crate::domain::numbers::CssNumberConversionError,
117 f32,
118 ),
119 CouldNotParseDimensionLessNumber(f32),
120 CouldNotParseDimension(f32, CowRcStr<'i>),
121 UnsignedIntegersCanNotBeNegative(i32),
122 UnsignedIntegersCanNotBeFloats(f32),
123
124 UnknownFunctionInValueExpression(CowRcStr<'i>),
126 CssVariablesInVarExpressionsMustStartWithTwoDashes(CowRcStr<'i>),
127
128 SelectorParseErrorKind(SelectorParseErrorKind<'i>),
130}
131
132impl<'i> CustomParseError<'i> {
133 #[inline(always)]
134 pub(crate) fn unexpectedToken<T>(
135 unexpectedToken: &Token<'i>,
136 ) -> Result<T, ParseError<'i, CustomParseError<'i>>> {
137 Err(ParseError {
138 kind: ParseErrorKind::Basic(BasicParseErrorKind::UnexpectedToken(
139 unexpectedToken.clone(),
140 )),
141 location: SourceLocation { line: 0, column: 0 },
142 })
143 }
144
145 #[inline(always)]
146 pub(crate) fn dimensionless<T>(
147 value: f32,
148 ) -> Result<T, ParseError<'i, CustomParseError<'i>>> {
149 Err(ParseError {
150 kind: ParseErrorKind::Custom(
151 CustomParseError::CouldNotParseDimensionLessNumber(value),
152 ),
153 location: SourceLocation {
154 line: value as u32,
155 column: 0,
156 },
157 })
158 }
159}
160
161impl<'i> From<CustomParseError<'i>> for ParseError<'i, CustomParseError<'i>> {
162 fn from(error: CustomParseError) -> ParseError<CustomParseError> {
163 ParseError {
164 kind: ParseErrorKind::Custom(error),
165 location: SourceLocation { line: 0, column: 0 },
166 }
167 }
168}
169
170impl<'i> From<SelectorParseErrorKind<'i>> for CustomParseError<'i> {
171 fn from(error: SelectorParseErrorKind) -> CustomParseError {
172 CustomParseError::SelectorParseErrorKind(error)
173 }
174}