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