1use oak_core::{ElementType, Token, TokenType, UniversalElementRole, UniversalTokenRole};
2use serde::{Deserialize, Serialize};
3
4pub type MsilToken = Token<MsilSyntaxKind>;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
8pub enum MsilSyntaxKind {
9 Root,
11 Assembly,
12 Module,
13 Class,
14 Method,
15 Instruction,
16 Label,
17 Directive,
18 Type,
19 Identifier,
20 Number,
21 String,
22 Comment,
23 ErrorNode,
24
25 AssemblyKeyword, ExternKeyword, ModuleKeyword, ClassKeyword, MethodKeyword, PublicKeyword, PrivateKeyword, StaticKeyword, LeftBrace, RightBrace, LeftParen, RightParen, LeftBracket, RightBracket, Dot, Colon, Semicolon, Comma, IdentifierToken,
49 NumberToken,
50 StringToken,
51
52 Whitespace,
54 CommentToken,
55 Eof,
56 Error,
57}
58
59impl TokenType for MsilSyntaxKind {
60 const END_OF_STREAM: Self = Self::Eof;
61 type Role = UniversalTokenRole;
62
63 fn role(&self) -> Self::Role {
64 match self {
65 Self::Whitespace => UniversalTokenRole::Whitespace,
66 Self::CommentToken | Self::Comment => UniversalTokenRole::Comment,
67 Self::Eof => UniversalTokenRole::Eof,
68 _ => UniversalTokenRole::None,
69 }
70 }
71
72 fn is_comment(&self) -> bool {
73 matches!(self, Self::CommentToken | Self::Comment)
74 }
75
76 fn is_whitespace(&self) -> bool {
77 matches!(self, Self::Whitespace)
78 }
79}
80
81impl ElementType for MsilSyntaxKind {
82 type Role = UniversalElementRole;
83
84 fn role(&self) -> Self::Role {
85 match self {
86 Self::ErrorNode | Self::Error => UniversalElementRole::Error,
87 Self::Root => UniversalElementRole::Root,
88 Self::Method | Self::Class => UniversalElementRole::Detail,
89 _ => UniversalElementRole::None,
90 }
91 }
92
93 fn is_root(&self) -> bool {
94 matches!(self, Self::Root)
95 }
96
97 fn is_error(&self) -> bool {
98 matches!(self, Self::Error | Self::ErrorNode)
99 }
100}