1use oak_core::{ElementType, TokenType, UniversalElementRole, UniversalTokenRole};
2use serde::{Deserialize, Serialize};
3
4#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
5pub enum NimSyntaxKind {
6 Whitespace,
8 Newline,
9 CommentToken,
10
11 AddrKeyword,
13 AndKeyword,
14 AsKeyword,
15 AsmKeyword,
16 BindKeyword,
17 BlockKeyword,
18 BreakKeyword,
19 CaseKeyword,
20 CastKeyword,
21 ConceptKeyword,
22 ConstKeyword,
23 ContinueKeyword,
24 ConverterKeyword,
25 DeferKeyword,
26 DiscardKeyword,
27 DistinctKeyword,
28 DivKeyword,
29 DoKeyword,
30 ElifKeyword,
31 ElseKeyword,
32 EndKeyword,
33 EnumKeyword,
34 ExceptKeyword,
35 ExportKeyword,
36 FinallyKeyword,
37 ForKeyword,
38 FromKeyword,
39 FuncKeyword,
40 IfKeyword,
41 ImportKeyword,
42 InKeyword,
43 IncludeKeyword,
44 InterfaceKeyword,
45 IsKeyword,
46 IteratorKeyword,
47 LetKeyword,
48 MacroKeyword,
49 MethodKeyword,
50 MixinKeyword,
51 ModKeyword,
52 NilKeyword,
53 NotKeyword,
54 NotnilKeyword,
55 ObjectKeyword,
56 OfKeyword,
57 OrKeyword,
58 OutKeyword,
59 ProcKeyword,
60 PtrKeyword,
61 RaiseKeyword,
62 RefKeyword,
63 ReturnKeyword,
64 ShlKeyword,
65 ShrKeyword,
66 StaticKeyword,
67 TemplateKeyword,
68 TryKeyword,
69 TupleKeyword,
70 TypeKeyword,
71 UsingKeyword,
72 VarKeyword,
73 WhenKeyword,
74 WhileKeyword,
75 XorKeyword,
76 YieldKeyword,
77
78 Plus,
80 Minus,
81 Star,
82 Slash,
83 Percent,
84 Equal,
85 EqualEqual,
86 NotEqual,
87 Less,
88 LessEqual,
89 Greater,
90 GreaterEqual,
91 Ampersand,
92 Pipe,
93 Caret,
94 Tilde,
95 LeftShift,
96 RightShift,
97 DotDot,
98 Arrow,
99 At,
100
101 LeftParen,
103 RightParen,
104 LeftBracket,
105 RightBracket,
106 LeftBrace,
107 RightBrace,
108 Comma,
109 Semicolon,
110 Colon,
111 Dot,
112 Question,
113 Exclamation,
114 Dollar,
115 Backtick,
116
117 IntLiteral,
119 FloatLiteral,
120 StringLiteral,
121 CharLiteral,
122 BoolLiteral,
123
124 Identifier,
126
127 Root,
129 ProcDecl,
130 VarDecl,
131 LetDecl,
132 ConstDecl,
133 TypeDecl,
134 IfStmt,
135 WhileStmt,
136 ForStmt,
137 CaseStmt,
138 BlockStmt,
139 Expression,
140 Literal,
141 Comment,
142 ImportDecl,
143 ErrorNode,
144 Error,
145 Eof,
146}
147
148impl NimSyntaxKind {
149 pub fn is_token(&self) -> bool {
150 !self.is_element()
151 }
152
153 pub fn is_element(&self) -> bool {
154 matches!(self, Self::Root | Self::ProcDecl | Self::TypeDecl | Self::VarDecl | Self::ConstDecl | Self::LetDecl | Self::ImportDecl | Self::Comment | Self::ErrorNode)
155 }
156}
157
158impl TokenType for NimSyntaxKind {
159 const END_OF_STREAM: Self = Self::Eof;
160 type Role = UniversalTokenRole;
161
162 fn role(&self) -> Self::Role {
163 match self {
164 Self::Whitespace | Self::Newline => UniversalTokenRole::Whitespace,
165 Self::CommentToken | Self::Comment => UniversalTokenRole::Comment,
166 Self::Eof => UniversalTokenRole::Eof,
167 _ => UniversalTokenRole::None,
168 }
169 }
170
171 fn is_comment(&self) -> bool {
172 matches!(self, Self::CommentToken | Self::Comment)
173 }
174
175 fn is_whitespace(&self) -> bool {
176 matches!(self, Self::Whitespace | Self::Newline)
177 }
178}
179
180impl ElementType for NimSyntaxKind {
181 type Role = UniversalElementRole;
182
183 fn role(&self) -> Self::Role {
184 match self {
185 Self::ErrorNode | Self::Error => UniversalElementRole::Error,
186 Self::Root => UniversalElementRole::Root,
187 Self::ProcDecl | Self::TypeDecl | Self::VarDecl => UniversalElementRole::Detail,
188 _ => UniversalElementRole::None,
189 }
190 }
191}