Skip to main content

oak_rust/parser/
element_type.rs

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