oak_rust/parser/element_type.rs
1use oak_core::{ElementType, UniversalElementRole};
2
3#[cfg(feature = "serde")]
4use serde::{Deserialize, Serialize};
5
6/// Rust element types.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9pub enum RustElementType {
10 /// `as`
11 As,
12 /// `break`
13 Break,
14 /// `const`
15 Const,
16 /// `continue`
17 Continue,
18 /// `crate`
19 Crate,
20 /// `else`
21 Else,
22 /// `enum`
23 Enum,
24 /// `extern`
25 Extern,
26 /// `false`
27 False,
28 /// `fn`
29 Fn,
30 /// `for`
31 For,
32 /// `if`
33 If,
34 /// `impl`
35 Impl,
36 /// `in`
37 In,
38 /// `let`
39 Let,
40 /// `loop`
41 Loop,
42 /// `match`
43 Match,
44 /// `mod`
45 Mod,
46 /// `move`
47 Move,
48 /// `mut`
49 Mut,
50 /// `pub`
51 Pub,
52 /// `ref`
53 Ref,
54 /// `return`
55 Return,
56 /// `self`
57 SelfLower,
58 /// `Self`
59 SelfUpper,
60 /// `static`
61 Static,
62 /// `struct`
63 Struct,
64 /// `super`
65 Super,
66 /// `trait`
67 Trait,
68 /// `true`
69 True,
70 /// `type`
71 Type,
72 /// `unsafe`
73 Unsafe,
74 /// `use`
75 Use,
76 /// `where`
77 Where,
78 /// `while`
79 While,
80 /// `abstract`
81 Abstract,
82 /// `become`
83 Become,
84 /// `box`
85 Box,
86 /// `do`
87 Do,
88 /// `final`
89 Final,
90 /// `macro`
91 Macro,
92 /// `override`
93 Override,
94 /// `priv`
95 Priv,
96 /// `typeof`
97 Typeof,
98 /// `unsized`
99 Unsized,
100 /// `virtual`
101 Virtual,
102 /// `yield`
103 Yield,
104 /// `async`
105 Async,
106 /// `await`
107 Await,
108 /// `dyn`
109 Dyn,
110 /// `try`
111 Try,
112 /// `union`
113 Union,
114 /// `raw`
115 Raw,
116 /// Integer literal
117 IntegerLiteral,
118 /// Float literal
119 FloatLiteral,
120 /// String literal
121 StringLiteral,
122 /// Char literal
123 CharLiteral,
124 /// Byte literal
125 ByteLiteral,
126 /// Byte string literal
127 ByteStringLiteral,
128 /// Raw string literal
129 RawStringLiteral,
130 /// Bool literal
131 BoolLiteral,
132 /// Identifier
133 Identifier,
134 /// Lifetime
135 Lifetime,
136 /// `(`
137 LeftParen,
138 /// `)`
139 RightParen,
140 /// `{`
141 LeftBrace,
142 /// `}`
143 RightBrace,
144 /// `[`
145 LeftBracket,
146 /// `]`
147 RightBracket,
148 /// `;`
149 Semicolon,
150 /// `,`
151 Comma,
152 /// `.`
153 Dot,
154 /// `..`
155 DotDot,
156 /// `...`
157 DotDotDot,
158 /// `..=`
159 DotDotEq,
160 /// `:`
161 Colon,
162 /// `::`
163 DoubleColon,
164 /// Path separator
165 PathSep,
166 /// `?`
167 Question,
168 /// `@`
169 At,
170 /// `#`
171 Hash,
172 /// `$`
173 Dollar,
174 /// `+`
175 Plus,
176 /// `-`
177 Minus,
178 /// `*`
179 Star,
180 /// `/`
181 Slash,
182 /// `%`
183 Percent,
184 /// `^`
185 Caret,
186 /// `&`
187 Ampersand,
188 /// `|`
189 Pipe,
190 /// `~`
191 Tilde,
192 /// `!`
193 Bang,
194 /// `=`
195 Eq,
196 /// `<`
197 Lt,
198 /// `>`
199 Gt,
200 /// `<`
201 LessThan,
202 /// `>`
203 GreaterThan,
204 /// `==`
205 EqEq,
206 /// `!=`
207 Ne,
208 /// `<=`
209 Le,
210 /// `>=`
211 Ge,
212 /// `<=`
213 LessEq,
214 /// `>=`
215 GreaterEq,
216 /// `&&`
217 AndAnd,
218 /// `||`
219 OrOr,
220 /// `<<`
221 LeftShift,
222 /// `>>`
223 RightShift,
224 /// `<<`
225 Shl,
226 /// `>>`
227 Shr,
228 /// `+=`
229 PlusEq,
230 /// `-=`
231 MinusEq,
232 /// `*=`
233 StarEq,
234 /// `/=`
235 SlashEq,
236 /// `%=`
237 PercentEq,
238 /// `^=`
239 CaretEq,
240 /// `&=`
241 AndEq,
242 /// `|=`
243 OrEq,
244 /// `<<=`
245 ShlEq,
246 /// `>>=`
247 ShrEq,
248 /// `<<=`
249 LeftShiftEq,
250 /// `>>=`
251 RightShiftEq,
252 /// `=`
253 Assign,
254 /// `+=`
255 PlusAssign,
256 /// `-=`
257 MinusAssign,
258 /// `*=`
259 StarAssign,
260 /// `/=`
261 SlashAssign,
262 /// `%=`
263 PercentAssign,
264 /// `&=`
265 AmpAssign,
266 /// `|=`
267 PipeAssign,
268 /// `^=`
269 CaretAssign,
270 /// `<<=`
271 ShlAssign,
272 /// `>>=`
273 ShrAssign,
274 /// `->`
275 Arrow,
276 /// `=>`
277 FatArrow,
278 /// Space
279 Space,
280 /// Newline
281 Newline,
282 /// Whitespace
283 Whitespace,
284 /// Line comment
285 LineComment,
286 /// Block comment
287 BlockComment,
288 /// Doc comment
289 DocComment,
290 /// `++`
291 PlusPlus,
292 /// `--`
293 MinusMinus,
294 /// End of stream
295 Eof,
296 /// Error
297 Error,
298
299 // Expressions
300 /// Identifier expression
301 IdentifierExpression,
302 /// Literal expression
303 LiteralExpression,
304 /// Parenthesized expression
305 ParenthesizedExpression,
306 /// Unary expression
307 UnaryExpression,
308 /// Binary expression
309 BinaryExpression,
310 /// Call expression
311 CallExpression,
312 /// Index expression
313 IndexExpression,
314 /// Field expression
315 FieldExpression,
316
317 // Items and Statements
318 /// Source file
319 SourceFile,
320 /// Function
321 Function,
322 /// Return type
323 ReturnType,
324 /// Use item
325 UseItem,
326 /// Module item
327 ModuleItem,
328 /// Struct item
329 StructItem,
330 /// Enum item
331 EnumItem,
332 /// Let statement
333 LetStatement,
334 /// If expression
335 IfExpression,
336 /// While expression
337 WhileExpression,
338 /// Loop expression
339 LoopExpression,
340 /// For expression
341 ForExpression,
342 /// Return statement
343 ReturnStatement,
344 /// Block
345 Block,
346 /// Parameter list
347 ParameterList,
348 /// Block expression
349 BlockExpression,
350
351 // Add missing variants used in builder
352 /// Parameter
353 Parameter,
354 /// Expression statement
355 ExpressionStatement,
356 /// Item statement
357 ItemStatement,
358 /// Pattern
359 Pattern,
360 /// Expression
361 Expression,
362 /// Argument list
363 ArgumentList,
364 /// Type alias
365 TypeAlias,
366 /// Member expression
367 MemberExpression,
368}
369
370impl ElementType for RustElementType {
371 type Role = UniversalElementRole;
372
373 fn role(&self) -> Self::Role {
374 match self {
375 Self::Error => UniversalElementRole::Error,
376 _ => UniversalElementRole::None,
377 }
378 }
379}
380
381impl From<crate::lexer::token_type::RustTokenType> for RustElementType {
382 fn from(token: crate::lexer::token_type::RustTokenType) -> Self {
383 unsafe { std::mem::transmute(token) }
384 }
385}