oak_msil/kind/
mod.rs

1use oak_core::{SyntaxKind, Token};
2use serde::{Deserialize, Serialize};
3
4pub type MsilToken = Token<MsilSyntaxKind>;
5
6/// 统一MSIL 语法种类(包含节点与词法
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
8pub enum MsilSyntaxKind {
9    // 节点种类
10    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    // 词法种类 - 关键
26    AssemblyKeyword, // .assembly
27    ExternKeyword,   // extern
28    ModuleKeyword,   // .module
29    ClassKeyword,    // .class
30    MethodKeyword,   // .method
31    PublicKeyword,   // public
32    PrivateKeyword,  // private
33    StaticKeyword,   // static
34
35    // 词法种类 - 符号
36    LeftBrace,    // {
37    RightBrace,   // }
38    LeftParen,    // (
39    RightParen,   // )
40    LeftBracket,  // [
41    RightBracket, // ]
42    Dot,          // .
43    Colon,        // :
44    Semicolon,    // ;
45    Comma,        // ,
46
47    // 词法种类 - 字面
48    IdentifierToken,
49    NumberToken,
50    StringToken,
51
52    // 词法种类 - 其他
53    Whitespace,
54    CommentToken,
55    Eof,
56    Error,
57}
58
59impl SyntaxKind for MsilSyntaxKind {
60    fn is_trivia(&self) -> bool {
61        matches!(self, Self::Whitespace | Self::CommentToken)
62    }
63
64    fn is_comment(&self) -> bool {
65        matches!(self, Self::CommentToken)
66    }
67
68    fn is_whitespace(&self) -> bool {
69        matches!(self, Self::Whitespace)
70    }
71
72    fn is_token_type(&self) -> bool {
73        !matches!(
74            self,
75            Self::Root
76                | Self::Assembly
77                | Self::Module
78                | Self::Class
79                | Self::Method
80                | Self::Instruction
81                | Self::Label
82                | Self::Directive
83                | Self::Type
84                | Self::ErrorNode
85        )
86    }
87
88    fn is_element_type(&self) -> bool {
89        matches!(
90            self,
91            Self::Root
92                | Self::Assembly
93                | Self::Module
94                | Self::Class
95                | Self::Method
96                | Self::Instruction
97                | Self::Label
98                | Self::Directive
99                | Self::Type
100                | Self::ErrorNode
101        )
102    }
103}