Skip to main content

oak_actionscript/parser/
element_type.rs

1use oak_core::{ElementType, UniversalElementRole};
2
3/// Element types for ActionScript.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub enum ActionScriptElementType {
7    /// Whitespace.
8    Whitespace,
9    /// Newline.
10    Newline,
11    /// Comment.
12    Comment,
13    /// Identifier.
14    Identifier,
15    /// String literal.
16    StringLiteral,
17    /// Character literal.
18    CharLiteral,
19    /// Number literal.
20    NumberLiteral,
21    /// Boolean literal.
22    BooleanLiteral,
23    /// Null literal.
24    NullLiteral,
25    /// `as` keyword.
26    As,
27    /// `break` keyword.
28    Break,
29    /// `case` keyword.
30    Case,
31    /// `catch` keyword.
32    Catch,
33    /// `class` keyword.
34    Class,
35    /// `const` keyword.
36    Const,
37    /// `continue` keyword.
38    Continue,
39    /// `default` keyword.
40    Default,
41    /// `delete` keyword.
42    Delete,
43    /// `do` keyword.
44    Do,
45    /// `else` keyword.
46    Else,
47    /// `extends` keyword.
48    Extends,
49    /// `false` keyword.
50    False,
51    /// `finally` keyword.
52    Finally,
53    /// `for` keyword.
54    For,
55    /// `function` keyword.
56    Function,
57    /// `if` keyword.
58    If,
59    /// `implements` keyword.
60    Implements,
61    /// `import` keyword.
62    Import,
63    /// `in` keyword.
64    In,
65    /// `instanceof` keyword.
66    Instanceof,
67    /// `interface` keyword.
68    Interface,
69    /// `internal` keyword.
70    Internal,
71    /// `is` keyword.
72    Is,
73    /// `native` keyword.
74    Native,
75    /// `new` keyword.
76    New,
77    /// `null` keyword.
78    Null,
79    /// `package` keyword.
80    Package,
81    /// `private` keyword.
82    Private,
83    /// `protected` keyword.
84    Protected,
85    /// `public` keyword.
86    Public,
87    /// `return` keyword.
88    Return,
89    /// `static` keyword.
90    Static,
91    /// `super` keyword.
92    Super,
93    /// `switch` keyword.
94    Switch,
95    /// `this` keyword.
96    This,
97    /// `throw` keyword.
98    Throw,
99    /// `true` keyword.
100    True,
101    /// `try` keyword.
102    Try,
103    /// `typeof` keyword.
104    Typeof,
105    /// `use` keyword.
106    Use,
107    /// `var` keyword.
108    Var,
109    /// `void` keyword.
110    Void,
111    /// `while` keyword.
112    While,
113    /// `with` keyword.
114    With,
115    /// `each` keyword.
116    Each,
117    /// `get` keyword.
118    Get,
119    /// `set` keyword.
120    Set,
121    /// `namespace` keyword.
122    Namespace,
123    /// `include` keyword.
124    Include,
125    /// `dynamic` keyword.
126    Dynamic,
127    /// `final` keyword.
128    Final,
129    /// `override` keyword.
130    Override,
131    /// `Array` type.
132    Array,
133    /// `Boolean` type.
134    Boolean,
135    /// `Date` type.
136    Date,
137    /// `Number` type.
138    Number,
139    /// `Object` type.
140    ObjectType,
141    /// `RegExp` type.
142    RegExp,
143    /// `String` type.
144    StringType,
145    /// `uint` type.
146    Uint,
147    /// `Vector` type.
148    Vector,
149    /// `void` type.
150    VoidType,
151    /// `XML` type.
152    Xml,
153    /// `XMLList` type.
154    XmlList,
155    /// `+`.
156    Plus,
157    /// `-`.
158    Minus,
159    /// `*`.
160    Star,
161    /// `/`.
162    Slash,
163    /// `%`.
164    Percent,
165    /// `=`.
166    Equal,
167    /// `==`.
168    EqualEqual,
169    /// `===`.
170    EqualEqualEqual,
171    /// `!=`.
172    NotEqual,
173    /// `!==`.
174    NotEqualEqual,
175    /// `<`.
176    LessThan,
177    /// `<=`.
178    LessEqual,
179    /// `>`.
180    GreaterThan,
181    /// `>=`.
182    GreaterEqual,
183    /// `&&`.
184    LogicalAnd,
185    /// `||`.
186    LogicalOr,
187    /// `!`.
188    LogicalNot,
189    /// `&`.
190    BitwiseAnd,
191    /// `|`.
192    BitwiseOr,
193    /// `^`.
194    BitwiseXor,
195    /// `~`.
196    BitwiseNot,
197    /// `<<`.
198    LeftShift,
199    /// `>>`.
200    RightShift,
201    /// `>>>`.
202    UnsignedRightShift,
203    /// `++`.
204    Increment,
205    /// `--`.
206    Decrement,
207    /// `+=`.
208    PlusAssign,
209    /// `-=`.
210    MinusAssign,
211    /// `*=`.
212    StarAssign,
213    /// `/=`.
214    SlashAssign,
215    /// `%=`.
216    PercentAssign,
217    /// `<<=`.
218    LeftShiftAssign,
219    /// `>>=`.
220    RightShiftAssign,
221    /// `>>>=`.
222    UnsignedRightShiftAssign,
223    /// `&=`.
224    BitwiseAndAssign,
225    /// `|=`.
226    BitwiseOrAssign,
227    /// `^=`.
228    BitwiseXorAssign,
229    /// `?`.
230    Question,
231    /// `:`.
232    Colon,
233    /// `.`.
234    Dot,
235    /// `->`.
236    Arrow,
237    /// `(`.
238    LeftParen,
239    /// `)`.
240    RightParen,
241    /// `{`.
242    LeftBrace,
243    /// `}`.
244    RightBrace,
245    /// `[`.
246    LeftBracket,
247    /// `]`.
248    RightBracket,
249    /// `;`.
250    Semicolon,
251    /// `,`.
252    Comma,
253    /// `@`.
254    At,
255    /// `#`.
256    Hash,
257    /// `$`.
258    Dollar,
259    /// `&`.
260    Ampersand,
261    /// `\`.
262    Backslash,
263    /// `'`.
264    Quote,
265    /// `"`.
266    DoubleQuote,
267    /// `` ` ``.
268    Backtick,
269    /// End of file.
270    Eof,
271    /// A program.
272    Program,
273    /// A block.
274    Block,
275    /// A variable declaration.
276    Variable,
277    /// A function call.
278    FunctionCall,
279    /// A method call.
280    MethodCall,
281    /// A property access.
282    PropertyAccess,
283    /// An array access.
284    ArrayAccess,
285    /// A parameter list.
286    ParameterList,
287    /// A use item.
288    UseItem,
289    /// A module item.
290    ModuleItem,
291    /// A struct item.
292    StructItem,
293    /// An enum item.
294    EnumItem,
295    /// A function type.
296    FunctionType,
297    /// The root node.
298    Root,
299    /// A statement.
300    Statement,
301    /// An expression.
302    Expression,
303    /// An assignment expression.
304    Assignment,
305    /// A conditional expression.
306    ConditionalExpression,
307    /// A binary expression.
308    BinaryExpression,
309    /// A unary expression.
310    UnaryExpression,
311    /// An if statement.
312    IfStatement,
313    /// A for statement.
314    ForStatement,
315    /// A while statement.
316    WhileStatement,
317    /// A do-while statement.
318    DoWhileStatement,
319    /// A switch statement.
320    SwitchStatement,
321    /// A try statement.
322    TryStatement,
323    /// A throw statement.
324    ThrowStatement,
325    /// A return statement.
326    ReturnStatement,
327    /// A break statement.
328    BreakStatement,
329    /// A continue statement.
330    ContinueStatement,
331    /// An error node.
332    Error,
333    /// A literal expression.
334    LiteralExpression,
335    /// An identifier expression.
336    IdentifierExpression,
337    /// A parenthesized expression.
338    ParenthesizedExpression,
339    /// A source file.
340    SourceFile,
341    /// A block expression.
342    BlockExpression,
343    /// A let statement.
344    LetStatement,
345    /// An if expression.
346    IfExpression,
347    /// A while expression.
348    WhileExpression,
349    /// A loop expression.
350    LoopExpression,
351    /// A for expression.
352    ForExpression,
353    /// A call expression.
354    CallExpression,
355    /// An index expression.
356    IndexExpression,
357    /// A field expression.
358    FieldExpression,
359}
360
361impl ElementType for ActionScriptElementType {
362    type Role = UniversalElementRole;
363
364    fn role(&self) -> Self::Role {
365        match self {
366            Self::Root => UniversalElementRole::Root,
367            Self::SourceFile => UniversalElementRole::Root,
368            Self::Error => UniversalElementRole::Error,
369            _ => UniversalElementRole::None,
370        }
371    }
372}
373
374impl From<crate::lexer::token_type::ActionScriptTokenType> for ActionScriptElementType {
375    fn from(token: crate::lexer::token_type::ActionScriptTokenType) -> Self {
376        unsafe { std::mem::transmute(token) }
377    }
378}