1use oak_core::{ElementType, Parser, UniversalElementRole};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub enum PurescriptElementType {
7 Whitespace,
9 Newline,
11 Comment,
13 Ado,
15 Case,
17 Class,
19 Data,
21 Derive,
23 Do,
25 Else,
27 False,
29 Forall,
31 Foreign,
33 If,
35 Import,
37 In,
39 Infix,
41 Infixl,
43 Infixr,
45 Instance,
47 Let,
49 Module,
51 Newtype,
53 Of,
55 Then,
57 True,
59 Type,
61 Where,
63 Arrow,
65 FatArrow,
67 Backslash,
69 Pipe,
71 Equal,
73 ColonColon,
75 Dot,
77 DotDot,
79 Plus,
81 Minus,
83 Star,
85 Slash,
87 Percent,
89 Caret,
91 EqualEqual,
93 NotEqual,
95 Less,
97 Greater,
99 LessEqual,
101 GreaterEqual,
103 And,
105 Or,
107 Not,
109 LeftParen,
111 RightParen,
113 LeftBracket,
115 RightBracket,
117 LeftBrace,
119 RightBrace,
121 Comma,
123 Semicolon,
125 Colon,
127 Dollar,
129 Append,
131 LeftArrow,
133 Underscore,
135 Identifier,
137 Constructor,
139 Operator,
141 StringLiteral,
143 IntLiteral,
145 NumberLiteral,
147 CharLiteral,
149
150 ModuleDeclaration,
152 ImportDeclaration,
154 DataDeclaration,
156 NewtypeDeclaration,
158 TypeAliasDeclaration,
160 ClassDeclaration,
162 InstanceDeclaration,
164 ForeignImportDeclaration,
166 TypeSignature,
168 ValueDeclaration,
170 Pattern,
172 Expression,
174 LiteralExpression,
176 IdentifierExpression,
178 PrefixExpression,
180 InfixExpression,
182 ApplicationExpression,
184 LambdaExpression,
186 LetExpression,
188 CaseExpression,
190 CaseArm,
192 DoExpression,
194 TypeNode,
196
197 SourceFile,
199 Compose,
201 ComposeFlipped,
203 Apply,
205 ApplyFlipped,
207 Bind,
209 BindFlipped,
211 Question,
213 Exclamation,
215 At,
217 Tick,
219 UpperIdentifier,
221 QualifiedIdentifier,
223 BooleanLiteral,
225 Root,
227 Eof,
229 Error,
231}
232
233impl ElementType for PurescriptElementType {
234 type Role = UniversalElementRole;
235
236 fn role(&self) -> Self::Role {
237 match self {
238 Self::Root => UniversalElementRole::Root,
239 Self::SourceFile => UniversalElementRole::Root,
240 Self::Error => UniversalElementRole::Error,
241 _ => UniversalElementRole::None,
242 }
243 }
244}
245
246impl From<crate::lexer::token_type::PurescriptTokenType> for PurescriptElementType {
247 fn from(token: crate::lexer::token_type::PurescriptTokenType) -> Self {
248 use crate::lexer::token_type::PurescriptTokenType as T;
249 match token {
250 T::Whitespace => Self::Whitespace,
251 T::Newline => Self::Newline,
252 T::Comment => Self::Comment,
253 T::Ado => Self::Ado,
254 T::Case => Self::Case,
255 T::Class => Self::Class,
256 T::Data => Self::Data,
257 T::Derive => Self::Derive,
258 T::Do => Self::Do,
259 T::Else => Self::Else,
260 T::False => Self::False,
261 T::Forall => Self::Forall,
262 T::Foreign => Self::Foreign,
263 T::If => Self::If,
264 T::Import => Self::Import,
265 T::In => Self::In,
266 T::Infix => Self::Infix,
267 T::Infixl => Self::Infixl,
268 T::Infixr => Self::Infixr,
269 T::Instance => Self::Instance,
270 T::Let => Self::Let,
271 T::Module => Self::Module,
272 T::Newtype => Self::Newtype,
273 T::Of => Self::Of,
274 T::Then => Self::Then,
275 T::True => Self::True,
276 T::Type => Self::Type,
277 T::Where => Self::Where,
278 T::Arrow => Self::Arrow,
279 T::FatArrow => Self::FatArrow,
280 T::Backslash => Self::Backslash,
281 T::Pipe => Self::Pipe,
282 T::Equal => Self::Equal,
283 T::ColonColon => Self::ColonColon,
284 T::Dot => Self::Dot,
285 T::DotDot => Self::DotDot,
286 T::Plus => Self::Plus,
287 T::Minus => Self::Minus,
288 T::Star => Self::Star,
289 T::Slash => Self::Slash,
290 T::Percent => Self::Percent,
291 T::Caret => Self::Caret,
292 T::EqualEqual => Self::EqualEqual,
293 T::NotEqual => Self::NotEqual,
294 T::Less => Self::Less,
295 T::Greater => Self::Greater,
296 T::LessEqual => Self::LessEqual,
297 T::GreaterEqual => Self::GreaterEqual,
298 T::And => Self::And,
299 T::Or => Self::Or,
300 T::Append => Self::Append,
301 T::Compose => Self::Compose,
302 T::ComposeFlipped => Self::ComposeFlipped,
303 T::Apply => Self::Apply,
304 T::ApplyFlipped => Self::ApplyFlipped,
305 T::Bind => Self::Bind,
306 T::BindFlipped => Self::BindFlipped,
307 T::LeftParen => Self::LeftParen,
308 T::RightParen => Self::RightParen,
309 T::LeftBrace => Self::LeftBrace,
310 T::RightBrace => Self::RightBrace,
311 T::LeftBracket => Self::LeftBracket,
312 T::RightBracket => Self::RightBracket,
313 T::Comma => Self::Comma,
314 T::Semicolon => Self::Semicolon,
315 T::Colon => Self::Colon,
316 T::Question => Self::Question,
317 T::Exclamation => Self::Exclamation,
318 T::At => Self::At,
319 T::Underscore => Self::Underscore,
320 T::Tick => Self::Tick,
321 T::IntLiteral => Self::IntLiteral,
322 T::NumberLiteral => Self::NumberLiteral,
323 T::StringLiteral => Self::StringLiteral,
324 T::CharLiteral => Self::CharLiteral,
325 T::BooleanLiteral => Self::BooleanLiteral,
326 T::Identifier => Self::Identifier,
327 T::UpperIdentifier => Self::UpperIdentifier,
328 T::Operator => Self::Operator,
329 T::QualifiedIdentifier => Self::QualifiedIdentifier,
330 T::Root => Self::Root,
331 T::SourceFile => Self::SourceFile,
332 T::Error => Self::Error,
333 T::Eof => Self::Eof,
334 }
335 }
336}