1pub use crate::lexer::ValkyrieKeywords;
2use oak_core::{ElementType, TokenType, UniversalElementRole, UniversalTokenRole};
3use serde::{Deserialize, Serialize};
4
5#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
6#[allow(missing_docs)]
7pub enum ValkyrieSyntaxKind {
8 Whitespace,
10 Newline,
11
12 LeftParen,
14 RightParen,
15 LeftBracket,
16 RightBracket,
17 LeftBrace,
18 RightBrace,
19 Colon,
20 Semicolon,
21 Dot,
22 Comma,
23 Question,
24 Bang,
25 At,
26 Hash,
27 Dollar,
28 Percent,
29 Caret,
30 Ampersand,
31 Star,
32 Plus,
33 Minus,
34 Eq,
35 LessThan,
36 GreaterThan,
37 Slash,
38 Backslash,
39 Pipe,
40 Tilde,
41 Underscore,
42
43 EqEq,
45 NotEq,
46 LessEq,
47 GreaterEq,
48 PlusPlus,
49 MinusMinus,
50 PlusEq,
51 MinusEq,
52 StarEq,
53 SlashEq,
54 PercentEq,
55 AndAnd,
56 OrOr,
57 LeftShift,
58 RightShift,
59 Arrow,
60
61 CaretEq,
63 AndEq,
64 OrEq,
65 ShlEq,
66 ShrEq,
67 Lt,
68 Gt,
69 Ne,
70 Le,
71 Ge,
72 Shl,
73 Shr,
74 Not,
75 And,
76 Or,
77
78 Keyword(ValkyrieKeywords),
80
81 Identifier,
83
84 IntegerLiteral,
86 FloatLiteral,
87 StringLiteral,
88 CharLiteral,
89 BoolLiteral,
90
91 LineComment,
93 BlockComment,
94
95 ValkyrieRoot, SourceFile,
98 Namespace,
99 Class,
100 Widget,
101 ApplyBlock,
102 Micro,
103 Mezzo,
104 Type,
105 ParameterList,
106 Parameter,
107 BlockExpression,
108 LetStatement,
109 ExpressionStatement,
110 IdentifierExpression,
111 LiteralExpression,
112 BooleanLiteral,
113 AnonymousClass,
114 ObjectExpression,
115 ParenthesizedExpression,
116 UnaryExpression,
117 BinaryExpression,
118 CallExpression,
119 FieldExpression,
120 IndexExpression,
121 IfExpression,
122 MatchExpression,
123 MatchArm,
124 LoopExpression,
125 ReturnExpression,
126 BreakExpression,
127 ContinueExpression,
128 YieldExpression,
129 RaiseExpression,
130 CatchExpression,
131
132 Error,
134 Eof,
135}
136
137impl TokenType for ValkyrieSyntaxKind {
138 const END_OF_STREAM: Self = Self::Eof;
139 type Role = UniversalTokenRole;
140
141 fn role(&self) -> Self::Role {
142 match self {
143 Self::Whitespace | Self::Newline => UniversalTokenRole::Whitespace,
144 Self::LineComment | Self::BlockComment => UniversalTokenRole::Comment,
145 Self::Keyword(_) => UniversalTokenRole::Keyword,
146 Self::Identifier => UniversalTokenRole::Name,
147 Self::IntegerLiteral | Self::FloatLiteral | Self::StringLiteral | Self::CharLiteral | Self::BoolLiteral => UniversalTokenRole::Literal,
148 Self::Plus
149 | Self::Minus
150 | Self::Star
151 | Self::Slash
152 | Self::Percent
153 | Self::Eq
154 | Self::EqEq
155 | Self::NotEq
156 | Self::LessThan
157 | Self::GreaterThan
158 | Self::LessEq
159 | Self::GreaterEq
160 | Self::AndAnd
161 | Self::OrOr
162 | Self::Bang
163 | Self::Ampersand
164 | Self::Pipe
165 | Self::Caret
166 | Self::Tilde
167 | Self::LeftShift
168 | Self::RightShift
169 | Self::Arrow => UniversalTokenRole::Operator,
170 Self::LeftParen | Self::RightParen | Self::LeftBracket | Self::RightBracket | Self::LeftBrace | Self::RightBrace => UniversalTokenRole::Punctuation,
171 Self::Comma | Self::Semicolon | Self::Colon | Self::Dot => UniversalTokenRole::Punctuation,
172 _ => UniversalTokenRole::None,
173 }
174 }
175}
176
177impl ElementType for ValkyrieSyntaxKind {
178 type Role = oak_core::UniversalElementRole;
179
180 fn role(&self) -> Self::Role {
181 match self {
182 Self::SourceFile | Self::ValkyrieRoot => UniversalElementRole::Root,
183 Self::Namespace => UniversalElementRole::Container,
184 Self::Class => UniversalElementRole::Definition,
185 Self::Widget => UniversalElementRole::Definition,
186 Self::Micro => UniversalElementRole::Definition,
187 Self::Mezzo => UniversalElementRole::Definition,
188 Self::ParameterList => UniversalElementRole::Container,
189 Self::Parameter => UniversalElementRole::Binding,
190 Self::BlockExpression => UniversalElementRole::Expression,
191 Self::LetStatement => UniversalElementRole::Statement,
192 Self::ExpressionStatement => UniversalElementRole::Statement,
193 Self::IdentifierExpression => UniversalElementRole::Expression,
194 Self::LiteralExpression => UniversalElementRole::Expression,
195 Self::BooleanLiteral => UniversalElementRole::Expression,
196 Self::AnonymousClass => UniversalElementRole::Expression,
197 Self::ApplyBlock | Self::ObjectExpression => UniversalElementRole::Expression,
198 Self::ParenthesizedExpression => UniversalElementRole::Expression,
199 Self::UnaryExpression => UniversalElementRole::Expression,
200 Self::BinaryExpression => UniversalElementRole::Expression,
201 Self::CallExpression => UniversalElementRole::Call,
202 Self::FieldExpression => UniversalElementRole::Expression,
203 Self::IndexExpression => UniversalElementRole::Expression,
204 Self::IfExpression => UniversalElementRole::Expression,
205 Self::MatchExpression => UniversalElementRole::Expression,
206 Self::MatchArm => UniversalElementRole::Container,
207 Self::LoopExpression => UniversalElementRole::Expression,
208 Self::ReturnExpression => UniversalElementRole::Expression,
209 Self::BreakExpression => UniversalElementRole::Expression,
210 Self::ContinueExpression => UniversalElementRole::Expression,
211 Self::YieldExpression => UniversalElementRole::Expression,
212 Self::RaiseExpression => UniversalElementRole::Expression,
213 Self::CatchExpression => UniversalElementRole::Expression,
214 Self::Error => UniversalElementRole::Error,
215 _ => UniversalElementRole::None,
216 }
217 }
218
219 fn is_root(&self) -> bool {
220 matches!(self, Self::SourceFile | Self::ValkyrieRoot)
221 }
222
223 fn is_error(&self) -> bool {
224 matches!(self, Self::Error)
225 }
226}
227
228impl From<ValkyrieSyntaxKind> for UniversalTokenRole {
229 fn from(kind: ValkyrieSyntaxKind) -> Self {
230 <ValkyrieSyntaxKind as TokenType>::role(&kind)
231 }
232}