oak_elm/parser/
element_type.rs1use oak_core::{ElementType, UniversalElementRole};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub enum ElmElementType {
7 Root,
9 Module,
11 Import,
13 TypeDeclaration,
15 TypeAlias,
17 FunctionDeclaration,
19 Expression,
21 Literal,
23 Identifier,
25 BinaryExpression,
27 UnaryExpression,
29 IfExpression,
31 CaseExpression,
33 LetExpression,
35 TupleExpression,
37 ListExpression,
39 RecordExpression,
41 FieldExpression,
43 LambdaExpression,
45 TypeSignature,
47 ValueDeclaration,
49 Pattern,
51 Error,
53}
54
55impl ElementType for ElmElementType {
56 type Role = UniversalElementRole;
57
58 fn role(&self) -> Self::Role {
59 match self {
60 Self::Root => UniversalElementRole::Root,
61 Self::Module => UniversalElementRole::Definition,
62 Self::Import => UniversalElementRole::Statement,
63 Self::FunctionDeclaration => UniversalElementRole::Definition,
64 Self::Expression => UniversalElementRole::Expression,
65 Self::Identifier => UniversalElementRole::Name,
66 _ => UniversalElementRole::None,
67 }
68 }
69}
70
71impl From<crate::lexer::token_type::ElmTokenType> for ElmElementType {
72 fn from(token: crate::lexer::token_type::ElmTokenType) -> Self {
73 match token {
74 crate::lexer::token_type::ElmTokenType::Root => Self::Root,
75 crate::lexer::token_type::ElmTokenType::Identifier => Self::Identifier,
76 _ => unsafe { std::mem::transmute(token) },
77 }
78 }
79}