1use oak_core::Token;
2use serde::{Deserialize, Serialize};
3
4pub type JasmToken = Token<JasmSyntaxKind>;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
8pub enum JasmSyntaxKind {
9 Root,
11 Class,
12 Method,
13 Field,
14 Instruction,
15 IdentifierNode,
16 StringNode,
17 NumberNode,
18 ErrorNode,
19
20 ClassKw,
22 VersionKw,
23 MethodKw,
24 FieldKw,
25 StringKw,
26 SourceFileKw,
27 StackKw,
28 LocalsKw,
29 EndKw,
30 CompiledKw,
31 FromKw,
32 InnerClassKw,
33 NestMembersKw,
34 BootstrapMethodKw,
35
36 Public,
37 Private,
38 Protected,
39 Static,
40 Super,
41 Final,
42 Abstract,
43 Synchronized,
44 Native,
45 Synthetic,
46 Deprecated,
47 Varargs,
48
49 ALoad0,
50 ALoad1,
51 ALoad2,
52 ALoad3,
53 ILoad0,
54 ILoad1,
55 ILoad2,
56 ILoad3,
57 Ldc,
58 LdcW,
59 Ldc2W,
60 InvokeSpecial,
61 InvokeVirtual,
62 InvokeStatic,
63 InvokeInterface,
64 InvokeDynamic,
65 GetStatic,
66 PutStatic,
67 GetField,
68 PutField,
69 Return,
70 IReturn,
71 AReturn,
72 LReturn,
73 FReturn,
74 DReturn,
75 Nop,
76 Dup,
77 Pop,
78 New,
79
80 LeftBrace,
81 RightBrace,
82 LeftParen,
83 RightParen,
84 LeftBracket,
85 RightBracket,
86 Colon,
87 Semicolon,
88 Dot,
89 Comma,
90 Slash,
91
92 StringLiteral,
93 Number,
94 TypeDescriptor,
95 IdentifierToken,
96 Whitespace,
97 Newline,
98 Comment,
99 Eof,
100 Error,
101}
102
103impl oak_core::TokenType for JasmSyntaxKind {
104 const END_OF_STREAM: Self = Self::Eof;
105 type Role = oak_core::UniversalTokenRole;
106
107 fn role(&self) -> Self::Role {
108 use oak_core::UniversalTokenRole::*;
109 match self {
110 Self::ClassKw
111 | Self::VersionKw
112 | Self::MethodKw
113 | Self::FieldKw
114 | Self::StringKw
115 | Self::SourceFileKw
116 | Self::StackKw
117 | Self::LocalsKw
118 | Self::EndKw
119 | Self::CompiledKw
120 | Self::FromKw
121 | Self::InnerClassKw
122 | Self::NestMembersKw
123 | Self::BootstrapMethodKw
124 | Self::Public
125 | Self::Private
126 | Self::Protected
127 | Self::Static
128 | Self::Super
129 | Self::Final
130 | Self::Abstract
131 | Self::Synchronized
132 | Self::Native
133 | Self::Synthetic
134 | Self::Deprecated
135 | Self::Varargs
136 | Self::ALoad0
137 | Self::ALoad1
138 | Self::ALoad2
139 | Self::ALoad3
140 | Self::ILoad0
141 | Self::ILoad1
142 | Self::ILoad2
143 | Self::ILoad3
144 | Self::Ldc
145 | Self::LdcW
146 | Self::Ldc2W
147 | Self::InvokeSpecial
148 | Self::InvokeVirtual
149 | Self::InvokeStatic
150 | Self::InvokeInterface
151 | Self::InvokeDynamic
152 | Self::GetStatic
153 | Self::PutStatic
154 | Self::GetField
155 | Self::PutField
156 | Self::Return
157 | Self::IReturn
158 | Self::AReturn
159 | Self::LReturn
160 | Self::FReturn
161 | Self::DReturn
162 | Self::Nop
163 | Self::Dup
164 | Self::Pop
165 | Self::New => Keyword,
166 Self::StringLiteral | Self::Number => Literal,
167 Self::IdentifierToken | Self::TypeDescriptor => Name,
168 Self::LeftBrace | Self::RightBrace | Self::LeftParen | Self::RightParen | Self::LeftBracket | Self::RightBracket | Self::Colon | Self::Semicolon | Self::Dot | Self::Comma | Self::Slash => Punctuation,
169 Self::Whitespace | Self::Newline => Whitespace,
170 Self::Comment => Comment,
171 _ => None,
172 }
173 }
174
175 fn is_ignored(&self) -> bool {
176 matches!(self, Self::Whitespace | Self::Newline | Self::Comment)
177 }
178
179 fn is_comment(&self) -> bool {
180 matches!(self, Self::Comment)
181 }
182
183 fn is_whitespace(&self) -> bool {
184 matches!(self, Self::Whitespace | Self::Newline)
185 }
186}
187
188impl oak_core::ElementType for JasmSyntaxKind {
189 type Role = oak_core::UniversalElementRole;
190
191 fn role(&self) -> Self::Role {
192 use oak_core::UniversalElementRole::*;
193 match self {
194 Self::Root => Root,
195 Self::Class | Self::Method | Self::Field => Definition,
196 _ => None,
197 }
198 }
199}