Skip to main content

oak_lua/parser/
element_type.rs

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