1use serde::{Deserialize, Serialize};
2
3#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
4pub enum SoliditySyntaxKind {
5 Whitespace,
7 Newline,
8
9 LineComment,
11 BlockComment,
12
13 Contract,
15 Interface,
16 Library,
17 Function,
18 Modifier,
19 Event,
20 Struct,
21 Enum,
22 Mapping,
23 Array,
24
25 Public,
27 Private,
28 Internal,
29 External,
30
31 Pure,
33 View,
34 Payable,
35 Constant,
36
37 Bool,
39 String,
40 Bytes,
41 Address,
42 Uint,
43 Int,
44 Fixed,
45 Ufixed,
46
47 If,
49 Else,
50 For,
51 While,
52 Do,
53 Break,
54 Continue,
55 Return,
56 Try,
57 Catch,
58
59 Import,
61 Pragma,
62 Using,
63 Is,
64 Override,
65 Virtual,
66 Abstract,
67
68 NumberLiteral,
70 StringLiteral,
71 BooleanLiteral,
72 AddressLiteral,
73 HexLiteral,
74
75 Identifier,
77
78 Plus,
80 Minus,
81 Star,
82 Slash,
83 Percent,
84 Power,
85 Equal,
86 NotEqual,
87 Less,
88 Greater,
89 LessEqual,
90 GreaterEqual,
91 And,
92 Or,
93 Not,
94 BitAnd,
95 BitOr,
96 BitXor,
97 BitNot,
98 LeftShift,
99 RightShift,
100 Assign,
101 PlusAssign,
102 MinusAssign,
103 StarAssign,
104 SlashAssign,
105 PercentAssign,
106
107 LeftParen,
109 RightParen,
110 LeftBrace,
111 RightBrace,
112 LeftBracket,
113 RightBracket,
114 Semicolon,
115 Comma,
116 Dot,
117 Arrow,
118
119 SourceFile,
121
122 Error,
124 Eof,
125}
126
127impl oak_core::TokenType for SoliditySyntaxKind {
128 type Role = oak_core::UniversalTokenRole;
129 const END_OF_STREAM: Self = Self::Eof;
130
131 fn role(&self) -> Self::Role {
132 match self {
133 Self::Whitespace | Self::Newline => oak_core::UniversalTokenRole::Whitespace,
134 Self::LineComment | Self::BlockComment => oak_core::UniversalTokenRole::Comment,
135 Self::Contract
136 | Self::Interface
137 | Self::Library
138 | Self::Function
139 | Self::Modifier
140 | Self::Event
141 | Self::Struct
142 | Self::Enum
143 | Self::Mapping
144 | Self::Public
145 | Self::Private
146 | Self::Internal
147 | Self::External
148 | Self::Pure
149 | Self::View
150 | Self::Payable
151 | Self::Constant
152 | Self::Bool
153 | Self::String
154 | Self::Bytes
155 | Self::Address
156 | Self::Uint
157 | Self::Int
158 | Self::Fixed
159 | Self::Ufixed
160 | Self::If
161 | Self::Else
162 | Self::For
163 | Self::While
164 | Self::Do
165 | Self::Break
166 | Self::Continue
167 | Self::Return
168 | Self::Try
169 | Self::Catch
170 | Self::Import
171 | Self::Pragma
172 | Self::Using
173 | Self::Is
174 | Self::Override
175 | Self::Virtual
176 | Self::Abstract => oak_core::UniversalTokenRole::Keyword,
177 Self::NumberLiteral | Self::StringLiteral | Self::BooleanLiteral | Self::AddressLiteral | Self::HexLiteral => oak_core::UniversalTokenRole::Literal,
178 Self::Identifier => oak_core::UniversalTokenRole::Name,
179 Self::Plus
180 | Self::Minus
181 | Self::Star
182 | Self::Slash
183 | Self::Percent
184 | Self::Power
185 | Self::Equal
186 | Self::NotEqual
187 | Self::Less
188 | Self::Greater
189 | Self::LessEqual
190 | Self::GreaterEqual
191 | Self::And
192 | Self::Or
193 | Self::Not
194 | Self::BitAnd
195 | Self::BitOr
196 | Self::BitXor
197 | Self::BitNot
198 | Self::LeftShift
199 | Self::RightShift
200 | Self::Assign
201 | Self::PlusAssign
202 | Self::MinusAssign
203 | Self::StarAssign
204 | Self::SlashAssign
205 | Self::PercentAssign => oak_core::UniversalTokenRole::Operator,
206 Self::LeftParen | Self::RightParen | Self::LeftBrace | Self::RightBrace | Self::LeftBracket | Self::RightBracket | Self::Semicolon | Self::Comma | Self::Dot | Self::Arrow => oak_core::UniversalTokenRole::Punctuation,
207 Self::Error => oak_core::UniversalTokenRole::Error,
208 Self::Eof => oak_core::UniversalTokenRole::Eof,
209 _ => oak_core::UniversalTokenRole::None,
210 }
211 }
212
213 fn is_ignored(&self) -> bool {
214 matches!(self, Self::Whitespace | Self::Newline | Self::LineComment | Self::BlockComment)
215 }
216
217 fn is_comment(&self) -> bool {
218 matches!(self, Self::LineComment | Self::BlockComment)
219 }
220
221 fn is_whitespace(&self) -> bool {
222 matches!(self, Self::Whitespace | Self::Newline)
223 }
224}
225
226impl SoliditySyntaxKind {
227 pub fn is_token_type(&self) -> bool {
228 !matches!(self, Self::SourceFile)
229 }
230
231 pub fn is_element_type(&self) -> bool {
232 matches!(self, Self::SourceFile)
233 }
234}
235
236impl oak_core::ElementType for SoliditySyntaxKind {
237 type Role = oak_core::UniversalElementRole;
238
239 fn role(&self) -> Self::Role {
240 match self {
241 Self::SourceFile => oak_core::UniversalElementRole::Root,
242 _ => oak_core::UniversalElementRole::None,
243 }
244 }
245}