oak_lua/parser/element_type.rs
1use oak_core::{ElementType, Parser, UniversalElementRole};
2
3/// Element types for Lua.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6#[repr(u16)]
7pub enum LuaElementType {
8 /// The root element.
9 Root,
10 // Keywords
11 /// The `and` keyword.
12 And,
13 /// The `break` keyword.
14 Break,
15 /// The `do` keyword.
16 Do,
17 /// The `else` keyword.
18 Else,
19 /// The `elseif` keyword.
20 Elseif,
21 /// The `end` keyword.
22 End,
23 /// The `false` keyword.
24 False,
25 /// The `for` keyword.
26 For,
27 /// The `function` keyword.
28 Function,
29 /// The `goto` keyword.
30 Goto,
31 /// The `if` keyword.
32 If,
33 /// The `in` keyword.
34 In,
35 /// The `local` keyword.
36 Local,
37 /// The `nil` keyword.
38 Nil,
39 /// The `not` keyword.
40 Not,
41 /// The `or` keyword.
42 Or,
43 /// The `repeat` keyword.
44 Repeat,
45 /// The `return` keyword.
46 Return,
47 /// The `then` keyword.
48 Then,
49 /// The `true` keyword.
50 True,
51 /// The `until` keyword.
52 Until,
53 /// The `while` keyword.
54 While,
55
56 /// An identifier.
57 Identifier,
58 /// A numeric literal.
59 Number,
60 /// A string literal.
61 String,
62
63 /// The `+` operator.
64 Plus,
65 /// The `-` operator.
66 Minus,
67 /// The `*` operator.
68 Star,
69 /// The `/` operator.
70 Slash,
71 /// The `%` operator.
72 Percent,
73 /// The `^` operator.
74 Caret,
75 /// The `#` operator.
76 Hash,
77 /// The `&` operator.
78 Ampersand,
79 /// The `~` operator.
80 Tilde,
81 /// The `|` operator.
82 Pipe,
83 /// The `<<` operator.
84 LtLt,
85 /// The `>>` operator.
86 GtGt,
87 /// The `//` operator.
88 SlashSlash,
89 /// The `==` operator.
90 EqEq,
91 /// The `~=` operator.
92 TildeEq,
93 /// The `<=` operator.
94 LtEq,
95 /// The `>=` operator.
96 GtEq,
97 /// The `<` operator.
98 Lt,
99 /// The `>` operator.
100 Gt,
101 /// The `=` operator.
102 Eq,
103
104 /// The `(` punctuation.
105 LeftParen,
106 /// The `)` punctuation.
107 RightParen,
108 /// The `{` punctuation.
109 LeftBrace,
110 /// The `}` punctuation.
111 RightBrace,
112 /// The `[` punctuation.
113 LeftBracket,
114 /// The `]` punctuation.
115 RightBracket,
116 /// The `::` punctuation.
117 ColonColon,
118 /// The `;` punctuation.
119 Semicolon,
120 /// The `:` punctuation.
121 Colon,
122 /// The `,` punctuation.
123 Comma,
124 /// The `.` punctuation.
125 Dot,
126 /// The `..` punctuation.
127 DotDot,
128 /// The `...` punctuation.
129 DotDotDot,
130
131 /// Whitespace.
132 Whitespace,
133 /// Newline.
134 Newline,
135 /// A comment.
136 Comment,
137
138 /// End of stream marker.
139 EndOfStream,
140 /// Error marker.
141 Error,
142
143 /// A source file.
144 SourceFile,
145 /// A function declaration.
146 FunctionDeclaration,
147 /// A parameter list.
148 ParameterList,
149 /// A parameter.
150 Parameter,
151 /// A block statement.
152 BlockStatement,
153 /// A local statement.
154 LocalStatement,
155 /// An assignment statement.
156 AssignmentStatement,
157 /// An expression statement.
158 ExpressionStatement,
159 /// An if statement.
160 IfStatement,
161 /// A while statement.
162 WhileStatement,
163 /// A for statement.
164 ForStatement,
165 /// A repeat statement.
166 RepeatStatement,
167 /// A do statement.
168 DoStatement,
169 /// A break statement.
170 BreakStatement,
171 /// A return statement.
172 ReturnStatement,
173 /// A goto statement.
174 GotoStatement,
175 /// A label statement.
176 LabelStatement,
177 /// An identifier expression.
178 IdentifierExpression,
179 /// A literal expression.
180 LiteralExpression,
181 /// A boolean literal.
182 BooleanLiteral,
183 /// A nil literal.
184 NilLiteral,
185 /// A parenthesized expression.
186 ParenthesizedExpression,
187 /// A binary expression.
188 BinaryExpression,
189 /// A unary expression.
190 UnaryExpression,
191 /// A call expression.
192 CallExpression,
193 /// A member expression.
194 MemberExpression,
195 /// An index expression.
196 IndexExpression,
197 /// A table constructor expression.
198 TableConstructorExpression,
199 /// A function expression.
200 FunctionExpression,
201 /// A vararg expression.
202 VarargExpression,
203 /// A table field.
204 TableField,
205 /// A field.
206 Field,
207 /// A field list.
208 FieldList,
209 /// Argument list.
210 ArgumentList,
211 /// Variable list.
212 VariableList,
213 /// Expression list.
214 ExpressionList,
215 /// Name list.
216 NameList,
217 /// Function name.
218 FunctionName,
219 /// Function body.
220 FunctionBody,
221 /// Chunk statement.
222 ChunkStatement,
223 /// Statement list.
224 StatementList,
225}
226
227impl ElementType for LuaElementType {
228 type Role = UniversalElementRole;
229
230 fn role(&self) -> Self::Role {
231 match self {
232 _ => UniversalElementRole::None,
233 }
234 }
235}
236
237impl From<crate::lexer::token_type::LuaTokenType> for LuaElementType {
238 fn from(token: crate::lexer::token_type::LuaTokenType) -> Self {
239 unsafe { std::mem::transmute(token) }
240 }
241}