oak_csharp/parser/
element_type.rs

1use crate::lexer::CSharpTokenType;
2use oak_core::{ElementType, UniversalElementRole};
3use serde::{Deserialize, Serialize};
4
5/// C# element type
6#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
7pub enum CSharpElementType {
8    /// Root node of the syntax tree
9    Root,
10    /// Compilation unit (source file)
11    CompilationUnit,
12    /// Namespace declaration
13    NamespaceDeclaration,
14    /// Using directive
15    UsingDirective,
16    /// Class declaration
17    ClassDeclaration,
18    /// Struct declaration
19    StructDeclaration,
20    /// Interface declaration
21    InterfaceDeclaration,
22    /// Enum declaration
23    EnumDeclaration,
24    /// Delegate declaration
25    DelegateDeclaration,
26    /// Method declaration
27    MethodDeclaration,
28    /// Property declaration
29    PropertyDeclaration,
30    /// Field declaration
31    FieldDeclaration,
32    /// Event declaration
33    EventDeclaration,
34    /// Indexer declaration
35    IndexerDeclaration,
36    /// Constructor declaration
37    ConstructorDeclaration,
38    /// Destructor declaration
39    DestructorDeclaration,
40    /// Operator declaration
41    OperatorDeclaration,
42    /// Conversion operator declaration
43    ConversionOperatorDeclaration,
44    /// Parameter
45    Parameter,
46    /// Type parameter
47    TypeParameter,
48    /// Constraint
49    Constraint,
50    /// Attribute
51    Attribute,
52    /// Attribute list
53    AttributeList,
54    /// Block statement
55    Block,
56    /// Expression statement
57    ExpressionStatement,
58    /// If statement
59    IfStatement,
60    /// Switch statement
61    SwitchStatement,
62    /// While statement
63    WhileStatement,
64    /// For statement
65    ForStatement,
66    /// Foreach statement
67    ForeachStatement,
68    /// Do-while statement
69    DoStatement,
70    /// Try statement
71    TryStatement,
72    /// Catch clause
73    CatchClause,
74    /// Finally clause
75    FinallyClause,
76    /// Throw statement
77    ThrowStatement,
78    /// Return statement
79    ReturnStatement,
80    /// Break statement
81    BreakStatement,
82    /// Continue statement
83    ContinueStatement,
84    /// Goto statement
85    GotoStatement,
86    /// Labeled statement
87    LabeledStatement,
88    /// Lock statement
89    LockStatement,
90    /// Using statement
91    UsingStatement,
92    /// Fixed statement
93    FixedStatement,
94    /// Unsafe statement
95    UnsafeStatement,
96    /// Checked statement
97    CheckedStatement,
98    /// Unchecked statement
99    UncheckedStatement,
100    /// Yield statement
101    YieldStatement,
102    /// Local declaration statement
103    LocalDeclarationStatement,
104    /// Binary expression
105    BinaryExpression,
106    /// Unary expression
107    UnaryExpression,
108    /// Assignment expression
109    AssignmentExpression,
110    /// Conditional expression (ternary)
111    ConditionalExpression,
112    /// Method invocation expression
113    InvocationExpression,
114    /// Member access expression
115    MemberAccessExpression,
116    /// Element access expression
117    ElementAccessExpression,
118    /// Cast expression
119    CastExpression,
120    /// As expression
121    AsExpression,
122    /// Is expression
123    IsExpression,
124    /// Typeof expression
125    TypeOfExpression,
126    /// Sizeof expression
127    SizeOfExpression,
128    /// Default value expression
129    DefaultExpression,
130    /// Literal expression
131    LiteralExpression,
132    /// This expression
133    ThisExpression,
134    /// Base expression
135    BaseExpression,
136    /// Identifier name
137    IdentifierName,
138    /// Qualified name
139    QualifiedName,
140    /// Generic name
141    GenericName,
142    /// Alias qualified name
143    AliasQualifiedName,
144    /// Predefined type
145    PredefinedType,
146    /// Array type
147    ArrayType,
148    /// Pointer type
149    PointerType,
150    /// Nullable type
151    NullableType,
152    /// Tuple type
153    TupleType,
154    /// Ref type
155    RefType,
156    /// Array creation expression
157    ArrayCreationExpression,
158    /// Implicit array creation expression
159    ImplicitArrayCreationExpression,
160    /// Stack alloc array creation expression
161    StackAllocArrayCreationExpression,
162    /// Object creation expression
163    ObjectCreationExpression,
164    /// Anonymous object creation expression
165    AnonymousObjectCreationExpression,
166    /// Array initializer expression
167    ArrayInitializerExpression,
168    /// Collection initializer expression
169    CollectionInitializerExpression,
170    /// Complex element initializer expression
171    ComplexElementInitializerExpression,
172    /// Object initializer expression
173    ObjectInitializerExpression,
174    /// Member initializer expression
175    MemberInitializerExpression,
176    /// Lambda expression
177    LambdaExpression,
178    /// Anonymous method expression
179    AnonymousMethodExpression,
180    /// Query expression
181    QueryExpression,
182    /// Query body
183    QueryBody,
184    /// From clause
185    FromClause,
186    /// Let clause
187    LetClause,
188    /// Where clause
189    WhereClause,
190    /// Join clause
191    JoinClause,
192    /// Join into clause
193    JoinIntoClause,
194    /// Order by clause
195    OrderByClause,
196    /// Ordering
197    Ordering,
198    /// Select clause
199    SelectClause,
200    /// Group clause
201    GroupClause,
202    /// Query continuation
203    QueryContinuation,
204    /// Omitted array size expression
205    OmittedArraySizeExpression,
206    /// Interpolated string expression
207    InterpolatedStringExpression,
208    /// Interpolated string text
209    InterpolatedStringText,
210    /// Interpolation
211    Interpolation,
212    /// Interpolation alignment clause
213    InterpolationAlignmentClause,
214    /// Interpolation format clause
215    InterpolationFormatClause,
216    /// Global statement
217    GlobalStatement,
218    /// Simple lambda expression
219    SimpleLambdaExpression,
220    /// Parenthesized lambda expression
221    ParenthesizedLambdaExpression,
222    /// Initializer expression
223    InitializerExpression,
224    /// Implicit element access
225    ImplicitElementAccess,
226    /// Postfix unary expression
227    PostfixUnaryExpression,
228    /// Prefix unary expression
229    PrefixUnaryExpression,
230    /// Await expression
231    AwaitExpression,
232    /// Name colon
233    NameColon,
234    /// Declaration expression
235    DeclarationExpression,
236    /// Tuple expression
237    TupleExpression,
238    /// Tuple element
239    TupleElement,
240    /// Single variable designation
241    SingleVariableDesignation,
242    /// Parenthesized variable designation
243    ParenthesizedVariableDesignation,
244    /// Discard designation
245    DiscardDesignation,
246    /// Ref expression
247    RefExpression,
248    /// Ref type expression
249    RefTypeExpression,
250    /// Ref value expression
251    RefValueExpression,
252    /// Make ref expression
253    MakeRefExpression,
254    /// Checked expression
255    CheckedExpression,
256    /// Unchecked expression
257    UncheckedExpression,
258    /// Default literal expression
259    DefaultLiteralExpression,
260    /// Conditional access expression
261    ConditionalAccessExpression,
262    /// Member binding expression
263    MemberBindingExpression,
264    /// Element binding expression
265    ElementBindingExpression,
266    ImplicitStackAllocArrayCreationExpression,
267    IsPatternExpression,
268    ThrowExpression,
269    WhenClause,
270    ConstantPattern,
271    DeclarationPattern,
272    VarPattern,
273    RecursivePattern,
274    PositionalPatternClause,
275    PropertyPatternClause,
276    Subpattern,
277    /// Switch expression
278    SwitchExpression,
279    /// Switch expression arm
280    SwitchExpressionArm,
281    /// Case pattern switch label
282    CasePatternSwitchLabel,
283    /// Case switch label
284    CaseSwitchLabel,
285    /// Discard pattern
286    DiscardPattern,
287    /// Tuple pattern
288    TuplePattern,
289    /// Parenthesized pattern
290    ParenthesizedPattern,
291    /// Relational pattern
292    RelationalPattern,
293    /// Type pattern
294    TypePattern,
295    /// Binary pattern
296    BinaryPattern,
297    /// Unary pattern
298    UnaryPattern,
299    /// Slice pattern
300    SlicePattern,
301    /// Range expression
302    RangeExpression,
303    /// Index expression
304    IndexExpression,
305    /// With expression
306    WithExpression,
307    /// Anonymous object member declarator
308    AnonymousObjectMemberDeclarator,
309    /// Argument list
310    ArgumentList,
311    /// Bracketed argument list
312    BracketedArgumentList,
313    /// Argument
314    Argument,
315    /// Name equals
316    NameEquals,
317    /// Type argument list
318    TypeArgumentList,
319    /// Type parameter list
320    TypeParameterList,
321    /// Type parameter constraint clause
322    TypeParameterConstraintClause,
323    /// Constructor constraint
324    ConstructorConstraint,
325    /// Class or struct constraint
326    ClassOrStructConstraint,
327    /// Type constraint
328    TypeConstraint,
329    /// Base list
330    BaseList,
331    /// Simple base type
332    SimpleBaseType,
333    /// Primary constructor base type
334    PrimaryConstructorBaseType,
335    /// Accessor list
336    AccessorList,
337    /// Accessor declaration
338    AccessorDeclaration,
339    /// Parameter list
340    ParameterList,
341    /// Bracketed parameter list
342    BracketedParameterList,
343    /// Arrow expression clause
344    ArrowExpressionClause,
345    /// Equals value clause
346    EqualsValueClause,
347    /// Variable declaration
348    VariableDeclaration,
349    /// Variable declarator
350    VariableDeclarator,
351    /// Separated syntax list
352    SeparatedSyntaxList,
353    /// Syntax list
354    SyntaxList,
355}
356
357impl ElementType for CSharpElementType {
358    type Role = UniversalElementRole;
359
360    fn role(&self) -> Self::Role {
361        UniversalElementRole::None
362    }
363}
364
365impl From<CSharpTokenType> for CSharpElementType {
366    fn from(token: CSharpTokenType) -> Self {
367        match token {
368            CSharpTokenType::Eof => Self::SyntaxList, // Default or Error?
369            _ => Self::SyntaxList,
370        }
371    }
372}