1use oak_core::{ElementType, UniversalElementRole};
2#[cfg(feature = "serde")]
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7pub enum GoElementType {
8 SourceFile,
10 PackageClause,
11 ImportDeclaration,
12 ImportSpec,
13 FunctionDeclaration,
14 ParameterList,
15 ParameterDecl,
16 Block,
17 VariableDeclaration,
18 VariableSpec,
19 ConstDeclaration,
20 ConstSpec,
21 TypeDeclaration,
22 TypeSpec,
23 StructType,
24 FieldDeclList,
25 FieldDecl,
26 InterfaceType,
27 MethodSpecList,
28 MethodSpec,
29 ExpressionList,
30 AssignmentStatement,
31 ShortVarDecl,
32 ReturnStatement,
33 IfStatement,
34 ForStatement,
35 SwitchStatement,
36 ExprCaseClause,
37 TypeSwitchStatement,
38 TypeCaseClause,
39 SelectStatement,
40 CommClause,
41 GoStatement,
42 DeferStatement,
43 CallExpression,
44 IndexExpression,
45 SelectorExpression,
46 SliceExpression,
47 TypeAssertion,
48 UnaryExpression,
49 BinaryExpression,
50 LiteralValue,
51 ElementList,
52 KeyedElement,
53
54 IntLiteral,
56 FloatLiteral,
57 StringLiteral,
58 RuneLiteral,
59 BoolLiteral,
60
61 Identifier,
63
64 Break,
66 Case,
67 Chan,
68 Const,
69 Continue,
70 Default,
71 Defer,
72 Else,
73 Fallthrough,
74 For,
75 Func,
76 Go,
77 Goto,
78 If,
79 Import,
80 Interface,
81 Map,
82 Package,
83 Range,
84 Return,
85 Select,
86 Struct,
87 Switch,
88 Type,
89 Var,
90
91 Bool,
93 Byte,
94 Complex64,
95 Complex128,
96 ErrorType,
97 Float32,
98 Float64,
99 Int,
100 Int8,
101 Int16,
102 Int32,
103 Int64,
104 Rune,
105 String,
106 Uint,
107 Uint8,
108 Uint16,
109 Uint32,
110 Uint64,
111 Uintptr,
112
113 NilLiteral,
115 NumberLiteral,
116 CharLiteral,
117
118 Plus, Minus, Star, Slash, Percent, Ampersand, Pipe, Caret, LeftShift, RightShift, AmpersandCaret, PlusAssign, MinusAssign, StarAssign, SlashAssign, PercentAssign, AmpersandAssign, PipeAssign, CaretAssign, XorAssign, LeftShiftAssign, RightShiftAssign, AmpersandCaretAssign, AndAssign, OrAssign, AndNotAssign, AndNot, LogicalAnd, LogicalOr, And, Or, Arrow, LeftArrow, Increment, Decrement, Equal, Less, Greater, Assign, LogicalNot, Not, NotEqual, LessEqual, GreaterEqual, ColonAssign, Define, Ellipsis, LeftParen, RightParen, LeftBracket, RightBracket, LeftBrace, RightBrace, Comma, Period, Dot, Semicolon, Colon, Whitespace,
186 Comment,
187
188 Eof,
190 Error,
191}
192
193impl GoElementType {
194 pub fn is_ignored(&self) -> bool {
195 matches!(self, Self::Whitespace | Self::Comment)
196 }
197
198 pub fn is_keyword(&self) -> bool {
199 matches!(
200 self,
201 Self::Break
202 | Self::Case
203 | Self::Chan
204 | Self::Const
205 | Self::Continue
206 | Self::Default
207 | Self::Defer
208 | Self::Else
209 | Self::Fallthrough
210 | Self::For
211 | Self::Func
212 | Self::Go
213 | Self::Goto
214 | Self::If
215 | Self::Import
216 | Self::Interface
217 | Self::Map
218 | Self::Package
219 | Self::Range
220 | Self::Return
221 | Self::Select
222 | Self::Struct
223 | Self::Switch
224 | Self::Type
225 | Self::Var
226 )
227 }
228}
229
230impl ElementType for GoElementType {
231 type Role = UniversalElementRole;
232
233 fn role(&self) -> Self::Role {
234 match self {
235 Self::Error => UniversalElementRole::Error,
236 _ => UniversalElementRole::None,
237 }
238 }
239}
240
241impl From<crate::lexer::token_type::GoTokenType> for GoElementType {
242 fn from(token: crate::lexer::token_type::GoTokenType) -> Self {
243 unsafe { std::mem::transmute(token) }
244 }
245}