oak_voml/parser/
element_type.rs1use oak_core::{ElementType, UniversalElementRole};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8#[repr(u16)]
9pub enum VomlElementType {
10 Root,
12 SourceFile,
14 Module,
16 Function,
18 Memory,
20 Export,
22 Import,
24 Param,
26 Result,
28 Local,
30 Instruction,
32
33 Int,
35 Uint,
37 F32,
39 F64,
41 String,
43 Rune,
45 Byte,
47 Voidptr,
49 Char,
51 Bool,
53
54 Identifier,
56 Number,
58 Boolean,
60
61 LeftParen,
63 RightParen,
65 LeftBracket,
67 RightBracket,
69 LeftBrace,
71 RightBrace,
73 Dot,
75 Comma,
77 Colon,
79 Semicolon,
81
82 Whitespace,
84 Comment,
86 Error,
88 Eof,
90}
91
92impl ElementType for VomlElementType {
93 type Role = UniversalElementRole;
94
95 fn role(&self) -> Self::Role {
96 match self {
97 Self::Root | Self::SourceFile => UniversalElementRole::Root,
98 Self::Module | Self::Function | Self::Memory | Self::Export | Self::Import => UniversalElementRole::Statement,
99 Self::Int | Self::Uint | Self::F32 | Self::F64 | Self::String | Self::Rune | Self::Byte | Self::Voidptr | Self::Char | Self::Bool => UniversalElementRole::Typing,
100 Self::Identifier => UniversalElementRole::Reference,
101 Self::Number | Self::Boolean => UniversalElementRole::Value,
102 Self::Error => UniversalElementRole::Error,
103 _ => UniversalElementRole::None,
104 }
105 }
106}
107
108impl From<crate::lexer::token_type::VomlTokenType> for VomlElementType {
109 fn from(token: crate::lexer::token_type::VomlTokenType) -> Self {
110 unsafe { std::mem::transmute(token) }
111 }
112}