Skip to main content

oak_purescript/parser/
element_type.rs

1use oak_core::{ElementType, Parser, 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 PurescriptElementType {
8    Whitespace,
9    Newline,
10    Comment,
11    Ado,
12    Case,
13    Class,
14    Data,
15    Derive,
16    Do,
17    Else,
18    False,
19    Forall,
20    Foreign,
21    If,
22    Import,
23    In,
24    Infix,
25    Infixl,
26    Infixr,
27    Instance,
28    Let,
29    Module,
30    Newtype,
31    Of,
32    Then,
33    True,
34    Type,
35    Where,
36    Arrow,
37    FatArrow,
38    Backslash,
39    Pipe,
40    Equal,
41    ColonColon,
42    Dot,
43    DotDot,
44    Plus,
45    Minus,
46    Star,
47    Slash,
48    Percent,
49    Caret,
50    EqualEqual,
51    NotEqual,
52    Less,
53    Greater,
54    LessEqual,
55    GreaterEqual,
56    And,
57    Or,
58    Append,
59    Compose,
60    ComposeFlipped,
61    Apply,
62    ApplyFlipped,
63    Bind,
64    BindFlipped,
65    LeftParen,
66    RightParen,
67    LeftBrace,
68    RightBrace,
69    LeftBracket,
70    RightBracket,
71    Comma,
72    Semicolon,
73    Colon,
74    Question,
75    Exclamation,
76    At,
77    Underscore,
78    Tick,
79    IntLiteral,
80    NumberLiteral,
81    StringLiteral,
82    CharLiteral,
83    BooleanLiteral,
84    Identifier,
85    UpperIdentifier,
86    Operator,
87    QualifiedIdentifier,
88    Root,
89    SourceFile,
90    Error,
91    Eof,
92}
93
94impl ElementType for PurescriptElementType {
95    type Role = UniversalElementRole;
96
97    fn role(&self) -> Self::Role {
98        match self {
99            Self::Root => UniversalElementRole::Root,
100            Self::SourceFile => UniversalElementRole::Root,
101            Self::Error => UniversalElementRole::Error,
102            _ => UniversalElementRole::None,
103        }
104    }
105}
106
107impl From<crate::lexer::token_type::PurescriptTokenType> for PurescriptElementType {
108    fn from(token: crate::lexer::token_type::PurescriptTokenType) -> Self {
109        use crate::lexer::token_type::PurescriptTokenType as T;
110        match token {
111            T::Whitespace => Self::Whitespace,
112            T::Newline => Self::Newline,
113            T::Comment => Self::Comment,
114            T::Ado => Self::Ado,
115            T::Case => Self::Case,
116            T::Class => Self::Class,
117            T::Data => Self::Data,
118            T::Derive => Self::Derive,
119            T::Do => Self::Do,
120            T::Else => Self::Else,
121            T::False => Self::False,
122            T::Forall => Self::Forall,
123            T::Foreign => Self::Foreign,
124            T::If => Self::If,
125            T::Import => Self::Import,
126            T::In => Self::In,
127            T::Infix => Self::Infix,
128            T::Infixl => Self::Infixl,
129            T::Infixr => Self::Infixr,
130            T::Instance => Self::Instance,
131            T::Let => Self::Let,
132            T::Module => Self::Module,
133            T::Newtype => Self::Newtype,
134            T::Of => Self::Of,
135            T::Then => Self::Then,
136            T::True => Self::True,
137            T::Type => Self::Type,
138            T::Where => Self::Where,
139            T::Arrow => Self::Arrow,
140            T::FatArrow => Self::FatArrow,
141            T::Backslash => Self::Backslash,
142            T::Pipe => Self::Pipe,
143            T::Equal => Self::Equal,
144            T::ColonColon => Self::ColonColon,
145            T::Dot => Self::Dot,
146            T::DotDot => Self::DotDot,
147            T::Plus => Self::Plus,
148            T::Minus => Self::Minus,
149            T::Star => Self::Star,
150            T::Slash => Self::Slash,
151            T::Percent => Self::Percent,
152            T::Caret => Self::Caret,
153            T::EqualEqual => Self::EqualEqual,
154            T::NotEqual => Self::NotEqual,
155            T::Less => Self::Less,
156            T::Greater => Self::Greater,
157            T::LessEqual => Self::LessEqual,
158            T::GreaterEqual => Self::GreaterEqual,
159            T::And => Self::And,
160            T::Or => Self::Or,
161            T::Append => Self::Append,
162            T::Compose => Self::Compose,
163            T::ComposeFlipped => Self::ComposeFlipped,
164            T::Apply => Self::Apply,
165            T::ApplyFlipped => Self::ApplyFlipped,
166            T::Bind => Self::Bind,
167            T::BindFlipped => Self::BindFlipped,
168            T::LeftParen => Self::LeftParen,
169            T::RightParen => Self::RightParen,
170            T::LeftBrace => Self::LeftBrace,
171            T::RightBrace => Self::RightBrace,
172            T::LeftBracket => Self::LeftBracket,
173            T::RightBracket => Self::RightBracket,
174            T::Comma => Self::Comma,
175            T::Semicolon => Self::Semicolon,
176            T::Colon => Self::Colon,
177            T::Question => Self::Question,
178            T::Exclamation => Self::Exclamation,
179            T::At => Self::At,
180            T::Underscore => Self::Underscore,
181            T::Tick => Self::Tick,
182            T::IntLiteral => Self::IntLiteral,
183            T::NumberLiteral => Self::NumberLiteral,
184            T::StringLiteral => Self::StringLiteral,
185            T::CharLiteral => Self::CharLiteral,
186            T::BooleanLiteral => Self::BooleanLiteral,
187            T::Identifier => Self::Identifier,
188            T::UpperIdentifier => Self::UpperIdentifier,
189            T::Operator => Self::Operator,
190            T::QualifiedIdentifier => Self::QualifiedIdentifier,
191            T::Root => Self::Root,
192            T::SourceFile => Self::SourceFile,
193            T::Error => Self::Error,
194            T::Eof => Self::Eof,
195        }
196    }
197}