oak_vbnet/parser/element_type.rs
1use oak_core::{ElementType, UniversalElementRole};
2
3/// VB.NET element types
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub enum VbNetElementType {
7 /// Root node
8 Root,
9 /// Expression
10 Expression,
11 /// Whitespace
12 Whitespace,
13 /// Newline
14 Newline,
15
16 /// Identifier
17 Identifier,
18 /// Integer literal
19 IntegerLiteral,
20 /// Float literal
21 FloatLiteral,
22 /// String literal
23 StringLiteral,
24 /// Character literal
25 CharLiteral,
26 /// Boolean literal
27 BooleanLiteral,
28 /// Date literal
29 DateLiteral,
30 /// Nothing literal
31 NothingLiteral,
32
33 /// Namespace declaration
34 Namespace,
35 /// Imports directive
36 Imports,
37 /// Class declaration
38 Class,
39 /// Interface declaration
40 Interface,
41 /// Structure declaration
42 Structure,
43 /// Enum declaration
44 Enum,
45 /// Module declaration
46 Module,
47 /// Delegate declaration
48 Delegate,
49 /// Event declaration
50 Event,
51 /// Function declaration
52 Function,
53 /// Subroutine declaration
54 Sub,
55 /// Property declaration
56 Property,
57 /// Variable declaration
58 Variable,
59
60 /// If statement
61 If,
62 /// For loop
63 For,
64 /// For Each loop
65 ForEach,
66 /// While loop
67 While,
68 /// Do While loop
69 DoWhile,
70 /// Select Case statement
71 SelectCase,
72 /// With statement
73 With,
74 /// Try statement
75 Try,
76 /// Catch clause
77 Catch,
78 /// Finally block
79 Finally,
80 /// Dim statement
81 Dim,
82 /// Const statement
83 Const,
84 /// Return statement
85 Return,
86 /// Exit statement
87 Exit,
88 /// Continue statement
89 Continue,
90 /// Statement
91 Statement,
92 /// Throw statement
93 Throw,
94
95 /// Binary expression
96 BinaryExpression,
97 /// Unary expression
98 UnaryExpression,
99 /// Assignment expression
100 AssignmentExpression,
101 /// Method call
102 MethodCall,
103 /// Member access
104 MemberAccess,
105 /// Element access
106 ElementAccess,
107 /// New expression
108 NewExpression,
109 /// Array expression
110 ArrayExpression,
111 /// Tuple expression
112 TupleExpression,
113 /// Parenthesized expression
114 ParenthesizedExpression,
115 /// TypeOf expression
116 TypeOfExpression,
117 /// Is expression
118 IsExpression,
119 /// Like expression
120 LikeExpression,
121 /// If expression
122 IfExpression,
123 /// Lambda expression
124 LambdaExpression,
125 /// XML literal
126 XmlLiteral,
127
128 /// Error
129 Error,
130 /// End of file
131 Eof,
132}
133
134impl VbNetElementType {
135 /// Checks if it is a keyword
136 pub fn is_keyword(&self) -> bool {
137 matches!(
138 self,
139 Self::Namespace
140 | Self::Imports
141 | Self::Class
142 | Self::Interface
143 | Self::Structure
144 | Self::Enum
145 | Self::Module
146 | Self::Delegate
147 | Self::Event
148 | Self::Function
149 | Self::Sub
150 | Self::Property
151 | Self::Dim
152 | Self::Const
153 | Self::If
154 | Self::For
155 | Self::ForEach
156 | Self::While
157 | Self::DoWhile
158 | Self::SelectCase
159 | Self::With
160 | Self::Try
161 | Self::Catch
162 | Self::Finally
163 | Self::Return
164 | Self::Exit
165 | Self::Continue
166 | Self::Statement
167 | Self::Throw
168 )
169 }
170}
171
172impl ElementType for VbNetElementType {
173 type Role = UniversalElementRole;
174
175 fn role(&self) -> Self::Role {
176 match self {
177 Self::Error => UniversalElementRole::Error,
178 _ => UniversalElementRole::None,
179 }
180 }
181}
182
183impl From<crate::lexer::token_type::VbNetTokenType> for VbNetElementType {
184 fn from(token: crate::lexer::token_type::VbNetTokenType) -> Self {
185 unsafe { std::mem::transmute(token) }
186 }
187}