1use oak_core::{ElementType, UniversalElementRole};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6#[repr(u8)]
7pub enum ErlangElementType {
8 Whitespace,
10 Newline,
12 Comment,
14
15 Identifier,
17 Atom,
19 Variable,
21 Number,
23 String,
25 Character,
27
28 After,
30 And,
32 Andalso,
34 Band,
36 Begin,
38 Bnot,
40 Bor,
42 Bsl,
44 Bsr,
46 Bxor,
48 Case,
50 Catch,
52 Cond,
54 Div,
56 End,
58 Fun,
60 If,
62 Let,
64 Not,
66 Of,
68 Or,
70 Orelse,
72 Query,
74 Receive,
76 Rem,
78 Try,
80 When,
82 Xor,
84
85 Plus,
87 Minus,
89 Star,
91 Slash,
93 Equal,
95 EqualEqual,
97 SlashEqual,
99 EqualColonEqual,
101 EqualSlashEqual,
103 Less,
105 Greater,
107 LessEqual,
109 GreaterEqual,
111 PlusPlus,
113 MinusMinus,
115 Exclamation,
117 Question,
119
120 LeftParen,
122 RightParen,
124 LeftBrace,
126 RightBrace,
128 LeftBracket,
130 RightBracket,
132 Comma,
134 Semicolon,
136 Dot,
138 Colon,
140 Arrow,
142 Pipe,
144 PipePipe,
146 Hash,
148
149 Root,
151 Item,
153 Module,
155 Export,
157 Attribute,
159 Function,
161 FunctionClause,
163 Pattern,
165 RecordPattern,
167 Statement,
169 Expr,
171 BinaryExpr,
173 CallExpr,
175 FunExpr,
177 CaseExpr,
179 CaseClause,
181 IfExpr,
183 IfClause,
185 TryExpr,
187 CatchClause,
189 ReceiveExpr,
191 ReceiveClause,
193 RecordExpr,
195
196 Error,
198 Eof,
200}
201
202impl ErlangElementType {
203 pub fn is_keyword(&self) -> bool {
205 matches!(
206 self,
207 Self::After
208 | Self::And
209 | Self::Andalso
210 | Self::Band
211 | Self::Begin
212 | Self::Bnot
213 | Self::Bor
214 | Self::Bsl
215 | Self::Bsr
216 | Self::Bxor
217 | Self::Case
218 | Self::Catch
219 | Self::Cond
220 | Self::Div
221 | Self::End
222 | Self::Fun
223 | Self::If
224 | Self::Let
225 | Self::Not
226 | Self::Of
227 | Self::Or
228 | Self::Orelse
229 | Self::Query
230 | Self::Receive
231 | Self::Rem
232 | Self::Try
233 | Self::When
234 | Self::Xor
235 )
236 }
237
238 pub fn is_operator(&self) -> bool {
240 matches!(
241 self,
242 Self::Plus
243 | Self::Minus
244 | Self::Star
245 | Self::Slash
246 | Self::Equal
247 | Self::EqualEqual
248 | Self::SlashEqual
249 | Self::EqualColonEqual
250 | Self::EqualSlashEqual
251 | Self::Less
252 | Self::Greater
253 | Self::LessEqual
254 | Self::GreaterEqual
255 | Self::PlusPlus
256 | Self::MinusMinus
257 | Self::Exclamation
258 | Self::Question
259 )
260 }
261
262 pub fn is_punctuation(&self) -> bool {
264 matches!(self, Self::LeftParen | Self::RightParen | Self::LeftBrace | Self::RightBrace | Self::LeftBracket | Self::RightBracket | Self::Comma | Self::Semicolon | Self::Dot | Self::Colon | Self::Arrow | Self::Pipe | Self::PipePipe | Self::Hash)
265 }
266}
267
268impl ElementType for ErlangElementType {
269 type Role = UniversalElementRole;
270
271 fn role(&self) -> Self::Role {
272 match self {
273 Self::Root => UniversalElementRole::Root,
274 _ => UniversalElementRole::None,
275 }
276 }
277}
278
279impl From<crate::lexer::token_type::ErlangTokenType> for ErlangElementType {
280 fn from(token: crate::lexer::token_type::ErlangTokenType) -> Self {
281 use crate::lexer::token_type::ErlangTokenType;
282 match token {
283 ErlangTokenType::Whitespace => Self::Whitespace,
284 ErlangTokenType::Newline => Self::Newline,
285 ErlangTokenType::Comment => Self::Comment,
286 ErlangTokenType::Identifier => Self::Identifier,
287 ErlangTokenType::Atom => Self::Atom,
288 ErlangTokenType::Variable => Self::Variable,
289 ErlangTokenType::Number => Self::Number,
290 ErlangTokenType::String => Self::String,
291 ErlangTokenType::Character => Self::Character,
292 ErlangTokenType::After => Self::After,
293 ErlangTokenType::And => Self::And,
294 ErlangTokenType::Andalso => Self::Andalso,
295 ErlangTokenType::Band => Self::Band,
296 ErlangTokenType::Begin => Self::Begin,
297 ErlangTokenType::Bnot => Self::Bnot,
298 ErlangTokenType::Bor => Self::Bor,
299 ErlangTokenType::Bsl => Self::Bsl,
300 ErlangTokenType::Bsr => Self::Bsr,
301 ErlangTokenType::Bxor => Self::Bxor,
302 ErlangTokenType::Case => Self::Case,
303 ErlangTokenType::Catch => Self::Catch,
304 ErlangTokenType::Cond => Self::Cond,
305 ErlangTokenType::Div => Self::Div,
306 ErlangTokenType::End => Self::End,
307 ErlangTokenType::Fun => Self::Fun,
308 ErlangTokenType::If => Self::If,
309 ErlangTokenType::Let => Self::Let,
310 ErlangTokenType::Not => Self::Not,
311 ErlangTokenType::Of => Self::Of,
312 ErlangTokenType::Or => Self::Or,
313 ErlangTokenType::Orelse => Self::Orelse,
314 ErlangTokenType::Query => Self::Query,
315 ErlangTokenType::Receive => Self::Receive,
316 ErlangTokenType::Rem => Self::Rem,
317 ErlangTokenType::Try => Self::Try,
318 ErlangTokenType::When => Self::When,
319 ErlangTokenType::Xor => Self::Xor,
320 ErlangTokenType::Plus => Self::Plus,
321 ErlangTokenType::Minus => Self::Minus,
322 ErlangTokenType::Star => Self::Star,
323 ErlangTokenType::Slash => Self::Slash,
324 ErlangTokenType::Equal => Self::Equal,
325 ErlangTokenType::EqualEqual => Self::EqualEqual,
326 ErlangTokenType::SlashEqual => Self::SlashEqual,
327 ErlangTokenType::EqualColonEqual => Self::EqualColonEqual,
328 ErlangTokenType::EqualSlashEqual => Self::EqualSlashEqual,
329 ErlangTokenType::Less => Self::Less,
330 ErlangTokenType::Greater => Self::Greater,
331 ErlangTokenType::LessEqual => Self::LessEqual,
332 ErlangTokenType::GreaterEqual => Self::GreaterEqual,
333 ErlangTokenType::PlusPlus => Self::PlusPlus,
334 ErlangTokenType::MinusMinus => Self::MinusMinus,
335 ErlangTokenType::Exclamation => Self::Exclamation,
336 ErlangTokenType::Question => Self::Question,
337 ErlangTokenType::LeftParen => Self::LeftParen,
338 ErlangTokenType::RightParen => Self::RightParen,
339 ErlangTokenType::LeftBrace => Self::LeftBrace,
340 ErlangTokenType::RightBrace => Self::RightBrace,
341 ErlangTokenType::LeftBracket => Self::LeftBracket,
342 ErlangTokenType::RightBracket => Self::RightBracket,
343 ErlangTokenType::Comma => Self::Comma,
344 ErlangTokenType::Semicolon => Self::Semicolon,
345 ErlangTokenType::Dot => Self::Dot,
346 ErlangTokenType::Colon => Self::Colon,
347 ErlangTokenType::Arrow => Self::Arrow,
348 ErlangTokenType::Pipe => Self::Pipe,
349 ErlangTokenType::PipePipe => Self::PipePipe,
350 ErlangTokenType::Hash => Self::Hash,
351 ErlangTokenType::Root => Self::Root,
352 ErlangTokenType::Item => Self::Item,
353 ErlangTokenType::Module => Self::Module,
354 ErlangTokenType::Export => Self::Export,
355 ErlangTokenType::Attribute => Self::Attribute,
356 ErlangTokenType::Function => Self::Function,
357 ErlangTokenType::FunctionClause => Self::FunctionClause,
358 ErlangTokenType::Pattern => Self::Pattern,
359 ErlangTokenType::RecordPattern => Self::RecordPattern,
360 ErlangTokenType::Statement => Self::Statement,
361 ErlangTokenType::Expr => Self::Expr,
362 ErlangTokenType::BinaryExpr => Self::BinaryExpr,
363 ErlangTokenType::CallExpr => Self::CallExpr,
364 ErlangTokenType::FunExpr => Self::FunExpr,
365 ErlangTokenType::CaseExpr => Self::CaseExpr,
366 ErlangTokenType::CaseClause => Self::CaseClause,
367 ErlangTokenType::IfExpr => Self::IfExpr,
368 ErlangTokenType::IfClause => Self::IfClause,
369 ErlangTokenType::TryExpr => Self::TryExpr,
370 ErlangTokenType::CatchClause => Self::CatchClause,
371 ErlangTokenType::ReceiveExpr => Self::ReceiveExpr,
372 ErlangTokenType::ReceiveClause => Self::ReceiveClause,
373 ErlangTokenType::RecordExpr => Self::RecordExpr,
374 ErlangTokenType::Error => Self::Error,
375 ErlangTokenType::Eof => Self::Eof,
376 }
377 }
378}