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