oak_hlsl/parser/element_type.rs
1use oak_core::{ElementType, Parser, UniversalElementRole};
2
3/// Element types for the HLSL (High-Level Shading Language) parser.
4///
5/// This enum represents all possible element types in HLSL,
6/// including data types, texture types, control flow keywords, operators, and AST nodes.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9#[repr(u8)]
10pub enum HlslElementType {
11 /// Whitespace token.
12 Whitespace,
13 /// Newline token.
14 Newline,
15
16 /// Comment token.
17 Comment,
18
19 /// String literal token.
20 StringLiteral,
21 /// Number literal token.
22 NumberLiteral,
23 /// Boolean literal token.
24 BooleanLiteral,
25
26 /// Identifier token.
27 Identifier,
28
29 /// Boolean data type `bool`.
30 Bool,
31 /// Integer data type `int`.
32 Int,
33 /// Unsigned integer data type `uint`.
34 Uint,
35 /// Half-precision floating-point data type `half`.
36 Half,
37 /// Single-precision floating-point data type `float`.
38 Float,
39 /// Double-precision floating-point data type `double`.
40 Double,
41 /// Minimum 16-bit float data type `min16float`.
42 Min16float,
43 /// Minimum 10-bit float data type `min10float`.
44 Min10float,
45 /// Minimum 16-bit integer data type `min16int`.
46 Min16int,
47 /// Minimum 12-bit integer data type `min12int`.
48 Min12int,
49 /// Minimum 16-bit unsigned integer data type `min16uint`.
50 Min16uint,
51
52 /// 2-component boolean vector `bool2`.
53 Bool2,
54 /// 3-component boolean vector `bool3`.
55 Bool3,
56 /// 4-component boolean vector `bool4`.
57 Bool4,
58 /// 2-component integer vector `int2`.
59 Int2,
60 /// 3-component integer vector `int3`.
61 Int3,
62 /// 4-component integer vector `int4`.
63 Int4,
64 /// 2-component unsigned integer vector `uint2`.
65 Uint2,
66 /// 3-component unsigned integer vector `uint3`.
67 Uint3,
68 /// 4-component unsigned integer vector `uint4`.
69 Uint4,
70 /// 2-component half-precision vector `half2`.
71 Half2,
72 /// 3-component half-precision vector `half3`.
73 Half3,
74 /// 4-component half-precision vector `half4`.
75 Half4,
76 /// 2-component float vector `float2`.
77 Float2,
78 /// 3-component float vector `float3`.
79 Float3,
80 /// 4-component float vector `float4`.
81 Float4,
82 /// 2-component double vector `double2`.
83 Double2,
84 /// 3-component double vector `double3`.
85 Double3,
86 /// 4-component double vector `double4`.
87 Double4,
88
89 /// 2x2 float matrix `float2x2`.
90 Float2x2,
91 /// 2x3 float matrix `float2x3`.
92 Float2x3,
93 /// 2x4 float matrix `float2x4`.
94 Float2x4,
95 /// 3x2 float matrix `float3x2`.
96 Float3x2,
97 /// 3x3 float matrix `float3x3`.
98 Float3x3,
99 /// 3x4 float matrix `float3x4`.
100 Float3x4,
101 /// 4x2 float matrix `float4x2`.
102 Float4x2,
103 /// 4x3 float matrix `float4x3`.
104 Float4x3,
105 /// 4x4 float matrix `float4x4`.
106 Float4x4,
107 /// 2x2 double matrix `double2x2`.
108 Double2x2,
109 /// 2x3 double matrix `double2x3`.
110 Double2x3,
111 /// 2x4 double matrix `double2x4`.
112 Double2x4,
113 /// 3x2 double matrix `double3x2`.
114 Double3x2,
115 /// 3x3 double matrix `double3x3`.
116 Double3x3,
117 /// 3x4 double matrix `double3x4`.
118 Double3x4,
119 /// 4x2 double matrix `double4x2`.
120 Double4x2,
121 /// 4x3 double matrix `double4x3`.
122 Double4x3,
123 /// 4x4 double matrix `double4x4`.
124 Double4x4,
125
126 /// 1D texture type `Texture1D`.
127 Texture1D,
128 /// 2D texture type `Texture2D`.
129 Texture2D,
130 /// 3D texture type `Texture3D`.
131 Texture3D,
132 /// Cubemap texture type `TextureCube`.
133 TextureCube,
134 /// 1D texture array type `Texture1DArray`.
135 Texture1DArray,
136 /// 2D texture array type `Texture2DArray`.
137 Texture2DArray,
138 /// Cubemap array type `TextureCubeArray`.
139 TextureCubeArray,
140 /// Multisampled 2D texture type `Texture2DMS`.
141 Texture2DMS,
142 /// Multisampled 2D texture array type `Texture2DMSArray`.
143 Texture2DMSArray,
144
145 /// Sampler type.
146 Sampler,
147 /// Sampler state type `SamplerState`.
148 SamplerState,
149 /// Comparison sampler state type `SamplerComparisonState`.
150 SamplerComparisonState,
151
152 /// Buffer type.
153 Buffer,
154 /// Structured buffer type `StructuredBuffer`.
155 StructuredBuffer,
156 /// Byte address buffer type `ByteAddressBuffer`.
157 ByteAddressBuffer,
158 /// Read-write buffer type `RWBuffer`.
159 RWBuffer,
160 /// Read-write structured buffer type `RWStructuredBuffer`.
161 RWStructuredBuffer,
162 /// Read-write byte address buffer type `RWByteAddressBuffer`.
163 RWByteAddressBuffer,
164 /// Append structured buffer type `AppendStructuredBuffer`.
165 AppendStructuredBuffer,
166 /// Consume structured buffer type `ConsumeStructuredBuffer`.
167 ConsumeStructuredBuffer,
168
169 /// If keyword `if`.
170 If,
171 /// Else keyword `else`.
172 Else,
173 /// For keyword `for`.
174 For,
175 /// While keyword `while`.
176 While,
177 /// Do keyword `do`.
178 Do,
179 /// Switch keyword `switch`.
180 Switch,
181 /// Case keyword `case`.
182 Case,
183 /// Default keyword `default`.
184 Default,
185 /// Break keyword `break`.
186 Break,
187 /// Continue keyword `continue`.
188 Continue,
189 /// Return keyword `return`.
190 Return,
191 /// Discard keyword `discard`.
192 Discard,
193
194 /// Static modifier `static`.
195 Static,
196 /// Const modifier `const`.
197 Const,
198 /// Uniform modifier `uniform`.
199 Uniform,
200 /// Varying modifier `varying`.
201 Varying,
202 /// Input parameter modifier `in`.
203 In,
204 /// Output parameter modifier `out`.
205 Out,
206 /// Input-output parameter modifier `inout`.
207 Inout,
208 /// Inline modifier `inline`.
209 Inline,
210 /// Extern modifier `extern`.
211 Extern,
212 /// Shared modifier `shared`.
213 Shared,
214 /// Group-shared modifier `groupshared`.
215 Groupshared,
216 /// Volatile modifier `volatile`.
217 Volatile,
218 /// Precise modifier `precise`.
219 Precise,
220 /// No interpolation modifier `nointerpolation`.
221 Nointerpolation,
222 /// Linear interpolation modifier `linear`.
223 Linear,
224 /// Centroid interpolation modifier `centroid`.
225 Centroid,
226 /// Sample interpolation modifier `sample`.
227 Sample,
228 /// No perspective modifier `noperspective`.
229 Noperspective,
230 /// Target modifier `target`.
231 Target,
232
233 /// Register semantic modifier `register`.
234 Register,
235 /// Pack offset modifier `packoffset`.
236 Packoffset,
237
238 /// Struct keyword `struct`.
239 Struct,
240 /// Constant buffer keyword `cbuffer`.
241 Cbuffer,
242 /// Texture buffer keyword `tbuffer`.
243 Tbuffer,
244 /// Technique keyword `technique`.
245 Technique,
246 /// Pass keyword `pass`.
247 Pass,
248 /// Interface keyword `interface`.
249 Interface,
250 /// Class keyword `class`.
251 Class,
252 /// Namespace keyword `namespace`.
253 Namespace,
254 /// Typedef keyword `typedef`.
255 Typedef,
256 /// Template keyword `template`.
257 Template,
258 /// Typename keyword `typename`.
259 Typename,
260 /// Using keyword `using`.
261 Using,
262 /// Sizeof keyword `sizeof`.
263 Sizeof,
264 /// Undef keyword `undef`.
265 Undef,
266
267 /// Include preprocessor directive `#include`.
268 Include,
269 /// Define preprocessor directive `#define`.
270 Define,
271 /// If preprocessor directive `#if`.
272 If_,
273 /// Ifdef preprocessor directive `#ifdef`.
274 Ifdef,
275 /// Ifndef preprocessor directive `#ifndef`.
276 Ifndef,
277 /// Else preprocessor directive `#else`.
278 Else_,
279 /// Elif preprocessor directive `#elif`.
280 Elif,
281 /// Endif preprocessor directive `#endif`.
282 Endif,
283 /// Line preprocessor directive `#line`.
284 Line,
285 /// Pragma preprocessor directive `#pragma`.
286 Pragma,
287
288 /// Plus operator `+`.
289 Plus,
290 /// Minus operator `-`.
291 Minus,
292 /// Multiply operator `*`.
293 Multiply,
294 /// Divide operator `/`.
295 Divide,
296 /// Modulo operator `%`.
297 Modulo,
298 /// Assignment operator `=`.
299 Assign,
300 /// Plus assignment operator `+=`.
301 PlusAssign,
302 /// Minus assignment operator `-=`.
303 MinusAssign,
304 /// Multiply assignment operator `*=`.
305 MultiplyAssign,
306 /// Divide assignment operator `/=`.
307 DivideAssign,
308 /// Modulo assignment operator `%=`.
309 ModuloAssign,
310 /// Equality operator `==`.
311 Equal,
312 /// Inequality operator `!=`.
313 NotEqual,
314 /// Less than operator `<`.
315 Less,
316 /// Greater than operator `>`.
317 Greater,
318 /// Less than or equal operator `<=`.
319 LessEqual,
320 /// Greater than or equal operator `>=`.
321 GreaterEqual,
322 /// Logical and operator `&&`.
323 LogicalAnd,
324 /// Logical or operator `||`.
325 LogicalOr,
326 /// Logical not operator `!`.
327 LogicalNot,
328 /// Bitwise and operator `&`.
329 BitwiseAnd,
330 /// Bitwise or operator `|`.
331 BitwiseOr,
332 /// Bitwise xor operator `^`.
333 BitwiseXor,
334 /// Bitwise not operator `~`.
335 BitwiseNot,
336 /// Left shift operator `<<`.
337 LeftShift,
338 /// Right shift operator `>>`.
339 RightShift,
340 /// Left shift assignment operator `<<=`.
341 LeftShiftAssign,
342 /// Right shift assignment operator `>>=`.
343 RightShiftAssign,
344 /// Bitwise and assignment operator `&=`.
345 BitwiseAndAssign,
346 /// Bitwise or assignment operator `|=`.
347 BitwiseOrAssign,
348 /// Bitwise xor assignment operator `^=`.
349 BitwiseXorAssign,
350 /// Increment operator `++`.
351 Increment,
352 /// Decrement operator `--`.
353 Decrement,
354 /// Dot operator `.`.
355 Dot,
356 /// Arrow operator `->`.
357 Arrow,
358 /// Conditional ternary operator `?:`.
359 Conditional,
360
361 /// Left parenthesis `(`.
362 LeftParen,
363 /// Right parenthesis `)`.
364 RightParen,
365 /// Left bracket `[`.
366 LeftBracket,
367 /// Right bracket `]`.
368 RightBracket,
369 /// Left brace `{`.
370 LeftBrace,
371 /// Right brace `}`.
372 RightBrace,
373 /// Semicolon `;`.
374 Semicolon,
375 /// Comma `,`.
376 Comma,
377 /// Colon `:`.
378 Colon,
379 /// Double colon `::`.
380 DoubleColon,
381 /// Question mark `?`.
382 Question,
383 /// Hash symbol `#`.
384 Hash,
385 /// At symbol `@`.
386 At,
387 /// Backslash symbol `\`.
388 Backslash,
389
390 /// End of file marker.
391 Eof,
392 /// Root node of the AST.
393 Root,
394 /// Function declaration node.
395 FunctionDeclaration,
396 /// Struct declaration node.
397 StructDeclaration,
398 /// Variable declaration node.
399 VariableDeclaration,
400 /// Parameter list node.
401 ParameterList,
402 /// Parameter node.
403 Parameter,
404 /// Code block node.
405 Block,
406 /// Statement node.
407 Statement,
408 /// Expression node.
409 Expression,
410 /// Error node.
411 Error,
412}
413
414impl ElementType for HlslElementType {
415 type Role = UniversalElementRole;
416
417 fn role(&self) -> Self::Role {
418 match self {
419 _ => UniversalElementRole::None,
420 }
421 }
422}
423
424impl From<crate::lexer::token_type::HlslTokenType> for HlslElementType {
425 fn from(token: crate::lexer::token_type::HlslTokenType) -> Self {
426 unsafe { std::mem::transmute(token) }
427 }
428}