1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
use oak_core::{ElementType, UniversalElementRole};
/// Element types for the Scala parser.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ScalaElementType {
/// Root node for Scala source files.
SourceFile,
/// Whitespace token.
Whitespace,
/// Newline token.
Newline,
/// Comment token (generic).
Comment,
/// Single-line comment token.
LineComment,
/// Multi-line block comment token.
BlockComment,
/// Error token for lexical errors.
Error,
/// End-of-file token.
Eof,
/// Error node for parse errors.
ErrorNode,
/// Identifier token for names and symbols.
Identifier,
/// Integer literal token.
IntegerLiteral,
/// Floating-point literal token.
FloatLiteral,
/// String literal token.
StringLiteral,
/// Character literal token.
CharLiteral,
/// Boolean literal token (true or false).
BooleanLiteral,
/// `abstract` keyword.
Abstract,
/// `case` keyword.
Case,
/// `catch` keyword.
Catch,
/// `class` keyword.
Class,
/// `def` keyword.
Def,
/// `do` keyword.
Do,
/// `else` keyword.
Else,
/// `extends` keyword.
Extends,
/// `false` keyword.
False,
/// `final` keyword.
Final,
/// `finally` keyword.
Finally,
/// `for` keyword.
For,
/// `forSome` keyword.
ForSome,
/// `if` keyword.
If,
/// `implicit` keyword.
Implicit,
/// `import` keyword.
Import,
/// `lazy` keyword.
Lazy,
/// `match` keyword.
Match,
/// `new` keyword.
New,
/// `null` keyword.
Null,
/// `object` keyword.
Object,
/// `override` keyword.
Override,
/// `package` keyword.
Package,
/// `private` keyword.
Private,
/// `protected` keyword.
Protected,
/// `return` keyword.
Return,
/// `sealed` keyword.
Sealed,
/// `super` keyword.
Super,
/// `this` keyword.
This,
/// `throw` keyword.
Throw,
/// `trait` keyword.
Trait,
/// `try` keyword.
Try,
/// `true` keyword.
True,
/// `type` keyword.
Type,
/// `val` keyword.
Val,
/// `var` keyword.
Var,
/// `while` keyword.
While,
/// `with` keyword.
With,
/// `yield` keyword.
Yield,
/// Addition operator `+`.
Plus,
/// Subtraction operator `-`.
Minus,
/// Multiplication operator `*`.
Star,
/// Division operator `/`.
Slash,
/// Modulo operator `%`.
Percent,
/// Assignment operator `=`.
Eq,
/// Equality operator `==`.
EqEq,
/// Inequality operator `!=`.
Ne,
/// Less-than operator `<`.
Lt,
/// Less-than-or-equal operator `<=`.
Le,
/// Greater-than operator `>`.
Gt,
/// Greater-than-or-equal operator `>=`.
Ge,
/// Less-than-or-equal operator `<=`.
LessEqual,
/// Greater-than-or-equal operator `>=`.
GreaterEqual,
/// Equality operator `==`.
EqualEqual,
/// Inequality operator `!=`.
NotEqual,
/// Bitwise AND operator `&`.
And,
/// Bitwise OR operator `|`.
Or,
/// Bitwise XOR operator `^`.
Xor,
/// Logical AND operator `&&`.
AndAnd,
/// Logical OR operator `||`.
OrOr,
/// Logical NOT operator `!`.
Not,
/// Bitwise NOT operator `~`.
Tilde,
/// Left shift operator `<<`.
LShift,
/// Right shift operator `>>`.
RShift,
/// Unsigned right shift operator `>>>`.
URShift,
/// Addition assignment operator `+=`.
PlusEq,
/// Subtraction assignment operator `-=`.
MinusEq,
/// Multiplication assignment operator `*=`.
StarEq,
/// Division assignment operator `/=`.
SlashEq,
/// Modulo assignment operator `%=`.
PercentEq,
/// Bitwise AND assignment operator `&=`.
AndEq,
/// Bitwise OR assignment operator `|=`.
OrEq,
/// Bitwise XOR assignment operator `^=`.
XorEq,
/// Left shift assignment operator `<<=`.
LShiftEq,
/// Right shift assignment operator `>>=`.
RShiftEq,
/// Unsigned right shift assignment operator `>>>=`.
URShiftEq,
/// Arrow operator `=>`.
Arrow,
/// Left arrow operator `<-`.
LeftArrow,
/// Colon operator `:`.
Colon,
/// Cons operator `::`.
ColonColon,
/// Semicolon separator `;`.
Semicolon,
/// Dot operator `.`.
Dot,
/// Comma separator `,`.
Comma,
/// Question mark operator `?`.
Question,
/// Annotation operator `@`.
At,
/// Hash operator `#`.
Hash,
/// Left parenthesis `(`.
LeftParen,
/// Right parenthesis `)`.
RightParen,
/// Left bracket `[`.
LeftBracket,
/// Right bracket `]`.
RightBracket,
/// Left brace `{`.
LeftBrace,
/// Right brace `}`.
RightBrace,
}
impl ElementType for ScalaElementType {
type Role = UniversalElementRole;
fn role(&self) -> Self::Role {
match self {
Self::SourceFile => UniversalElementRole::Root,
Self::Error => UniversalElementRole::Error,
_ => UniversalElementRole::None,
}
}
}
impl From<crate::lexer::token_type::ScalaTokenType> for ScalaElementType {
fn from(token: crate::lexer::token_type::ScalaTokenType) -> Self {
use crate::lexer::token_type::ScalaTokenType as T;
match token {
T::SourceFile => ScalaElementType::SourceFile,
T::Whitespace => ScalaElementType::Whitespace,
T::Newline => ScalaElementType::Newline,
T::Comment => ScalaElementType::Comment,
T::LineComment => ScalaElementType::LineComment,
T::BlockComment => ScalaElementType::BlockComment,
T::Error => ScalaElementType::Error,
T::Eof => ScalaElementType::Eof,
T::ErrorNode => ScalaElementType::ErrorNode,
T::Identifier => ScalaElementType::Identifier,
T::IntegerLiteral => ScalaElementType::IntegerLiteral,
T::FloatLiteral => ScalaElementType::FloatLiteral,
T::StringLiteral => ScalaElementType::StringLiteral,
T::CharLiteral => ScalaElementType::CharLiteral,
T::BooleanLiteral => ScalaElementType::BooleanLiteral,
T::Abstract => ScalaElementType::Abstract,
T::Case => ScalaElementType::Case,
T::Catch => ScalaElementType::Catch,
T::Class => ScalaElementType::Class,
T::Def => ScalaElementType::Def,
T::Do => ScalaElementType::Do,
T::Else => ScalaElementType::Else,
T::Extends => ScalaElementType::Extends,
T::False => ScalaElementType::False,
T::Final => ScalaElementType::Final,
T::Finally => ScalaElementType::Finally,
T::For => ScalaElementType::For,
T::ForSome => ScalaElementType::ForSome,
T::If => ScalaElementType::If,
T::Implicit => ScalaElementType::Implicit,
T::Import => ScalaElementType::Import,
T::Lazy => ScalaElementType::Lazy,
T::Match => ScalaElementType::Match,
T::New => ScalaElementType::New,
T::Null => ScalaElementType::Null,
T::Object => ScalaElementType::Object,
T::Override => ScalaElementType::Override,
T::Package => ScalaElementType::Package,
T::Private => ScalaElementType::Private,
T::Protected => ScalaElementType::Protected,
T::Return => ScalaElementType::Return,
T::Sealed => ScalaElementType::Sealed,
T::Super => ScalaElementType::Super,
T::This => ScalaElementType::This,
T::Throw => ScalaElementType::Throw,
T::Trait => ScalaElementType::Trait,
T::Try => ScalaElementType::Try,
T::True => ScalaElementType::True,
T::Type => ScalaElementType::Type,
T::Val => ScalaElementType::Val,
T::Var => ScalaElementType::Var,
T::While => ScalaElementType::While,
T::With => ScalaElementType::With,
T::Yield => ScalaElementType::Yield,
T::Plus => ScalaElementType::Plus,
T::Minus => ScalaElementType::Minus,
T::Star => ScalaElementType::Star,
T::Slash => ScalaElementType::Slash,
T::Percent => ScalaElementType::Percent,
T::Eq => ScalaElementType::Eq,
T::EqEq => ScalaElementType::EqEq,
T::Ne => ScalaElementType::Ne,
T::Lt => ScalaElementType::Lt,
T::Le => ScalaElementType::Le,
T::Gt => ScalaElementType::Gt,
T::Ge => ScalaElementType::Ge,
T::LessEqual => ScalaElementType::LessEqual,
T::GreaterEqual => ScalaElementType::GreaterEqual,
T::EqualEqual => ScalaElementType::EqualEqual,
T::NotEqual => ScalaElementType::NotEqual,
T::And => ScalaElementType::And,
T::Or => ScalaElementType::Or,
T::Xor => ScalaElementType::Xor,
T::AndAnd => ScalaElementType::AndAnd,
T::OrOr => ScalaElementType::OrOr,
T::Not => ScalaElementType::Not,
T::Tilde => ScalaElementType::Tilde,
T::LShift => ScalaElementType::LShift,
T::RShift => ScalaElementType::RShift,
T::URShift => ScalaElementType::URShift,
T::PlusEq => ScalaElementType::PlusEq,
T::MinusEq => ScalaElementType::MinusEq,
T::StarEq => ScalaElementType::StarEq,
T::SlashEq => ScalaElementType::SlashEq,
T::PercentEq => ScalaElementType::PercentEq,
T::AndEq => ScalaElementType::AndEq,
T::OrEq => ScalaElementType::OrEq,
T::XorEq => ScalaElementType::XorEq,
T::LShiftEq => ScalaElementType::LShiftEq,
T::RShiftEq => ScalaElementType::RShiftEq,
T::URShiftEq => ScalaElementType::URShiftEq,
T::Arrow => ScalaElementType::Arrow,
T::LeftArrow => ScalaElementType::LeftArrow,
T::Colon => ScalaElementType::Colon,
T::ColonColon => ScalaElementType::ColonColon,
T::Semicolon => ScalaElementType::Semicolon,
T::Dot => ScalaElementType::Dot,
T::Comma => ScalaElementType::Comma,
T::Question => ScalaElementType::Question,
T::At => ScalaElementType::At,
T::Hash => ScalaElementType::Hash,
T::LeftParen => ScalaElementType::LeftParen,
T::RightParen => ScalaElementType::RightParen,
T::LeftBracket => ScalaElementType::LeftBracket,
T::RightBracket => ScalaElementType::RightBracket,
T::LeftBrace => ScalaElementType::LeftBrace,
T::RightBrace => ScalaElementType::RightBrace,
}
}
}