Skip to main content

oak_jasmin/parser/
element_type.rs

1use oak_core::{ElementType, UniversalElementRole};
2
3/// Jasmin element types for the green tree.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub enum JasminElementType {
7    /// Root node.
8    Root,
9    /// Class definition.
10    Class,
11    /// Method definition.
12    Method,
13    /// Field definition.
14    Field,
15    /// Instruction.
16    Instruction,
17    /// Identifier node.
18    IdentifierNode,
19    /// String node.
20    StringNode,
21    /// Number node.
22    NumberNode,
23    /// Error node.
24    ErrorNode,
25
26    /// `.class` keyword.
27    ClassKw,
28    /// `.version` keyword.
29    VersionKw,
30    /// `.method` keyword.
31    MethodKw,
32    /// `.field` keyword.
33    FieldKw,
34    /// `.string` keyword.
35    StringKw,
36    /// `.source` keyword.
37    SourceFileKw,
38    /// `.stack` keyword.
39    StackKw,
40    /// `.limit locals` keyword.
41    LocalsKw,
42    /// `.end` keyword.
43    EndKw,
44    /// `compiled` keyword.
45    CompiledKw,
46    /// `from` keyword.
47    FromKw,
48    /// `.inner` keyword.
49    InnerClassKw,
50    /// `.nest` keyword.
51    NestMembersKw,
52    /// `.bootstrap` keyword.
53    BootstrapMethodKw,
54
55    /// `public` access flag.
56    Public,
57    /// `private` access flag.
58    Private,
59    /// `protected` access flag.
60    Protected,
61    /// `static` access flag.
62    Static,
63    /// `super` access flag.
64    Super,
65    /// `final` access flag.
66    Final,
67    /// `abstract` access flag.
68    Abstract,
69    /// `synchronized` access flag.
70    Synchronized,
71    /// `native` access flag.
72    Native,
73    /// `synthetic` access flag.
74    Synthetic,
75    /// `deprecated` access flag.
76    Deprecated,
77    /// `varargs` access flag.
78    Varargs,
79    /// `bridge` access flag.
80    Bridge,
81    /// `enum` keyword.
82    Enum,
83    /// `annotation` keyword.
84    Annotation,
85    /// `strictfp` access flag.
86    Strictfp,
87    /// `interface` keyword.
88    Interface,
89    /// `volatile` access flag.
90    Volatile,
91    /// `transient` access flag.
92    Transient,
93
94    /// `aload_0` instruction.
95    ALoad0,
96    /// `aload_1` instruction.
97    ALoad1,
98    /// `aload_2` instruction.
99    ALoad2,
100    /// `aload_3` instruction.
101    ALoad3,
102    /// `iload_0` instruction.
103    ILoad0,
104    /// `iload_1` instruction.
105    ILoad1,
106    /// `iload_2` instruction.
107    ILoad2,
108    /// `iload_3` instruction.
109    ILoad3,
110    /// `ldc` instruction.
111    Ldc,
112    /// `ldc_w` instruction.
113    LdcW,
114    /// `ldc2_w` instruction.
115    Ldc2W,
116    /// `invokespecial` instruction.
117    InvokeSpecial,
118    /// `invokevirtual` instruction.
119    InvokeVirtual,
120    /// `invokestatic` instruction.
121    InvokeStatic,
122    /// `invokeinterface` instruction.
123    InvokeInterface,
124    /// `invokedynamic` instruction.
125    InvokeDynamic,
126    /// `getstatic` instruction.
127    GetStatic,
128    /// `putstatic` instruction.
129    PutStatic,
130    /// `getfield` instruction.
131    GetField,
132    /// `putfield` instruction.
133    PutField,
134    /// `return` instruction.
135    Return,
136    /// `ireturn` instruction.
137    IReturn,
138    /// `areturn` instruction.
139    AReturn,
140    /// `lreturn` instruction.
141    LReturn,
142    /// `freturn` instruction.
143    FReturn,
144    /// `dreturn` instruction.
145    DReturn,
146    /// `nop` instruction.
147    Nop,
148    /// `dup` instruction.
149    Dup,
150    /// `pop` instruction.
151    Pop,
152    /// `new` instruction.
153    New,
154
155    /// `{` token.
156    LeftBrace,
157    /// `}` token.
158    RightBrace,
159    /// `(` token.
160    LeftParen,
161    /// `)` token.
162    RightParen,
163    /// `[` token.
164    LeftBracket,
165    /// `]` token.
166    RightBracket,
167    /// `:` token.
168    Colon,
169    /// `;` token.
170    Semicolon,
171    /// `.` token.
172    Dot,
173    /// `,` token.
174    Comma,
175    /// `/` token.
176    Slash,
177
178    /// String literal token.
179    StringLiteral,
180    /// Number token.
181    Number,
182    /// Type descriptor token.
183    TypeDescriptor,
184    /// Identifier token.
185    IdentifierToken,
186    /// Whitespace token.
187    Whitespace,
188    /// Newline token.
189    Newline,
190    /// Comment token.
191    Comment,
192    /// EOF token.
193    Eof,
194    /// Error token.
195    Error,
196}
197
198impl ElementType for JasminElementType {
199    type Role = UniversalElementRole;
200
201    fn role(&self) -> Self::Role {
202        match self {
203            _ => UniversalElementRole::None,
204        }
205    }
206}
207
208impl From<crate::lexer::token_type::JasminTokenType> for JasminElementType {
209    fn from(token: crate::lexer::token_type::JasminTokenType) -> Self {
210        match token {
211            crate::lexer::token_type::JasminTokenType::Root => JasminElementType::Root,
212            crate::lexer::token_type::JasminTokenType::Class => JasminElementType::Class,
213            crate::lexer::token_type::JasminTokenType::Method => JasminElementType::Method,
214            crate::lexer::token_type::JasminTokenType::Field => JasminElementType::Field,
215            crate::lexer::token_type::JasminTokenType::Instruction => JasminElementType::Instruction,
216            crate::lexer::token_type::JasminTokenType::IdentifierNode => JasminElementType::IdentifierNode,
217            crate::lexer::token_type::JasminTokenType::StringNode => JasminElementType::StringNode,
218            crate::lexer::token_type::JasminTokenType::NumberNode => JasminElementType::NumberNode,
219            crate::lexer::token_type::JasminTokenType::ErrorNode => JasminElementType::ErrorNode,
220
221            crate::lexer::token_type::JasminTokenType::ClassKw => JasminElementType::ClassKw,
222            crate::lexer::token_type::JasminTokenType::VersionKw => JasminElementType::VersionKw,
223            crate::lexer::token_type::JasminTokenType::MethodKw => JasminElementType::MethodKw,
224            crate::lexer::token_type::JasminTokenType::FieldKw => JasminElementType::FieldKw,
225            crate::lexer::token_type::JasminTokenType::StringKw => JasminElementType::StringKw,
226            crate::lexer::token_type::JasminTokenType::SourceFileKw => JasminElementType::SourceFileKw,
227            crate::lexer::token_type::JasminTokenType::StackKw => JasminElementType::StackKw,
228            crate::lexer::token_type::JasminTokenType::LocalsKw => JasminElementType::LocalsKw,
229            crate::lexer::token_type::JasminTokenType::EndKw => JasminElementType::EndKw,
230            crate::lexer::token_type::JasminTokenType::CompiledKw => JasminElementType::CompiledKw,
231            crate::lexer::token_type::JasminTokenType::FromKw => JasminElementType::FromKw,
232            crate::lexer::token_type::JasminTokenType::InnerClassKw => JasminElementType::InnerClassKw,
233            crate::lexer::token_type::JasminTokenType::NestMembersKw => JasminElementType::NestMembersKw,
234            crate::lexer::token_type::JasminTokenType::BootstrapMethodKw => JasminElementType::BootstrapMethodKw,
235
236            crate::lexer::token_type::JasminTokenType::Public => JasminElementType::Public,
237            crate::lexer::token_type::JasminTokenType::Private => JasminElementType::Private,
238            crate::lexer::token_type::JasminTokenType::Protected => JasminElementType::Protected,
239            crate::lexer::token_type::JasminTokenType::Static => JasminElementType::Static,
240            crate::lexer::token_type::JasminTokenType::Super => JasminElementType::Super,
241            crate::lexer::token_type::JasminTokenType::Final => JasminElementType::Final,
242            crate::lexer::token_type::JasminTokenType::Abstract => JasminElementType::Abstract,
243            crate::lexer::token_type::JasminTokenType::Synchronized => JasminElementType::Synchronized,
244            crate::lexer::token_type::JasminTokenType::Native => JasminElementType::Native,
245            crate::lexer::token_type::JasminTokenType::Synthetic => JasminElementType::Synthetic,
246            crate::lexer::token_type::JasminTokenType::Deprecated => JasminElementType::Deprecated,
247            crate::lexer::token_type::JasminTokenType::Varargs => JasminElementType::Varargs,
248            crate::lexer::token_type::JasminTokenType::Bridge => JasminElementType::Bridge,
249            crate::lexer::token_type::JasminTokenType::Enum => JasminElementType::Enum,
250            crate::lexer::token_type::JasminTokenType::Annotation => JasminElementType::Annotation,
251            crate::lexer::token_type::JasminTokenType::Strictfp => JasminElementType::Strictfp,
252            crate::lexer::token_type::JasminTokenType::Interface => JasminElementType::Interface,
253            crate::lexer::token_type::JasminTokenType::Volatile => JasminElementType::Volatile,
254            crate::lexer::token_type::JasminTokenType::Transient => JasminElementType::Transient,
255
256            crate::lexer::token_type::JasminTokenType::ALoad0 => JasminElementType::ALoad0,
257            crate::lexer::token_type::JasminTokenType::ALoad1 => JasminElementType::ALoad1,
258            crate::lexer::token_type::JasminTokenType::ALoad2 => JasminElementType::ALoad2,
259            crate::lexer::token_type::JasminTokenType::ALoad3 => JasminElementType::ALoad3,
260            crate::lexer::token_type::JasminTokenType::ILoad0 => JasminElementType::ILoad0,
261            crate::lexer::token_type::JasminTokenType::ILoad1 => JasminElementType::ILoad1,
262            crate::lexer::token_type::JasminTokenType::ILoad2 => JasminElementType::ILoad2,
263            crate::lexer::token_type::JasminTokenType::ILoad3 => JasminElementType::ILoad3,
264            crate::lexer::token_type::JasminTokenType::Ldc => JasminElementType::Ldc,
265            crate::lexer::token_type::JasminTokenType::LdcW => JasminElementType::LdcW,
266            crate::lexer::token_type::JasminTokenType::Ldc2W => JasminElementType::Ldc2W,
267            crate::lexer::token_type::JasminTokenType::InvokeSpecial => JasminElementType::InvokeSpecial,
268            crate::lexer::token_type::JasminTokenType::InvokeVirtual => JasminElementType::InvokeVirtual,
269            crate::lexer::token_type::JasminTokenType::InvokeStatic => JasminElementType::InvokeStatic,
270            crate::lexer::token_type::JasminTokenType::InvokeInterface => JasminElementType::InvokeInterface,
271            crate::lexer::token_type::JasminTokenType::InvokeDynamic => JasminElementType::InvokeDynamic,
272            crate::lexer::token_type::JasminTokenType::GetStatic => JasminElementType::GetStatic,
273            crate::lexer::token_type::JasminTokenType::PutStatic => JasminElementType::PutStatic,
274            crate::lexer::token_type::JasminTokenType::GetField => JasminElementType::GetField,
275            crate::lexer::token_type::JasminTokenType::PutField => JasminElementType::PutField,
276            crate::lexer::token_type::JasminTokenType::Return => JasminElementType::Return,
277            crate::lexer::token_type::JasminTokenType::IReturn => JasminElementType::IReturn,
278            crate::lexer::token_type::JasminTokenType::AReturn => JasminElementType::AReturn,
279            crate::lexer::token_type::JasminTokenType::LReturn => JasminElementType::LReturn,
280            crate::lexer::token_type::JasminTokenType::FReturn => JasminElementType::FReturn,
281            crate::lexer::token_type::JasminTokenType::DReturn => JasminElementType::DReturn,
282            crate::lexer::token_type::JasminTokenType::Nop => JasminElementType::Nop,
283            crate::lexer::token_type::JasminTokenType::Dup => JasminElementType::Dup,
284            crate::lexer::token_type::JasminTokenType::Pop => JasminElementType::Pop,
285            crate::lexer::token_type::JasminTokenType::New => JasminElementType::New,
286
287            crate::lexer::token_type::JasminTokenType::LeftBrace => JasminElementType::LeftBrace,
288            crate::lexer::token_type::JasminTokenType::RightBrace => JasminElementType::RightBrace,
289            crate::lexer::token_type::JasminTokenType::LeftParen => JasminElementType::LeftParen,
290            crate::lexer::token_type::JasminTokenType::RightParen => JasminElementType::RightParen,
291            crate::lexer::token_type::JasminTokenType::LeftBracket => JasminElementType::LeftBracket,
292            crate::lexer::token_type::JasminTokenType::RightBracket => JasminElementType::RightBracket,
293            crate::lexer::token_type::JasminTokenType::Colon => JasminElementType::Colon,
294            crate::lexer::token_type::JasminTokenType::Semicolon => JasminElementType::Semicolon,
295            crate::lexer::token_type::JasminTokenType::Dot => JasminElementType::Dot,
296            crate::lexer::token_type::JasminTokenType::Comma => JasminElementType::Comma,
297            crate::lexer::token_type::JasminTokenType::Slash => JasminElementType::Slash,
298
299            crate::lexer::token_type::JasminTokenType::StringLiteral => JasminElementType::StringLiteral,
300            crate::lexer::token_type::JasminTokenType::Number => JasminElementType::Number,
301            crate::lexer::token_type::JasminTokenType::TypeDescriptor => JasminElementType::TypeDescriptor,
302            crate::lexer::token_type::JasminTokenType::IdentifierToken => JasminElementType::IdentifierToken,
303            crate::lexer::token_type::JasminTokenType::Whitespace => JasminElementType::Whitespace,
304            crate::lexer::token_type::JasminTokenType::Newline => JasminElementType::Newline,
305            crate::lexer::token_type::JasminTokenType::Comment => JasminElementType::Comment,
306            crate::lexer::token_type::JasminTokenType::Eof => JasminElementType::Eof,
307            crate::lexer::token_type::JasminTokenType::Error => JasminElementType::Error,
308        }
309    }
310}