Skip to main content

oak_actionscript/parser/
element_type.rs

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