Skip to main content

oak_d/parser/
element_type.rs

1//! Element types for the D parser.
2
3use oak_core::{ElementType, UniversalElementRole};
4
5/// Element types for the D programming language.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub enum DElementType {
9    /// The root of the parse tree.
10    Root,
11    /// A module declaration.
12    Module,
13    /// A declaration.
14    Declaration,
15    /// A statement.
16    Statement,
17    /// An expression.
18    Expression,
19    /// A type.
20    Type,
21    /// An aggregate (class, struct, etc.).
22    Aggregate,
23    /// An import declaration.
24    Import,
25    /// A class definition.
26    Class,
27    /// A struct definition.
28    Struct,
29    /// An interface definition.
30    Interface,
31    /// A function definition.
32    Function,
33    /// A block statement.
34    Block,
35    /// An if statement.
36    IfStatement,
37    /// A while statement.
38    WhileStatement,
39    /// A for statement.
40    ForStatement,
41    /// A return statement.
42    ReturnStatement,
43    /// An expression statement.
44    ExpressionStatement,
45    /// A literal value.
46    Literal,
47    /// A parenthesized expression.
48    ParenthesizedExpression,
49    /// A binary expression.
50    BinaryExpression,
51    /// The `module` keyword.
52    ModuleKeyword,
53    /// The `import` keyword.
54    ImportKeyword,
55    /// The `public` keyword.
56    PublicKeyword,
57    /// The `private` keyword.
58    PrivateKeyword,
59    /// The `protected` keyword.
60    ProtectedKeyword,
61    /// The `package` keyword.
62    PackageKeyword,
63    /// The `export` keyword.
64    ExportKeyword,
65    /// The `static` keyword.
66    StaticKeyword,
67    /// The `final` keyword.
68    FinalKeyword,
69    /// The `abstract` keyword.
70    AbstractKeyword,
71    /// The `override` keyword.
72    OverrideKeyword,
73    /// The `synchronized` keyword.
74    SynchronizedKeyword,
75    /// The `const` keyword.
76    ConstKeyword,
77    /// The `immutable` keyword.
78    ImmutableKeyword,
79    /// The `inout` keyword.
80    InoutKeyword,
81    /// The `shared` keyword.
82    SharedKeyword,
83    /// The `class` keyword.
84    ClassKeyword,
85    /// The `struct` keyword.
86    StructKeyword,
87    /// The `interface` keyword.
88    InterfaceKeyword,
89    /// The `union` keyword.
90    UnionKeyword,
91    /// The `enum` keyword.
92    EnumKeyword,
93    /// The `function` keyword.
94    FunctionKeyword,
95    /// The `delegate` keyword.
96    DelegateKeyword,
97    /// The `if` keyword.
98    IfKeyword,
99    /// The `else` keyword.
100    ElseKeyword,
101    /// The `while` keyword.
102    WhileKeyword,
103    /// The `for` keyword.
104    ForKeyword,
105    /// The `foreach` keyword.
106    ForeachKeyword,
107    /// The `do` keyword.
108    DoKeyword,
109    /// The `switch` keyword.
110    SwitchKeyword,
111    /// The `case` keyword.
112    CaseKeyword,
113    /// The `default` keyword.
114    DefaultKeyword,
115    /// The `break` keyword.
116    BreakKeyword,
117    /// The `continue` keyword.
118    ContinueKeyword,
119    /// The `return` keyword.
120    ReturnKeyword,
121    /// The `goto` keyword.
122    GotoKeyword,
123    /// The `try` keyword.
124    TryKeyword,
125    /// The `catch` keyword.
126    CatchKeyword,
127    /// The `finally` keyword.
128    FinallyKeyword,
129    /// The `throw` keyword.
130    ThrowKeyword,
131    /// The `scope` keyword.
132    ScopeKeyword,
133    /// The `with` keyword.
134    WithKeyword,
135    /// Another `synchronized` keyword variant.
136    SynchronizedKeyword2,
137    /// The `asm` keyword.
138    AsmKeyword,
139    /// The `mixin` keyword.
140    MixinKeyword,
141    /// The `template` keyword.
142    TemplateKeyword,
143    /// The `this` keyword.
144    ThisKeyword,
145    /// The `super` keyword.
146    SuperKeyword,
147    /// The `null` keyword.
148    NullKeyword,
149    /// The `true` keyword.
150    TrueKeyword,
151    /// The `false` keyword.
152    FalseKeyword,
153    /// The `cast` keyword.
154    CastKeyword,
155    /// The `new` keyword.
156    NewKeyword,
157    /// The `delete` keyword.
158    DeleteKeyword,
159    /// The `typeof` keyword.
160    TypeofKeyword,
161    /// The `typeid` keyword.
162    TypeidKeyword,
163    /// The `is` keyword.
164    IsKeyword,
165    /// The `in` keyword.
166    InKeyword,
167    /// The `out` keyword.
168    OutKeyword,
169    /// The `ref` keyword.
170    RefKeyword,
171    /// The `lazy` keyword.
172    LazyKeyword,
173    /// The `auto` keyword.
174    AutoKeyword,
175    /// The `alias` keyword.
176    AliasKeyword,
177    /// The `typedef` keyword.
178    TypedefKeyword,
179    /// The `extern` keyword.
180    ExternKeyword,
181    /// The `pure` keyword.
182    PureKeyword,
183    /// The `nothrow` keyword.
184    NothrowKeyword,
185    /// The `safe` keyword.
186    SafeKeyword,
187    /// The `trusted` keyword.
188    TrustedKeyword,
189    /// The `system` keyword.
190    SystemKeyword,
191    /// The `nogc` keyword.
192    NogcKeyword,
193    /// The `property` keyword.
194    PropertyKeyword,
195    /// The `disable` keyword.
196    DisableKeyword,
197    /// The `deprecated` keyword.
198    DeprecatedKeyword,
199    /// The `version` keyword.
200    VersionKeyword,
201    /// The `debug` keyword.
202    DebugKeyword,
203    /// The `unittest` keyword.
204    UnitTestKeyword,
205    /// The `invariant` keyword.
206    InvariantKeyword,
207    /// The `body` keyword.
208    BodyKeyword,
209    /// The `pragma` keyword.
210    PragmaKeyword,
211    /// The `align` keyword.
212    AlignKeyword,
213    /// The `void` type.
214    VoidType,
215    /// The `bool` type.
216    BoolType,
217    /// The `byte` type.
218    ByteType,
219    /// The `ubyte` type.
220    UbyteType,
221    /// The `short` type.
222    ShortType,
223    /// The `ushort` type.
224    UshortType,
225    /// The `int` type.
226    IntType,
227    /// The `uint` type.
228    UintType,
229    /// The `long` type.
230    LongType,
231    /// The `ulong` type.
232    UlongType,
233    /// The `cent` type.
234    CentType,
235    /// The `ucent` type.
236    UcentType,
237    /// The `float` type.
238    FloatType,
239    /// The `double` type.
240    DoubleType,
241    /// The `real` type.
242    RealType,
243    /// The `ifloat` type.
244    IfloatType,
245    /// The `idouble` type.
246    IdoubleType,
247    /// The `ireal` type.
248    IrealType,
249    /// The `cfloat` type.
250    CfloatType,
251    /// The `cdouble` type.
252    CdoubleType,
253    /// The `creal` type.
254    CrealType,
255    /// The `char` type.
256    CharType,
257    /// The `wchar` type.
258    WcharType,
259    /// The `dchar` type.
260    DcharType,
261    /// The `string` type.
262    StringType,
263    /// The `wstring` type.
264    WstringType,
265    /// The `dstring` type.
266    DstringType,
267    /// The `+` operator.
268    Plus,
269    /// The `-` operator.
270    Minus,
271    /// The `*` operator.
272    Multiply,
273    /// The `/` operator.
274    Divide,
275    /// The `%` operator.
276    Modulo,
277    /// The `&` operator.
278    BitwiseAnd,
279    /// The `|` operator.
280    BitwiseOr,
281    /// The `^` operator.
282    BitwiseXor,
283    /// The `~` operator.
284    BitwiseNot,
285    /// The `<<` operator.
286    LeftShift,
287    /// The `>>` operator.
288    RightShift,
289    /// The `>>>` operator.
290    UnsignedRightShift,
291    /// The `==` operator.
292    Equal,
293    /// The `!=` operator.
294    NotEqual,
295    /// The `<` operator.
296    Less,
297    /// The `<=` operator.
298    LessEqual,
299    /// The `>` operator.
300    Greater,
301    /// The `>=` operator.
302    GreaterEqual,
303    /// The `is` operator.
304    Identity,
305    /// The `!is` operator.
306    NotIdentity,
307    /// The `=` operator.
308    Assign,
309    /// The `+=` operator.
310    PlusAssign,
311    /// The `-=` operator.
312    MinusAssign,
313    /// The `*=` operator.
314    MultiplyAssign,
315    /// The `/=` operator.
316    DivideAssign,
317    /// The `%=` operator.
318    ModuloAssign,
319    /// The `&=` operator.
320    BitwiseAndAssign,
321    /// The `|=` operator.
322    BitwiseOrAssign,
323    /// The `^=` operator.
324    BitwiseXorAssign,
325    /// The `<<=` operator.
326    LeftShiftAssign,
327    /// The `>>=` operator.
328    RightShiftAssign,
329    /// The `>>>=` operator.
330    UnsignedRightShiftAssign,
331    /// The `~=` operator.
332    ConcatenateAssign,
333    /// The `&&` operator.
334    LogicalAnd,
335    /// The `||` operator.
336    LogicalOr,
337    /// The `++` operator.
338    Increment,
339    /// The `--` operator.
340    Decrement,
341    /// The `!` operator.
342    Not,
343    /// The `?` operator.
344    Question,
345    /// The `$` operator.
346    Dollar,
347    /// The `@` operator.
348    At,
349    /// Opening parenthesis (`(`).
350    LeftParen,
351    /// Closing parenthesis (`)`).
352    RightParen,
353    /// Opening bracket (`[`).
354    LeftBracket,
355    /// Closing bracket (`]`).
356    RightBracket,
357    /// Opening brace (`{`).
358    LeftBrace,
359    /// Closing brace (`}`).
360    RightBrace,
361    /// Semicolon (`;`).
362    Semicolon,
363    /// Comma (`,`).
364    Comma,
365    /// Dot (`.`).
366    Dot,
367    /// Double dot (`..`).
368    DotDot,
369    /// Triple dot (`...`).
370    DotDotDot,
371    /// Colon (`:`).
372    Colon,
373    /// Arrow (`->`).
374    Arrow,
375    /// Hash (`#`).
376    Hash,
377    /// An integer literal.
378    IntegerLiteral,
379    /// A floating-point literal.
380    FloatLiteral,
381    /// A string literal.
382    StringLiteral,
383    /// A character literal.
384    CharLiteral,
385    /// An identifier.
386    Identifier,
387    /// A line comment.
388    LineComment,
389    /// A block comment.
390    BlockComment,
391    /// A nested comment.
392    NestedComment,
393    /// Whitespace.
394    Whitespace,
395    /// A newline.
396    Newline,
397    /// End of stream.
398    Eof,
399    /// An error.
400    Error,
401}
402
403impl ElementType for DElementType {
404    type Role = UniversalElementRole;
405
406    fn role(&self) -> Self::Role {
407        match self {
408            Self::Root => UniversalElementRole::Root,
409
410            Self::Error => UniversalElementRole::Error,
411            _ => UniversalElementRole::None,
412        }
413    }
414}
415
416impl From<crate::lexer::token_type::DTokenType> for DElementType {
417    fn from(token: crate::lexer::token_type::DTokenType) -> Self {
418        unsafe { std::mem::transmute(token) }
419    }
420}