oak_valkyrie/parser/element_type.rs
1use oak_core::{ElementType, UniversalElementRole};
2
3use crate::lexer::token_type::ValkyrieTokenType;
4
5/// Element types for Valkyrie language syntax tree nodes.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub enum ValkyrieElementType {
9 /// Root node of the syntax tree.
10 Root,
11 /// End of file marker.
12 Eof,
13 /// Whitespace token.
14 Whitespace,
15 /// Newline token.
16 Newline,
17 /// Line comment token.
18 LineComment,
19 /// Block comment token.
20 BlockComment,
21 /// Error node.
22 Error,
23
24 // Nodes
25 /// Attribute node.
26 Attribute,
27 /// Name path node.
28 NamePath,
29 /// Type node.
30 Type,
31 /// Namespace node.
32 Namespace,
33 /// Class node.
34 Class,
35 /// Structure node (value type).
36 Structure,
37 /// Parameter list node.
38 ParameterList,
39 /// Block expression node.
40 BlockExpression,
41 /// Identifier expression node.
42 IdentifierExpression,
43 /// Path expression node.
44 PathExpression,
45
46 // Statements
47 /// Statement node.
48 Statement,
49 /// Let statement node.
50 LetStatement,
51 /// Expression statement node.
52 ExprStatement,
53
54 // Expressions
55 /// Expression node.
56 Expression,
57 /// Call expression node.
58 CallExpression,
59 /// Parameter node.
60 Param,
61 /// Return expression node.
62 ReturnExpression,
63 /// Literal expression node.
64 LiteralExpression,
65 /// Boolean literal node.
66 BooleanLiteral,
67 /// Binary expression node.
68 BinaryExpression,
69 /// Unary expression node.
70 UnaryExpression,
71 /// Parenthesized expression node.
72 ParenthesizedExpression,
73 /// Index expression node.
74 IndexExpression,
75 /// Offset expression node (cardinal indexing, 0-based).
76 OffsetExpression,
77 /// Field expression node.
78 FieldExpression,
79 /// If expression node.
80 IfExpression,
81 /// Match expression node.
82 MatchExpression,
83 /// Loop expression node.
84 LoopExpression,
85 /// Break expression node.
86 BreakExpression,
87 /// Continue expression node.
88 ContinueExpression,
89 /// Yield expression node.
90 YieldExpression,
91 /// Raise expression node.
92 RaiseExpression,
93 /// Catch expression node.
94 CatchExpression,
95 /// Resume expression node.
96 ResumeExpression,
97 /// With expression node (functional record update).
98 WithExpression,
99 /// Apply block node.
100 ApplyBlock,
101 /// Object expression node.
102 ObjectExpression,
103 /// Lambda expression node.
104 LambdaExpression,
105
106 // Definitions
107 /// Micro definition node.
108 Micro,
109 /// Mezzo definition node.
110 Mezzo,
111 /// Macro definition node.
112 Macro,
113 /// Struct definition node.
114 Struct,
115 /// Enum definition node.
116 Enum,
117 /// Enums definition node.
118 Enums,
119 /// Trait definition node.
120 Trait,
121 /// Associated type node.
122 AssociatedType,
123 /// Impl definition node.
124 Impl,
125 /// Field definition node.
126 Field,
127 /// Method definition node.
128 Method,
129 /// Variant definition node.
130 Variant,
131 /// Property definition node (getter/setter).
132 Property,
133 /// Flags definition node.
134 Flags,
135 /// Widget definition node.
136 Widget,
137 /// Singleton definition node.
138 Singleton,
139 /// Effect definition node.
140 EffectDefinition,
141 /// Using statement node.
142 UsingStatement,
143
144 // Template
145 /// Template text node.
146 TemplateText,
147 /// Template control node.
148 TemplateControl,
149 /// Interpolation node.
150 Interpolation,
151 /// Template comment node.
152 TemplateComment,
153
154 // Others
155 /// Pattern node.
156 Pattern,
157 /// Argument list node.
158 ArgList,
159 /// Generic parameter list node.
160 GenericParameterList,
161 /// Generic argument list node.
162 GenericArgumentList,
163 /// Match arm node.
164 MatchArm,
165 /// Parameter node.
166 Parameter,
167 /// Anonymous class node.
168 AnonymousClass,
169 /// Generic parameter node.
170 GenericParameter,
171 /// Super call expression node.
172 SuperCallExpression,
173}
174
175impl ElementType for ValkyrieElementType {
176 type Role = UniversalElementRole;
177
178 fn role(&self) -> Self::Role {
179 match self {
180 Self::Root => UniversalElementRole::Root,
181 Self::Error => UniversalElementRole::Error,
182 _ => UniversalElementRole::None,
183 }
184 }
185}
186
187impl From<ValkyrieTokenType> for ValkyrieElementType {
188 fn from(token: ValkyrieTokenType) -> Self {
189 match token {
190 ValkyrieTokenType::Eof => Self::Eof,
191 ValkyrieTokenType::Whitespace => Self::Whitespace,
192 ValkyrieTokenType::Newline => Self::Newline,
193 ValkyrieTokenType::LineComment => Self::LineComment,
194 ValkyrieTokenType::BlockComment => Self::BlockComment,
195 ValkyrieTokenType::Error => Self::Error,
196 _ => Self::Error,
197 }
198 }
199}