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