tangled
alpha
login
or
join now
gearsco.de
/
just
3
fork
atom
A JavaScript lexer and syntax highlighter for Gleam!
3
fork
atom
overview
issues
pulls
pipelines
Add token type
gearsco.de
11 months ago
115baa14
0bd66c6f
+313
1 changed file
expand all
collapse all
unified
split
src
just
token.gleam
+313
src/just/token.gleam
···
1
1
+
pub type Token {
2
2
+
// Comments and whitespace
3
3
+
SingleLineComment(String)
4
4
+
MultiLineComment(String)
5
5
+
HashBangComment(String)
6
6
+
Whitespace(String)
7
7
+
8
8
+
// Literals
9
9
+
Identifier(String)
10
10
+
PrivateIdentifier(String)
11
11
+
Number(String)
12
12
+
BigInt(String)
13
13
+
String(quote: String, contents: String)
14
14
+
RegularExpression(String)
15
15
+
TemplateHead(tag: String, contents: String)
16
16
+
TemplateMiddle(String)
17
17
+
TemplateTail(String)
18
18
+
19
19
+
// Keywords
20
20
+
Break
21
21
+
Case
22
22
+
Catch
23
23
+
Class
24
24
+
Const
25
25
+
Continue
26
26
+
Debugger
27
27
+
Default
28
28
+
Delete
29
29
+
Do
30
30
+
Else
31
31
+
Export
32
32
+
Extends
33
33
+
False
34
34
+
Finally
35
35
+
For
36
36
+
Function
37
37
+
If
38
38
+
Import
39
39
+
In
40
40
+
Instanceof
41
41
+
New
42
42
+
Null
43
43
+
Return
44
44
+
Super
45
45
+
Switch
46
46
+
This
47
47
+
Throw
48
48
+
True
49
49
+
Try
50
50
+
Typeof
51
51
+
Var
52
52
+
Void
53
53
+
While
54
54
+
With
55
55
+
56
56
+
// Keywords in strict mode
57
57
+
Let
58
58
+
Static
59
59
+
Yield
60
60
+
61
61
+
// Keywords in an async function
62
62
+
Await
63
63
+
64
64
+
// Future reserved words
65
65
+
Enum
66
66
+
67
67
+
// Future reserved words in strict mode
68
68
+
Implements
69
69
+
Interface
70
70
+
Package
71
71
+
Private
72
72
+
Protected
73
73
+
74
74
+
// Contextual keywords
75
75
+
ContextualKeyword(ContextualKeyword)
76
76
+
77
77
+
// Grouping
78
78
+
LeftBrace
79
79
+
RightBrace
80
80
+
LeftParen
81
81
+
RightParen
82
82
+
LeftSquare
83
83
+
RightSquare
84
84
+
85
85
+
// Separators
86
86
+
Dot
87
87
+
TripleDot
88
88
+
Semicolon
89
89
+
Comma
90
90
+
Colon
91
91
+
Arrow
92
92
+
93
93
+
// Comparison
94
94
+
Less
95
95
+
Greater
96
96
+
LessEqual
97
97
+
GreaterEqual
98
98
+
DoubleEqual
99
99
+
BangEqual
100
100
+
TripleEqual
101
101
+
BangDoubleEqual
102
102
+
103
103
+
// Arithmetic
104
104
+
Plus
105
105
+
Minus
106
106
+
Star
107
107
+
Slash
108
108
+
Percent
109
109
+
DoubleStar
110
110
+
DoublePlus
111
111
+
DoubleMinus
112
112
+
DoubleLess
113
113
+
DoubleGreater
114
114
+
TripleGreater
115
115
+
Ampersand
116
116
+
Pipe
117
117
+
Caret
118
118
+
Tilde
119
119
+
120
120
+
// Logic
121
121
+
Bang
122
122
+
DoubleAmpersand
123
123
+
DoublePipe
124
124
+
Question
125
125
+
DoubleQuestion
126
126
+
QuestionDot
127
127
+
128
128
+
// Assignment
129
129
+
Equal
130
130
+
PlusEqual
131
131
+
MinusEqual
132
132
+
StarEqual
133
133
+
SlashEqual
134
134
+
PercentEqual
135
135
+
DoubleStarEqual
136
136
+
DoubleLessEqual
137
137
+
DoubleGreaterEqual
138
138
+
TripleGreaterEqual
139
139
+
AmpersandEqual
140
140
+
PipeEqual
141
141
+
CaratEqual
142
142
+
DoubleAmpersandEqual
143
143
+
DoublePipeEqual
144
144
+
DoubleQuestionEqual
145
145
+
}
146
146
+
147
147
+
pub type ContextualKeyword {
148
148
+
As
149
149
+
Async
150
150
+
From
151
151
+
Get
152
152
+
Of
153
153
+
Set
154
154
+
}
155
155
+
156
156
+
pub fn contextual_keyword_name(keyword: ContextualKeyword) -> String {
157
157
+
case keyword {
158
158
+
As -> "as"
159
159
+
Async -> "async"
160
160
+
From -> "from"
161
161
+
Get -> "get"
162
162
+
Of -> "of"
163
163
+
Set -> "set"
164
164
+
}
165
165
+
}
166
166
+
167
167
+
pub fn to_source(token: Token) -> String {
168
168
+
case token {
169
169
+
// Comments and whitespace
170
170
+
SingleLineComment(value) -> "//" <> value
171
171
+
MultiLineComment(value) -> "/*" <> value <> "*/"
172
172
+
HashBangComment(value) -> "#!" <> value
173
173
+
Whitespace(value) -> value
174
174
+
175
175
+
// Literals
176
176
+
Identifier(value) -> value
177
177
+
PrivateIdentifier(value) -> "#" <> value
178
178
+
Number(value) -> value
179
179
+
BigInt(value) -> value <> "n"
180
180
+
String(quote:, contents:) -> quote <> contents <> quote
181
181
+
RegularExpression(value) -> "/" <> value <> "/"
182
182
+
TemplateHead(tag:, contents:) -> tag <> "`" <> contents
183
183
+
TemplateMiddle(value) -> value
184
184
+
TemplateTail(value) -> value <> "`"
185
185
+
186
186
+
// Keywords
187
187
+
Break -> "break"
188
188
+
Case -> "case"
189
189
+
Catch -> "catch"
190
190
+
Class -> "class"
191
191
+
Const -> "const"
192
192
+
Continue -> "continue"
193
193
+
Debugger -> "debugger"
194
194
+
Default -> "default"
195
195
+
Delete -> "delete"
196
196
+
Do -> "do"
197
197
+
Else -> "else"
198
198
+
Export -> "export"
199
199
+
Extends -> "extends"
200
200
+
False -> "false"
201
201
+
Finally -> "finally"
202
202
+
For -> "for"
203
203
+
Function -> "function"
204
204
+
If -> "if"
205
205
+
Import -> "import"
206
206
+
In -> "in"
207
207
+
Instanceof -> "instanceof"
208
208
+
New -> "new"
209
209
+
Null -> "null"
210
210
+
Return -> "return"
211
211
+
Super -> "super"
212
212
+
Switch -> "switch"
213
213
+
This -> "this"
214
214
+
Throw -> "throw"
215
215
+
True -> "true"
216
216
+
Try -> "try"
217
217
+
Typeof -> "typeof"
218
218
+
Var -> "var"
219
219
+
Void -> "void"
220
220
+
While -> "while"
221
221
+
With -> "with"
222
222
+
223
223
+
// Keywords in strict mode
224
224
+
Let -> "let"
225
225
+
Static -> "static"
226
226
+
Yield -> "yield"
227
227
+
228
228
+
// Keywords in an async function
229
229
+
Await -> "await"
230
230
+
231
231
+
// Future reserved words
232
232
+
Enum -> "enum"
233
233
+
234
234
+
// Future reserved words in strict mode
235
235
+
Implements -> "implements"
236
236
+
Interface -> "interface"
237
237
+
Package -> "package"
238
238
+
Private -> "private"
239
239
+
Protected -> "protected"
240
240
+
241
241
+
// Contextual keywords
242
242
+
ContextualKeyword(keyword) -> contextual_keyword_name(keyword)
243
243
+
244
244
+
// Grouping
245
245
+
LeftBrace -> "{"
246
246
+
RightBrace -> "}"
247
247
+
LeftParen -> "("
248
248
+
RightParen -> ")"
249
249
+
LeftSquare -> "["
250
250
+
RightSquare -> "]"
251
251
+
252
252
+
// Separators
253
253
+
Dot -> "."
254
254
+
TripleDot -> "..."
255
255
+
Semicolon -> ";"
256
256
+
Comma -> ","
257
257
+
Colon -> ":"
258
258
+
Arrow -> "=>"
259
259
+
260
260
+
// Comparison
261
261
+
Less -> "<"
262
262
+
Greater -> ">"
263
263
+
LessEqual -> "<="
264
264
+
GreaterEqual -> ">="
265
265
+
DoubleEqual -> "=="
266
266
+
BangEqual -> "!="
267
267
+
TripleEqual -> "==="
268
268
+
BangDoubleEqual -> "!=="
269
269
+
270
270
+
// Arithmetic
271
271
+
Plus -> "+"
272
272
+
Minus -> "-"
273
273
+
Star -> "*"
274
274
+
Slash -> "/"
275
275
+
Percent -> "%"
276
276
+
DoubleStar -> "**"
277
277
+
DoublePlus -> "++"
278
278
+
DoubleMinus -> "--"
279
279
+
DoubleLess -> "<<"
280
280
+
DoubleGreater -> ">>"
281
281
+
TripleGreater -> ">>>"
282
282
+
Ampersand -> "&"
283
283
+
Pipe -> "|"
284
284
+
Caret -> "^"
285
285
+
Tilde -> "~"
286
286
+
287
287
+
// Logic
288
288
+
Bang -> "!"
289
289
+
DoubleAmpersand -> "&&"
290
290
+
DoublePipe -> "||"
291
291
+
Question -> "?"
292
292
+
DoubleQuestion -> "??"
293
293
+
QuestionDot -> "?."
294
294
+
295
295
+
// Assignment
296
296
+
Equal -> "="
297
297
+
PlusEqual -> "+="
298
298
+
MinusEqual -> "-="
299
299
+
StarEqual -> "*="
300
300
+
SlashEqual -> "/="
301
301
+
PercentEqual -> "%="
302
302
+
DoubleStarEqual -> "**="
303
303
+
DoubleLessEqual -> "<<="
304
304
+
DoubleGreaterEqual -> ">>="
305
305
+
TripleGreaterEqual -> ">>>="
306
306
+
AmpersandEqual -> "&="
307
307
+
PipeEqual -> "|="
308
308
+
CaratEqual -> "^="
309
309
+
DoubleAmpersandEqual -> "&&="
310
310
+
DoublePipeEqual -> "||="
311
311
+
DoubleQuestionEqual -> "??="
312
312
+
}
313
313
+
}