1use oak_core::{Token, TokenType, UniversalTokenRole};
2
3pub type PurescriptToken = Token<PurescriptTokenType>;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9pub enum PurescriptTokenType {
10 Whitespace,
12 Newline,
14 Comment,
16 Ado,
18 Case,
20 Class,
22 Data,
24 Derive,
26 Do,
28 Else,
30 False,
32 Forall,
34 Foreign,
36 If,
38 Import,
40 In,
42 Infix,
44 Infixl,
46 Infixr,
48 Instance,
50 Let,
52 Module,
54 Newtype,
56 Of,
58 Then,
60 True,
62 Type,
64 Where,
66 Arrow,
68 FatArrow,
70 Backslash,
72 Pipe,
74 Equal,
76 ColonColon,
78 Dot,
80 DotDot,
82 Plus,
84 Minus,
86 Star,
88 Slash,
90 Percent,
92 Caret,
94 EqualEqual,
96 NotEqual,
98 Less,
100 Greater,
102 LessEqual,
104 GreaterEqual,
106 And,
108 Or,
110 Append,
112 Compose,
114 ComposeFlipped,
116 Apply,
118 ApplyFlipped,
120 Bind,
122 BindFlipped,
124 LeftParen,
126 RightParen,
128 LeftBrace,
130 RightBrace,
132 LeftBracket,
134 RightBracket,
136 Comma,
138 Semicolon,
140 Colon,
142 Question,
144 Exclamation,
146 At,
148 Underscore,
150 Tick,
152 IntLiteral,
154 NumberLiteral,
156 StringLiteral,
158 CharLiteral,
160 BooleanLiteral,
162 Identifier,
164 UpperIdentifier,
166 Operator,
168 QualifiedIdentifier,
170 Root,
172 SourceFile,
174 Error,
176 Eof,
178}
179
180impl From<crate::parser::element_type::PurescriptElementType> for PurescriptTokenType {
181 fn from(element: crate::parser::element_type::PurescriptElementType) -> Self {
182 use crate::parser::element_type::PurescriptElementType as E;
183 match element {
184 E::Whitespace => Self::Whitespace,
185 E::Newline => Self::Newline,
186 E::Comment => Self::Comment,
187 E::Ado => Self::Ado,
188 E::Case => Self::Case,
189 E::Class => Self::Class,
190 E::Data => Self::Data,
191 E::Derive => Self::Derive,
192 E::Do => Self::Do,
193 E::Else => Self::Else,
194 E::False => Self::False,
195 E::Forall => Self::Forall,
196 E::Foreign => Self::Foreign,
197 E::If => Self::If,
198 E::Import => Self::Import,
199 E::In => Self::In,
200 E::Infix => Self::Infix,
201 E::Infixl => Self::Infixl,
202 E::Infixr => Self::Infixr,
203 E::Instance => Self::Instance,
204 E::Let => Self::Let,
205 E::Module => Self::Module,
206 E::Newtype => Self::Newtype,
207 E::Of => Self::Of,
208 E::Then => Self::Then,
209 E::True => Self::True,
210 E::Type => Self::Type,
211 E::Where => Self::Where,
212 E::Arrow => Self::Arrow,
213 E::FatArrow => Self::FatArrow,
214 E::Backslash => Self::Backslash,
215 E::Pipe => Self::Pipe,
216 E::Equal => Self::Equal,
217 E::ColonColon => Self::ColonColon,
218 E::Dot => Self::Dot,
219 E::DotDot => Self::DotDot,
220 E::Plus => Self::Plus,
221 E::Minus => Self::Minus,
222 E::Star => Self::Star,
223 E::Slash => Self::Slash,
224 E::Percent => Self::Percent,
225 E::Caret => Self::Caret,
226 E::EqualEqual => Self::EqualEqual,
227 E::NotEqual => Self::NotEqual,
228 E::Less => Self::Less,
229 E::Greater => Self::Greater,
230 E::LessEqual => Self::LessEqual,
231 E::GreaterEqual => Self::GreaterEqual,
232 E::And => Self::And,
233 E::Or => Self::Or,
234 E::Append => Self::Append,
235 E::Compose => Self::Compose,
236 E::ComposeFlipped => Self::ComposeFlipped,
237 E::Apply => Self::Apply,
238 E::ApplyFlipped => Self::ApplyFlipped,
239 E::Bind => Self::Bind,
240 E::BindFlipped => Self::BindFlipped,
241 E::LeftParen => Self::LeftParen,
242 E::RightParen => Self::RightParen,
243 E::LeftBrace => Self::LeftBrace,
244 E::RightBrace => Self::RightBrace,
245 E::LeftBracket => Self::LeftBracket,
246 E::RightBracket => Self::RightBracket,
247 E::Comma => Self::Comma,
248 E::Semicolon => Self::Semicolon,
249 E::Colon => Self::Colon,
250 E::Question => Self::Question,
251 E::Exclamation => Self::Exclamation,
252 E::At => Self::At,
253 E::Underscore => Self::Underscore,
254 E::Tick => Self::Tick,
255 E::IntLiteral => Self::IntLiteral,
256 E::NumberLiteral => Self::NumberLiteral,
257 E::StringLiteral => Self::StringLiteral,
258 E::CharLiteral => Self::CharLiteral,
259 E::BooleanLiteral => Self::BooleanLiteral,
260 E::Identifier => Self::Identifier,
261 E::UpperIdentifier => Self::UpperIdentifier,
262 E::Operator => Self::Operator,
263 E::QualifiedIdentifier => Self::QualifiedIdentifier,
264 E::Root => Self::Root,
265 E::SourceFile => Self::SourceFile,
266 E::Error => Self::Error,
267 E::Eof => Self::Eof,
268 _ => Self::Error,
269 }
270 }
271}
272
273impl TokenType for PurescriptTokenType {
274 type Role = UniversalTokenRole;
275 const END_OF_STREAM: Self = Self::Eof;
276
277 fn is_ignored(&self) -> bool {
278 match self {
279 Self::Whitespace | Self::Newline | Self::Comment => true,
280 _ => false,
281 }
282 }
283
284 fn role(&self) -> Self::Role {
285 match self {
286 Self::Whitespace | Self::Newline => UniversalTokenRole::Whitespace,
287 Self::Comment => UniversalTokenRole::Comment,
288 Self::Eof => UniversalTokenRole::Eof,
289 Self::Error => UniversalTokenRole::Error,
290 _ => UniversalTokenRole::None,
291 }
292 }
293}