Skip to main content

oak_msil/lexer/
token_type.rs

1use oak_core::{Token, TokenType, UniversalTokenRole};
2
3/// MSIL token.
4pub type MsilToken = Token<MsilTokenType>;
5
6impl TokenType for MsilTokenType {
7    type Role = UniversalTokenRole;
8    const END_OF_STREAM: Self = Self::Eof;
9
10    fn is_ignored(&self) -> bool {
11        false
12    }
13
14    fn role(&self) -> Self::Role {
15        match self {
16            Self::Whitespace => UniversalTokenRole::Whitespace,
17            Self::CommentToken => UniversalTokenRole::Comment,
18            Self::IdentifierToken => UniversalTokenRole::Name,
19            Self::NumberToken => UniversalTokenRole::Literal,
20            Self::StringToken => UniversalTokenRole::Literal,
21            Self::AssemblyKeyword | Self::ExternKeyword | Self::ModuleKeyword | Self::ClassKeyword | Self::MethodKeyword | Self::PublicKeyword | Self::PrivateKeyword | Self::StaticKeyword | Self::Keyword => UniversalTokenRole::Keyword,
22            Self::LeftBrace | Self::RightBrace | Self::LeftParen | Self::RightParen | Self::LeftBracket | Self::RightBracket | Self::Dot | Self::Colon | Self::Semicolon | Self::Comma | Self::Equal | Self::Slash => UniversalTokenRole::Operator,
23            Self::Eof => UniversalTokenRole::Eof,
24            Self::Error | Self::ErrorNode => UniversalTokenRole::Error,
25            _ => UniversalTokenRole::None,
26        }
27    }
28}
29
30/// MSIL token type.
31#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
32#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
33pub enum MsilTokenType {
34    /// Root node.
35    Root,
36    /// Assembly.
37    Assembly,
38    /// External assembly.
39    AssemblyExtern,
40    /// Module.
41    Module,
42    /// Class.
43    Class,
44    /// Method.
45    Method,
46    /// Instruction.
47    Instruction,
48    /// Label.
49    Label,
50    /// Directive.
51    Directive,
52    /// Type.
53    Type,
54    /// Identifier.
55    Identifier,
56    /// Number.
57    Number,
58    /// String.
59    String,
60    /// Comment.
61    Comment,
62    /// Error node.
63    ErrorNode,
64
65    /// .assembly keyword
66    AssemblyKeyword,
67    /// extern keyword
68    ExternKeyword,
69    /// .module keyword
70    ModuleKeyword,
71    /// .class keyword
72    ClassKeyword,
73    /// .method keyword
74    MethodKeyword,
75    /// public keyword
76    PublicKeyword,
77    /// private keyword
78    PrivateKeyword,
79    /// static keyword
80    StaticKeyword,
81    /// Other keywords
82    Keyword,
83
84    /// Left brace ({)
85    LeftBrace,
86    /// Right brace (})
87    RightBrace,
88    /// Left parenthesis (()
89    LeftParen,
90    /// Right parenthesis ())
91    RightParen,
92    /// Left bracket ([)
93    LeftBracket,
94    /// Right bracket (])
95    RightBracket,
96    /// Dot (.)
97    Dot,
98    /// Colon (:)
99    Colon,
100    /// Semicolon (;)
101    Semicolon,
102    /// Comma (,)
103    Comma,
104    /// Equal (=)
105    Equal,
106    /// Slash (/)
107    Slash,
108
109    /// Identifier unit
110    IdentifierToken,
111    /// Number unit
112    NumberToken,
113    /// String unit
114    StringToken,
115
116    /// Whitespace
117    Whitespace,
118    /// Comment unit
119    CommentToken,
120    /// End of file
121    Eof,
122    /// Error unit
123    Error,
124}