Skip to main content

oak_purescript/parser/
element_type.rs

1use oak_core::{ElementType, Parser, UniversalElementRole};
2
3/// Element types for PureScript AST.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub enum PurescriptElementType {
7    /// Whitespace.
8    Whitespace,
9    /// Newline.
10    Newline,
11    /// Comment.
12    Comment,
13    /// `ado`
14    Ado,
15    /// `case`
16    Case,
17    /// `class`
18    Class,
19    /// `data`
20    Data,
21    /// `derive`
22    Derive,
23    /// `do`
24    Do,
25    /// `else`
26    Else,
27    /// `false`
28    False,
29    /// `forall`
30    Forall,
31    /// `foreign`
32    Foreign,
33    /// `if`
34    If,
35    /// `import`
36    Import,
37    /// `in`
38    In,
39    /// `infix`
40    Infix,
41    /// `infixl`
42    Infixl,
43    /// `infixr`
44    Infixr,
45    /// `instance`
46    Instance,
47    /// `let`
48    Let,
49    /// `module`
50    Module,
51    /// `newtype`
52    Newtype,
53    /// `of`
54    Of,
55    /// `then`
56    Then,
57    /// `true`
58    True,
59    /// `type`
60    Type,
61    /// `where`
62    Where,
63    /// `->`
64    Arrow,
65    /// `=>`
66    FatArrow,
67    /// `\`
68    Backslash,
69    /// `|`
70    Pipe,
71    /// `=`
72    Equal,
73    /// `::`
74    ColonColon,
75    /// `.`
76    Dot,
77    /// `..`
78    DotDot,
79    /// `+`
80    Plus,
81    /// `-`
82    Minus,
83    /// `*`
84    Star,
85    /// `/`
86    Slash,
87    /// `%`
88    Percent,
89    /// `^`
90    Caret,
91    /// `==`
92    EqualEqual,
93    /// `/=`
94    NotEqual,
95    /// `<`
96    Less,
97    /// `>`
98    Greater,
99    /// `<=`
100    LessEqual,
101    /// `>=`
102    GreaterEqual,
103    /// `&&`
104    And,
105    /// `||`
106    Or,
107    /// `!`
108    Not,
109    /// `(`
110    LeftParen,
111    /// `)`
112    RightParen,
113    /// `[`
114    LeftBracket,
115    /// `]`
116    RightBracket,
117    /// `{`
118    LeftBrace,
119    /// `}`
120    RightBrace,
121    /// `,`
122    Comma,
123    /// `;`
124    Semicolon,
125    /// `:`
126    Colon,
127    /// `$`
128    Dollar,
129    /// `<>`
130    Append,
131    /// `<-`
132    LeftArrow,
133    /// `_`
134    Underscore,
135    /// Identifier.
136    Identifier,
137    /// Constructor.
138    Constructor,
139    /// Operator.
140    Operator,
141    /// String literal.
142    StringLiteral,
143    /// Integer literal.
144    IntLiteral,
145    /// Float literal.
146    NumberLiteral,
147    /// Char literal.
148    CharLiteral,
149
150    /// A module declaration.
151    ModuleDeclaration,
152    /// An import declaration.
153    ImportDeclaration,
154    /// A data declaration.
155    DataDeclaration,
156    /// A newtype declaration.
157    NewtypeDeclaration,
158    /// A type alias declaration.
159    TypeAliasDeclaration,
160    /// A class declaration.
161    ClassDeclaration,
162    /// An instance declaration.
163    InstanceDeclaration,
164    /// A foreign import declaration.
165    ForeignImportDeclaration,
166    /// A type signature.
167    TypeSignature,
168    /// A value declaration.
169    ValueDeclaration,
170    /// A pattern.
171    Pattern,
172    /// An expression.
173    Expression,
174    /// A literal expression.
175    LiteralExpression,
176    /// An identifier expression.
177    IdentifierExpression,
178    /// A prefix expression.
179    PrefixExpression,
180    /// An infix expression.
181    InfixExpression,
182    /// A function application.
183    ApplicationExpression,
184    /// A lambda expression.
185    LambdaExpression,
186    /// A let expression.
187    LetExpression,
188    /// A case expression.
189    CaseExpression,
190    /// A case arm.
191    CaseArm,
192    /// A do expression.
193    DoExpression,
194    /// A type.
195    TypeNode,
196
197    /// Source file node.
198    SourceFile,
199    /// `<<<`
200    Compose,
201    /// `>>>`
202    ComposeFlipped,
203    /// `$`
204    Apply,
205    /// `#`
206    ApplyFlipped,
207    /// `>>=`
208    Bind,
209    /// `=<<`
210    BindFlipped,
211    /// `?`
212    Question,
213    /// `!`
214    Exclamation,
215    /// `@`
216    At,
217    /// Backtick
218    Tick,
219    /// Upper case identifier
220    UpperIdentifier,
221    /// Qualified identifier
222    QualifiedIdentifier,
223    /// Boolean literal
224    BooleanLiteral,
225    /// Root node
226    Root,
227    /// End of file
228    Eof,
229    /// Error node.
230    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}