1use oak_core::{Token, TokenType, UniversalTokenRole};
2
3pub type RustToken = Token<RustTokenType>;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9pub enum RustTokenType {
10 As,
12 Break,
14 Const,
16 Continue,
18 Crate,
20 Else,
22 Enum,
24 Extern,
26 False,
28 Fn,
30 For,
32 If,
34 Impl,
36 In,
38 Let,
40 Loop,
42 Match,
44 Mod,
46 Move,
48 Mut,
50 Pub,
52 Ref,
54 Return,
56 SelfLower,
58 SelfUpper,
60 Static,
62 Struct,
64 Super,
66 Trait,
68 True,
70 Type,
72 Unsafe,
74 Use,
76 Where,
78 While,
80 Abstract,
82 Become,
84 Box,
86 Do,
88 Final,
90 Macro,
92 Override,
94 Priv,
96 Typeof,
98 Unsized,
100 Virtual,
102 Yield,
104 Async,
106 Await,
108 Dyn,
110 Try,
112 Union,
114 Raw,
116 IntegerLiteral,
118 FloatLiteral,
120 StringLiteral,
122 CharLiteral,
124 ByteLiteral,
126 ByteStringLiteral,
128 RawStringLiteral,
130 BoolLiteral,
132 Identifier,
134 Lifetime,
136 LeftParen,
138 RightParen,
140 LeftBrace,
142 RightBrace,
144 LeftBracket,
146 RightBracket,
148 Semicolon,
150 Comma,
152 Dot,
154 DotDot,
156 DotDotDot,
158 DotDotEq,
160 Colon,
162 DoubleColon,
164 PathSep,
166 Question,
168 At,
170 Hash,
172 Dollar,
174 Plus,
176 Minus,
178 Star,
180 Slash,
182 Percent,
184 Caret,
186 Ampersand,
188 Pipe,
190 Tilde,
192 Bang,
194 Eq,
196 Lt,
198 Gt,
200 LessThan,
202 GreaterThan,
204 EqEq,
206 Ne,
208 Le,
210 Ge,
212 LessEq,
214 GreaterEq,
216 AndAnd,
218 OrOr,
220 LeftShift,
222 RightShift,
224 Shl,
226 Shr,
228 PlusEq,
230 MinusEq,
232 StarEq,
234 SlashEq,
236 PercentEq,
238 CaretEq,
240 AndEq,
242 OrEq,
244 ShlEq,
246 ShrEq,
248 LeftShiftEq,
250 RightShiftEq,
252 Underscore,
254 Assign,
256 PlusAssign,
258 MinusAssign,
260 StarAssign,
262 SlashAssign,
264 PercentAssign,
266 AmpAssign,
268 PipeAssign,
270 CaretAssign,
272 ShlAssign,
274 ShrAssign,
276 Arrow,
278 FatArrow,
280 Space,
282 Newline,
284 Whitespace,
286 LineComment,
288 BlockComment,
290 DocComment,
292 PlusPlus,
294 MinusMinus,
296 Eof,
298 Error,
300}
301
302impl RustTokenType {
303 pub fn is_literal(&self) -> bool {
305 matches!(self, Self::IntegerLiteral | Self::FloatLiteral | Self::StringLiteral | Self::CharLiteral | Self::ByteLiteral | Self::ByteStringLiteral | Self::RawStringLiteral | Self::BoolLiteral | Self::True | Self::False)
306 }
307}
308
309impl TokenType for RustTokenType {
310 type Role = UniversalTokenRole;
311 const END_OF_STREAM: Self = Self::Eof;
312
313 fn is_ignored(&self) -> bool {
314 matches!(self, Self::Whitespace | Self::Newline | Self::LineComment | Self::BlockComment)
315 }
316
317 fn role(&self) -> Self::Role {
318 match self {
319 Self::Whitespace => UniversalTokenRole::Whitespace,
320 Self::Newline => UniversalTokenRole::Whitespace,
321 Self::LineComment => UniversalTokenRole::Comment,
322 Self::BlockComment => UniversalTokenRole::Comment,
323 Self::Eof => UniversalTokenRole::Eof,
324 Self::Error => UniversalTokenRole::Error,
325 Self::As
326 | Self::Break
327 | Self::Const
328 | Self::Continue
329 | Self::Crate
330 | Self::Else
331 | Self::Enum
332 | Self::Extern
333 | Self::False
334 | Self::Fn
335 | Self::For
336 | Self::If
337 | Self::Impl
338 | Self::In
339 | Self::Let
340 | Self::Loop
341 | Self::Match
342 | Self::Mod
343 | Self::Move
344 | Self::Mut
345 | Self::Pub
346 | Self::Ref
347 | Self::Return
348 | Self::SelfLower
349 | Self::SelfUpper
350 | Self::Static
351 | Self::Struct
352 | Self::Super
353 | Self::Trait
354 | Self::True
355 | Self::Type
356 | Self::Unsafe
357 | Self::Use
358 | Self::Where
359 | Self::While => UniversalTokenRole::Keyword,
360 Self::Identifier => UniversalTokenRole::Name,
361 Self::IntegerLiteral | Self::FloatLiteral | Self::StringLiteral | Self::CharLiteral | Self::ByteLiteral | Self::ByteStringLiteral | Self::RawStringLiteral | Self::BoolLiteral => UniversalTokenRole::Literal,
362 _ => UniversalTokenRole::None,
363 }
364 }
365}