1use oak_core::{TokenType, UniversalTokenRole};
2#[cfg(feature = "serde")]
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
7#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8pub enum CssTokenType {
9 Whitespace,
11 Newline,
13 Comment,
15
16 StringLiteral,
18 NumberLiteral,
20 ColorLiteral,
22 UrlLiteral,
24
25 Identifier,
27 ClassName,
29 IdSelector,
31 TagName,
33 PseudoClass,
35 PseudoElement,
37 AttributeName,
39 PropertyName,
41 FunctionName,
43
44 Important,
46 Inherit,
48 Initial,
50 Unset,
52 Auto,
54 None,
56 Normal,
58
59 Px,
61 Em,
63 Rem,
65 Percent,
67 Vh,
69 Vw,
71 Pt,
73 Cm,
75 Mm,
77 In,
79 Pc,
81 Ex,
83 Ch,
85 Vmin,
87 Vmax,
89
90 Colon,
92 Semicolon,
94 Comma,
96 Dot,
98 Hash,
100 Plus,
102 Minus,
104 Star,
106 Slash,
108 Equals,
110 Tilde,
112 Pipe,
114 Caret,
116 Dollar,
118 GreaterThan,
120
121 LeftParen,
123 RightParen,
125 LeftBrace,
127 RightBrace,
129 LeftBracket,
131 RightBracket,
133
134 AtImport,
136 AtMedia,
138 AtKeyframes,
140 AtFontFace,
142 AtCharset,
144 AtNamespace,
146 AtSupports,
148 AtPage,
150 AtDocument,
152 AtRule,
154
155 Eof,
157 Error,
159}
160
161impl TokenType for CssTokenType {
162 const END_OF_STREAM: Self = Self::Eof;
163 type Role = UniversalTokenRole;
164
165 fn is_ignored(&self) -> bool {
166 matches!(self, Self::Whitespace | Self::Newline | Self::Comment)
167 }
168
169 fn is_comment(&self) -> bool {
170 matches!(self, Self::Comment)
171 }
172
173 fn is_whitespace(&self) -> bool {
174 matches!(self, Self::Whitespace | Self::Newline)
175 }
176
177 fn role(&self) -> Self::Role {
178 match self {
179 Self::Whitespace | Self::Newline => UniversalTokenRole::Whitespace,
180 Self::Comment => UniversalTokenRole::Comment,
181 Self::StringLiteral | Self::NumberLiteral | Self::ColorLiteral | Self::UrlLiteral => UniversalTokenRole::Literal,
182 Self::Identifier | Self::ClassName | Self::IdSelector | Self::TagName | Self::PseudoClass | Self::PseudoElement | Self::AttributeName | Self::PropertyName | Self::FunctionName => UniversalTokenRole::Name,
183 Self::Important
184 | Self::Inherit
185 | Self::Initial
186 | Self::Unset
187 | Self::Auto
188 | Self::None
189 | Self::Normal
190 | Self::AtImport
191 | Self::AtMedia
192 | Self::AtKeyframes
193 | Self::AtFontFace
194 | Self::AtCharset
195 | Self::AtNamespace
196 | Self::AtSupports
197 | Self::AtPage
198 | Self::AtDocument => UniversalTokenRole::Keyword,
199 Self::Colon | Self::Semicolon | Self::Comma | Self::Dot | Self::Hash | Self::Plus | Self::Minus | Self::Star | Self::Slash | Self::Equals | Self::Tilde | Self::Pipe | Self::Caret | Self::Dollar | Self::GreaterThan => {
200 UniversalTokenRole::Operator
201 }
202 Self::LeftParen | Self::RightParen | Self::LeftBrace | Self::RightBrace | Self::LeftBracket | Self::RightBracket => UniversalTokenRole::Punctuation,
203 Self::Eof => UniversalTokenRole::Eof,
204 Self::Error => UniversalTokenRole::Error,
205 _ => UniversalTokenRole::None,
206 }
207 }
208}