@exercism/codemirror-lang-purescript 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +107 -2
- package/dist/index.cjs +1010 -0
- package/dist/index.d.cts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +1002 -0
- package/package.json +51 -4
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1010 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var lr = require('@lezer/lr');
|
|
4
|
+
var language = require('@codemirror/language');
|
|
5
|
+
var highlight = require('@lezer/highlight');
|
|
6
|
+
var autocomplete = require('@codemirror/autocomplete');
|
|
7
|
+
var common = require('@lezer/common');
|
|
8
|
+
|
|
9
|
+
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
10
|
+
const LineComment = 1,
|
|
11
|
+
BlockComment = 2,
|
|
12
|
+
DocComment = 3,
|
|
13
|
+
blockOpen = 147,
|
|
14
|
+
blockEnd = 148,
|
|
15
|
+
blockSep = 149,
|
|
16
|
+
fieldDot = 150,
|
|
17
|
+
PropertyName = 4,
|
|
18
|
+
recordBrace = 151,
|
|
19
|
+
Qualifier = 5,
|
|
20
|
+
OperatorQualifier = 6,
|
|
21
|
+
DeclName = 7,
|
|
22
|
+
module$1 = 10,
|
|
23
|
+
closeParen = 12,
|
|
24
|
+
comma = 52,
|
|
25
|
+
closeBrace = 72,
|
|
26
|
+
where = 85,
|
|
27
|
+
_else = 89,
|
|
28
|
+
_in = 100,
|
|
29
|
+
then = 103,
|
|
30
|
+
of = 109,
|
|
31
|
+
closeBracket = 118;
|
|
32
|
+
|
|
33
|
+
// The external tokenizers and the layout tracker for the PureScript grammar.
|
|
34
|
+
// They are adapted from the Haskell grammar at
|
|
35
|
+
// https://codeberg.org/reeven/codemirror-lang-haskell (MIT, by CodinCod).
|
|
36
|
+
function isSpace(ch) {
|
|
37
|
+
return (ch == 32 /* Ch.Space */ ||
|
|
38
|
+
ch == 9 /* Ch.Tab */ ||
|
|
39
|
+
ch == 10 /* Ch.Newline */ ||
|
|
40
|
+
ch == 13 /* Ch.Return */ ||
|
|
41
|
+
ch == 12 /* Ch.FormFeed */ ||
|
|
42
|
+
ch == 11 /* Ch.VerticalTab */);
|
|
43
|
+
}
|
|
44
|
+
function isDigit(ch) {
|
|
45
|
+
return ch >= 48 /* Ch.Zero */ && ch <= 57 /* Ch.Nine */;
|
|
46
|
+
}
|
|
47
|
+
function isUpper(ch) {
|
|
48
|
+
return ch >= 65 /* Ch.UpperA */ && ch <= 90 /* Ch.UpperZ */;
|
|
49
|
+
}
|
|
50
|
+
// Everything above Latin-1 that the grammar doesn't read as an operator counts
|
|
51
|
+
// as a lowercase letter, which is close enough to read the names people write.
|
|
52
|
+
function isLower(ch) {
|
|
53
|
+
return ((ch >= 97 /* Ch.LowerA */ && ch <= 122 /* Ch.LowerZ */) ||
|
|
54
|
+
ch == 95 /* Ch.Underscore */ ||
|
|
55
|
+
(ch >= 161 /* Ch.Latin1 */ && ch < 8592 /* Ch.ArrowsFrom */) ||
|
|
56
|
+
ch >= 9312 /* Ch.LettersAgain */);
|
|
57
|
+
}
|
|
58
|
+
function isIdentifierStart(ch) {
|
|
59
|
+
return isLower(ch) || isUpper(ch);
|
|
60
|
+
}
|
|
61
|
+
function isIdentifierChar(ch) {
|
|
62
|
+
return isIdentifierStart(ch) || isDigit(ch) || ch == 39 /* Ch.Apostrophe */;
|
|
63
|
+
}
|
|
64
|
+
function isSymbol(ch) {
|
|
65
|
+
switch (ch) {
|
|
66
|
+
case 33 /* Ch.Bang */:
|
|
67
|
+
case 35 /* Ch.Hash */:
|
|
68
|
+
case 36 /* Ch.Dollar */:
|
|
69
|
+
case 37 /* Ch.Percent */:
|
|
70
|
+
case 38 /* Ch.Ampersand */:
|
|
71
|
+
case 42 /* Ch.Star */:
|
|
72
|
+
case 43 /* Ch.Plus */:
|
|
73
|
+
case 46 /* Ch.Dot */:
|
|
74
|
+
case 47 /* Ch.Slash */:
|
|
75
|
+
case 60 /* Ch.Less */:
|
|
76
|
+
case 61 /* Ch.Equals */:
|
|
77
|
+
case 62 /* Ch.Greater */:
|
|
78
|
+
case 63 /* Ch.Question */:
|
|
79
|
+
case 64 /* Ch.At */:
|
|
80
|
+
case 92 /* Ch.Backslash */:
|
|
81
|
+
case 94 /* Ch.Caret */:
|
|
82
|
+
case 124 /* Ch.Pipe */:
|
|
83
|
+
case 45 /* Ch.Minus */:
|
|
84
|
+
case 126 /* Ch.Tilde */:
|
|
85
|
+
case 58 /* Ch.Colon */:
|
|
86
|
+
return true;
|
|
87
|
+
default:
|
|
88
|
+
return ch >= 8592 /* Ch.ArrowsFrom */ && ch <= 8959 /* Ch.OperatorsTo */;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// The word that starts `offset` characters ahead, or "" if no word starts there.
|
|
92
|
+
function wordAt(input, offset) {
|
|
93
|
+
let word = "";
|
|
94
|
+
for (let pos = offset; isIdentifierChar(input.peek(pos)); pos++) {
|
|
95
|
+
word += String.fromCharCode(input.peek(pos));
|
|
96
|
+
}
|
|
97
|
+
return word;
|
|
98
|
+
}
|
|
99
|
+
// A line comment is two or more dashes with no other symbol after them, so
|
|
100
|
+
// `-->` stays an operator.
|
|
101
|
+
function startsComment(input, offset = 0) {
|
|
102
|
+
const next = input.peek(offset);
|
|
103
|
+
if (next == 123 /* Ch.BraceL */)
|
|
104
|
+
return input.peek(offset + 1) == 45 /* Ch.Minus */;
|
|
105
|
+
if (next != 45 /* Ch.Minus */ || input.peek(offset + 1) != 45 /* Ch.Minus */)
|
|
106
|
+
return false;
|
|
107
|
+
let pos = offset + 2;
|
|
108
|
+
while (input.peek(pos) == 45 /* Ch.Minus */)
|
|
109
|
+
pos++;
|
|
110
|
+
return !isSymbol(input.peek(pos));
|
|
111
|
+
}
|
|
112
|
+
// The position after any whitespace and comments that start at `pos`.
|
|
113
|
+
function skipSpace(input, pos) {
|
|
114
|
+
for (;;) {
|
|
115
|
+
const ch = input.peek(pos);
|
|
116
|
+
if (isSpace(ch))
|
|
117
|
+
pos++;
|
|
118
|
+
else if (ch == 45 /* Ch.Minus */ && startsComment(input, pos)) {
|
|
119
|
+
while (input.peek(pos) != 10 /* Ch.Newline */ && input.peek(pos) != -1 /* Ch.EOF */)
|
|
120
|
+
pos++;
|
|
121
|
+
}
|
|
122
|
+
else
|
|
123
|
+
return pos;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// ── Comments ──────────────────────────────────────────────────────────────────
|
|
127
|
+
/// Block comments nest here, so `{- {- -} -}` is one comment. A comment that
|
|
128
|
+
/// starts with `|`, such as `-- | Adds one`, is documentation.
|
|
129
|
+
const comments = new lr.ExternalTokenizer((input) => {
|
|
130
|
+
if (input.next == 45 /* Ch.Minus */) {
|
|
131
|
+
if (!startsComment(input))
|
|
132
|
+
return;
|
|
133
|
+
let pos = 2;
|
|
134
|
+
while (input.peek(pos) == 45 /* Ch.Minus */)
|
|
135
|
+
pos++;
|
|
136
|
+
let doc = false;
|
|
137
|
+
for (let scan = pos;; scan++) {
|
|
138
|
+
const ch = input.peek(scan);
|
|
139
|
+
if (ch == 32 /* Ch.Space */ || ch == 9 /* Ch.Tab */)
|
|
140
|
+
continue;
|
|
141
|
+
doc = ch == 124 /* Ch.Pipe */;
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
while (input.peek(pos) != 10 /* Ch.Newline */ && input.peek(pos) != -1 /* Ch.EOF */)
|
|
145
|
+
pos++;
|
|
146
|
+
input.acceptToken(doc ? DocComment : LineComment, pos);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (input.next != 123 /* Ch.BraceL */ || input.peek(1) != 45 /* Ch.Minus */)
|
|
150
|
+
return;
|
|
151
|
+
const doc = input.peek(2) == 124 /* Ch.Pipe */;
|
|
152
|
+
let depth = 0;
|
|
153
|
+
for (let pos = 0;; pos++) {
|
|
154
|
+
const ch = input.peek(pos);
|
|
155
|
+
if (ch == -1 /* Ch.EOF */) {
|
|
156
|
+
input.acceptToken(doc ? DocComment : BlockComment, pos);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (ch == 123 /* Ch.BraceL */ && input.peek(pos + 1) == 45 /* Ch.Minus */) {
|
|
160
|
+
depth++;
|
|
161
|
+
pos++;
|
|
162
|
+
}
|
|
163
|
+
else if (ch == 45 /* Ch.Minus */ && input.peek(pos + 1) == 125 /* Ch.BraceR */) {
|
|
164
|
+
depth--;
|
|
165
|
+
pos++;
|
|
166
|
+
if (!depth) {
|
|
167
|
+
input.acceptToken(doc ? DocComment : BlockComment, pos + 1);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
// ── Layout ────────────────────────────────────────────────────────────────────
|
|
174
|
+
/// One open block, and the column its items line up on.
|
|
175
|
+
class Layout {
|
|
176
|
+
constructor(parent, column) {
|
|
177
|
+
this.parent = parent;
|
|
178
|
+
this.column = column;
|
|
179
|
+
this.hash = (parent ? parent.hash * 31 : 0) + column;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// Nothing is open yet, and a block may open at any column, including the first.
|
|
183
|
+
const noLayout = new Layout(null, -1);
|
|
184
|
+
// The column a position stands in, and whether only whitespace stands in front
|
|
185
|
+
// of it on its line. Tabs advance to the next multiple of eight.
|
|
186
|
+
function lineInfo(input) {
|
|
187
|
+
const before = [];
|
|
188
|
+
for (let offset = -1; offset > -400; offset--) {
|
|
189
|
+
const ch = input.peek(offset);
|
|
190
|
+
if (ch == -1 /* Ch.EOF */ || ch == 10 /* Ch.Newline */ || ch == 13 /* Ch.Return */)
|
|
191
|
+
break;
|
|
192
|
+
before.push(ch);
|
|
193
|
+
}
|
|
194
|
+
let column = 0, firstOnLine = true;
|
|
195
|
+
for (let pos = before.length - 1; pos >= 0; pos--) {
|
|
196
|
+
const ch = before[pos];
|
|
197
|
+
if (ch == 9 /* Ch.Tab */)
|
|
198
|
+
column += 8 - (column % 8);
|
|
199
|
+
else
|
|
200
|
+
column++;
|
|
201
|
+
if (!isSpace(ch))
|
|
202
|
+
firstOnLine = false;
|
|
203
|
+
}
|
|
204
|
+
return { column, firstOnLine };
|
|
205
|
+
}
|
|
206
|
+
// A block also ends where the parser would otherwise fail, which is what ends
|
|
207
|
+
// the block in `let x = 1 in x` on one line. These are the tokens that often
|
|
208
|
+
// stand right after a block, so the tokenizer asks the parser about them.
|
|
209
|
+
function closesBlock(input, stack) {
|
|
210
|
+
switch (input.next) {
|
|
211
|
+
case 41 /* Ch.ParenR */:
|
|
212
|
+
return !stack.canShift(closeParen);
|
|
213
|
+
case 93 /* Ch.BracketR */:
|
|
214
|
+
return !stack.canShift(closeBracket);
|
|
215
|
+
case 125 /* Ch.BraceR */:
|
|
216
|
+
return !stack.canShift(closeBrace);
|
|
217
|
+
case 44 /* Ch.Comma */:
|
|
218
|
+
return !stack.canShift(comma);
|
|
219
|
+
}
|
|
220
|
+
if (!isIdentifierStart(input.next))
|
|
221
|
+
return false;
|
|
222
|
+
switch (wordAt(input, 0)) {
|
|
223
|
+
case "in":
|
|
224
|
+
return !stack.canShift(_in);
|
|
225
|
+
case "then":
|
|
226
|
+
return !stack.canShift(then);
|
|
227
|
+
case "else":
|
|
228
|
+
return !stack.canShift(_else);
|
|
229
|
+
case "of":
|
|
230
|
+
return !stack.canShift(of);
|
|
231
|
+
case "where":
|
|
232
|
+
return !stack.canShift(where);
|
|
233
|
+
default:
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/// The braces and semicolons that PureScript leaves out. A block opens at the
|
|
238
|
+
/// column of the first token after `where`, `do`, `ado`, `let` or `of`. An
|
|
239
|
+
/// item starts wherever a line begins at exactly that column. The block ends
|
|
240
|
+
/// at the first token to the left of that column, where the parser would
|
|
241
|
+
/// fail, or at the end of the file.
|
|
242
|
+
///
|
|
243
|
+
/// If a block's first token stands no further right than the block around it,
|
|
244
|
+
/// the block is empty and closes where it opened.
|
|
245
|
+
const layout = new lr.ExternalTokenizer((input, stack) => {
|
|
246
|
+
const cx = stack.context;
|
|
247
|
+
const open = cx.parent != null;
|
|
248
|
+
if (input.next == -1 /* Ch.EOF */) {
|
|
249
|
+
if (stack.canShift(blockOpen))
|
|
250
|
+
input.acceptToken(blockOpen);
|
|
251
|
+
else if (open && stack.canShift(blockEnd))
|
|
252
|
+
input.acceptToken(blockEnd);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
// The grammar skips whitespace and comments, so layout is decided in front
|
|
256
|
+
// of the tokens that are left.
|
|
257
|
+
if (isSpace(input.next) || startsComment(input))
|
|
258
|
+
return;
|
|
259
|
+
// The body of a module may open at the first token of the file, which is
|
|
260
|
+
// also where its header may stand. If there is a header, it wins.
|
|
261
|
+
if (stack.canShift(blockOpen)) {
|
|
262
|
+
if (stack.canShift(module$1) && wordAt(input, 0) == "module")
|
|
263
|
+
return;
|
|
264
|
+
input.acceptToken(blockOpen);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (!open)
|
|
268
|
+
return;
|
|
269
|
+
if (cx.column <= cx.parent.column && stack.canShift(blockEnd)) {
|
|
270
|
+
input.acceptToken(blockEnd);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const { column, firstOnLine } = lineInfo(input);
|
|
274
|
+
// An `else` at the start of an item continues an instance chain or an
|
|
275
|
+
// `if` in a `do` block, so it starts a new item and closes nothing.
|
|
276
|
+
const startsItem = firstOnLine && column == cx.column && wordAt(input, 0) == "else";
|
|
277
|
+
if (!startsItem && closesBlock(input, stack) && stack.canShift(blockEnd)) {
|
|
278
|
+
input.acceptToken(blockEnd);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
if (!firstOnLine)
|
|
282
|
+
return;
|
|
283
|
+
// No item in a block starts with `where`, so a `where` at the block's own
|
|
284
|
+
// column belongs to whatever the block is inside.
|
|
285
|
+
const closing = column < cx.column || (column == cx.column && wordAt(input, 0) == "where");
|
|
286
|
+
if (closing && stack.canShift(blockEnd))
|
|
287
|
+
input.acceptToken(blockEnd);
|
|
288
|
+
else if (column == cx.column && stack.canShift(blockSep))
|
|
289
|
+
input.acceptToken(blockSep);
|
|
290
|
+
}, { contextual: true });
|
|
291
|
+
/// The stack of open blocks. Each block remembers the column it opened on.
|
|
292
|
+
const trackLayout = new lr.ContextTracker({
|
|
293
|
+
start: noLayout,
|
|
294
|
+
shift(context, term, stack, input) {
|
|
295
|
+
var _a;
|
|
296
|
+
if (term == blockOpen)
|
|
297
|
+
return new Layout(context, lineInfo(input).column);
|
|
298
|
+
if (term == blockEnd)
|
|
299
|
+
return (_a = context.parent) !== null && _a !== void 0 ? _a : context;
|
|
300
|
+
return context;
|
|
301
|
+
},
|
|
302
|
+
hash: (context) => context.hash,
|
|
303
|
+
});
|
|
304
|
+
// ── Records ───────────────────────────────────────────────────────────────────
|
|
305
|
+
// The position after the label that starts at `pos`, or -1 if no label starts
|
|
306
|
+
// there. A label is a name or a string.
|
|
307
|
+
function labelEnd(input, pos) {
|
|
308
|
+
if (input.peek(pos) == 34 /* Ch.Quote */) {
|
|
309
|
+
for (pos++;; pos++) {
|
|
310
|
+
const ch = input.peek(pos);
|
|
311
|
+
if (ch == -1 /* Ch.EOF */ || ch == 10 /* Ch.Newline */)
|
|
312
|
+
return -1;
|
|
313
|
+
if (ch == 92 /* Ch.Backslash */)
|
|
314
|
+
pos++;
|
|
315
|
+
else if (ch == 34 /* Ch.Quote */)
|
|
316
|
+
return pos + 1;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (!isIdentifierStart(input.peek(pos)))
|
|
320
|
+
return -1;
|
|
321
|
+
while (isIdentifierChar(input.peek(pos)))
|
|
322
|
+
pos++;
|
|
323
|
+
return pos;
|
|
324
|
+
}
|
|
325
|
+
/// Three tokens that records need.
|
|
326
|
+
///
|
|
327
|
+
/// A dot with no space either side, as in `person.name` or `_.name`, reads a
|
|
328
|
+
/// field. PureScript has no `.` operator, so a dot in that position means
|
|
329
|
+
/// nothing else.
|
|
330
|
+
///
|
|
331
|
+
/// A field's name is read here as well, because a label may be any word,
|
|
332
|
+
/// including a keyword such as `type`.
|
|
333
|
+
///
|
|
334
|
+
/// A brace straight after a value opens a record update if its first field is
|
|
335
|
+
/// followed by `=`, as in `p { x = 1 }`. Otherwise the brace opens a record
|
|
336
|
+
/// literal, as in `f { x: 1 }`.
|
|
337
|
+
const fields = new lr.ExternalTokenizer((input, stack) => {
|
|
338
|
+
const next = input.next;
|
|
339
|
+
if (next == 46 /* Ch.Dot */) {
|
|
340
|
+
const before = input.peek(-1);
|
|
341
|
+
const after = input.peek(1);
|
|
342
|
+
const joined = isIdentifierChar(before) ||
|
|
343
|
+
before == 41 /* Ch.ParenR */ ||
|
|
344
|
+
before == 93 /* Ch.BracketR */ ||
|
|
345
|
+
before == 125 /* Ch.BraceR */ ||
|
|
346
|
+
before == 34 /* Ch.Quote */;
|
|
347
|
+
if (joined && (isIdentifierStart(after) || after == 34 /* Ch.Quote */) && stack.canShift(fieldDot))
|
|
348
|
+
input.acceptToken(fieldDot, 1);
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
if (next == 123 /* Ch.BraceL */) {
|
|
352
|
+
if (!stack.canShift(recordBrace))
|
|
353
|
+
return;
|
|
354
|
+
const end = labelEnd(input, skipSpace(input, 1));
|
|
355
|
+
if (end < 0)
|
|
356
|
+
return;
|
|
357
|
+
const after = skipSpace(input, end);
|
|
358
|
+
const ch = input.peek(after);
|
|
359
|
+
if ((ch == 61 /* Ch.Equals */ && !isSymbol(input.peek(after + 1))) || ch == 123 /* Ch.BraceL */)
|
|
360
|
+
input.acceptToken(recordBrace, 1);
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
if (isIdentifierStart(next) && stack.canShift(PropertyName)) {
|
|
364
|
+
let pos = 0;
|
|
365
|
+
while (isIdentifierChar(input.peek(pos)))
|
|
366
|
+
pos++;
|
|
367
|
+
input.acceptToken(PropertyName, pos);
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
// ── Names ─────────────────────────────────────────────────────────────────────
|
|
371
|
+
/// The module a name is read out of. `Data.Map.insert` is one name in three
|
|
372
|
+
/// parts, so the module part is read here and handed over as its own token.
|
|
373
|
+
const qualifiers = new lr.ExternalTokenizer((input, stack) => {
|
|
374
|
+
if (!isUpper(input.next))
|
|
375
|
+
return;
|
|
376
|
+
let pos = 0, end = 0, operator = false;
|
|
377
|
+
for (;;) {
|
|
378
|
+
if (!isUpper(input.peek(pos)))
|
|
379
|
+
break;
|
|
380
|
+
while (isIdentifierChar(input.peek(pos)))
|
|
381
|
+
pos++;
|
|
382
|
+
if (input.peek(pos) != 46 /* Ch.Dot */)
|
|
383
|
+
break;
|
|
384
|
+
const after = input.peek(pos + 1);
|
|
385
|
+
if (!isIdentifierStart(after) && !isSymbol(after))
|
|
386
|
+
break;
|
|
387
|
+
pos++;
|
|
388
|
+
end = pos;
|
|
389
|
+
operator = isSymbol(after);
|
|
390
|
+
}
|
|
391
|
+
if (!end)
|
|
392
|
+
return;
|
|
393
|
+
// `f M.x` applies a function and `f M.+ y` doesn't, so the tokenizer decides
|
|
394
|
+
// here whether an operator follows.
|
|
395
|
+
const term = operator ? OperatorQualifier : Qualifier;
|
|
396
|
+
if (stack.canShift(term))
|
|
397
|
+
input.acceptToken(term, end);
|
|
398
|
+
});
|
|
399
|
+
const reserved = new Set([
|
|
400
|
+
"ado",
|
|
401
|
+
"case",
|
|
402
|
+
"class",
|
|
403
|
+
"data",
|
|
404
|
+
"derive",
|
|
405
|
+
"do",
|
|
406
|
+
"else",
|
|
407
|
+
"false",
|
|
408
|
+
"forall",
|
|
409
|
+
"foreign",
|
|
410
|
+
"if",
|
|
411
|
+
"import",
|
|
412
|
+
"in",
|
|
413
|
+
"infix",
|
|
414
|
+
"infixl",
|
|
415
|
+
"infixr",
|
|
416
|
+
"instance",
|
|
417
|
+
"let",
|
|
418
|
+
"module",
|
|
419
|
+
"newtype",
|
|
420
|
+
"of",
|
|
421
|
+
"then",
|
|
422
|
+
"true",
|
|
423
|
+
"type",
|
|
424
|
+
"where",
|
|
425
|
+
"_",
|
|
426
|
+
]);
|
|
427
|
+
/// The name a declaration declares. `f x = x` declares `f`, and so does
|
|
428
|
+
/// `f :: Int -> Int`, but `x <+> y = ...` declares the operator between the two
|
|
429
|
+
/// names. The tokenizer looks one token ahead to decide.
|
|
430
|
+
///
|
|
431
|
+
/// If an operator follows the name, the name isn't the one being declared,
|
|
432
|
+
/// unless the operator is `::`, `=` or `|`. A backtick after the name means an
|
|
433
|
+
/// infix function is being declared. Anything else after the name, including
|
|
434
|
+
/// another name, a literal, a bracket and a comma, leaves the name a
|
|
435
|
+
/// declaration.
|
|
436
|
+
const declNames = new lr.ExternalTokenizer((input, stack) => {
|
|
437
|
+
if (!isLower(input.next) || !stack.canShift(DeclName))
|
|
438
|
+
return;
|
|
439
|
+
let pos = 0;
|
|
440
|
+
while (isIdentifierChar(input.peek(pos)))
|
|
441
|
+
pos++;
|
|
442
|
+
if (reserved.has(wordAt(input, 0)))
|
|
443
|
+
return;
|
|
444
|
+
const scan = skipSpace(input, pos);
|
|
445
|
+
const next = input.peek(scan);
|
|
446
|
+
if (next == 96 /* Ch.Backtick */)
|
|
447
|
+
return;
|
|
448
|
+
// `person.name = ...` isn't valid, but `x.y` in a pattern is never a
|
|
449
|
+
// declaration either.
|
|
450
|
+
if (next == 46 /* Ch.Dot */ && scan == pos)
|
|
451
|
+
return;
|
|
452
|
+
if (isSymbol(next)) {
|
|
453
|
+
const second = input.peek(scan + 1), third = input.peek(scan + 2);
|
|
454
|
+
const signature = (next == 58 /* Ch.Colon */ && second == 58 /* Ch.Colon */ && !isSymbol(third)) ||
|
|
455
|
+
(next == 8759 /* Ch.Colons */ && !isSymbol(second));
|
|
456
|
+
const body = (next == 61 /* Ch.Equals */ || next == 124 /* Ch.Pipe */) && !isSymbol(second);
|
|
457
|
+
if (!signature && !body)
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
input.acceptToken(DeclName, pos);
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
464
|
+
const spec_varid = {__proto__:null,module:20, type:34, class:36, kind:39, _:54, true:58, false:60, let:94, import:98, hiding:101, as:107, infixl:110, infixr:112, infix:114, forall:128, data:156, newtype:162, where:170, instance:174, else:178, derive:182, foreign:186, in:200, if:204, then:206, ado:210, case:216, of:218, do:226};
|
|
465
|
+
const spec_varsym = {__proto__:null,"?":70, "@":82, "\\":86, "->":88, "→":90, "∀":130, "=>":132, "⇒":134, "∷":138, "|":142, "=":152, "<-":196, "←":198};
|
|
466
|
+
const spec_consym = {__proto__:null,"::":136, ":":247};
|
|
467
|
+
const parser = lr.LRParser.deserialize({
|
|
468
|
+
version: 14,
|
|
469
|
+
states: "!)[O`QsOOO#zQ!]O'#GOQOQqOOOcQsOOO$RQyO'#CeOOQ_'#Cp'#CpO$ZQqO'#CpOOQ_'#Cq'#CqOOQZ'#Cs'#CsO$cQqO'#CsOOQZ'#Ct'#CtO&[Q!PO'#DTOOQX'#Fz'#FzO'kQ!PO'#FzO*bQ{O'#FzO,rQyO'#E_OOQR'#GP'#GPOOQR,5<j,5<jO,|QsO,5<jOOQR'#F|'#F|OOQZ'#G^'#G^OOQR'#F{'#F{O-UQ{O'#F{O.lQyO'#DSO/yQ{O'#FyOOQR'#Fy'#FyOOQZ'#Ga'#GaO1aQ{O'#GbOOQR'#Er'#ErO2yQyO'#ErOOQR'#Fx'#FxO3XQyO'#DQO3lQyO'#ExO4PQuO'#EyO4[Q!PO'#FsOOQ_'#Fu'#FuO5tQyO'#CvOOQZ'#Fp'#FpOOQ_'#Cx'#CxO6PQyO'#DOO6XQyO'#DWO$RQyO'#D^O7SQqO'#DdO7XQyO'#DhO7XQyO'#D{O7XQyO'#EOO7XQyO'#EQO8iQ!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%c%f&p&s&u&y'R'W(P(V(Y(^(_Q$e!vQ%c#qQ&u%UQ'R%eQ'W%hQ(^'TR(_'VS#Oq$lS$p#S&cT%U#h&vQ%]#mR%^#nS!l_!TR$V!iQ$Z!jQ'm&RR)r)^Q&P$XR'[%lQ#y!WR#{!YQ%o#xR(e']Seg!q!dfPop!V!X!j!k!m#x$f$k$v%i%j%p&P&R&T&b'Z'[']'b'o(a)U)W)[)^)_)k)|)}Q!ukQ$c!sR&W$aQ'c%rR(h'aQ)](iR)n)X!dmPop!V!X!j!k!m#x$f$k$v%i%j%p&P&R&T&b'Z'[']'b'o(a)U)W)[)^)_)k)|)}R!uk!dlPop!V!X!j!k!m#x$f$k$v%i%j%p&P&R&T&b'Z'[']'b'o(a)U)W)[)^)_)k)|)}S!pfmQ!tkR$d!uQ(p'eR)v)b",
|
|
472
|
+
nodeNames: "⚠ LineComment BlockComment DocComment PropertyName Qualifier OperatorQualifier DeclName Module ModuleHeader module ModuleName ) ( ExportList ModuleExport ExportItem type class kind Variable Constructor ParenOperator Operator ConstructorOperator ` BacktickOperator Wildcard Boolean true false Number String Char Hole ? ParenExpression Annotated ApplyExpression Callee AsPattern @ LambdaExpression \\ -> -> LetExpression let ImportDeclaration import hiding ImportList , as FixityDeclaration infixl infixr infix TypeSynonym Type TypeConstructor TypeVariable TypeOperator TypeConstructorOperator forall forall => => :: :: ParenType | } { RecordType FieldDeclaration = DataDeclaration data ConstructorDeclaration NewtypeDeclaration newtype ClassDeclaration FunctionalDependencies WhereBlock where InstanceDeclaration instance InstanceChain else DeriveDeclaration derive ForeignDeclaration foreign TypeSignature Bind GuardedEquation LetStatement <- <- in IfExpression if then AdoExpression ado BindStatement CaseExpression case of CaseAlternative GuardedEquation DoExpression do OperatorExpression ApplyExpression ApplyExpression ApplyExpression ] [ ArrayExpression Record FieldBind : FieldAccess RecordUpdate RecordUpdateFields FieldUpdate SubordinateList",
|
|
473
|
+
maxTerm: 191,
|
|
474
|
+
context: trackLayout,
|
|
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'S;=`,o<%lO+_~+tTOr+_rs,Ts;'S+_;'S;=`,o<%lO+_~,WTOr+_rs,gs;'S+_;'S;=`,o<%lO+_~,lPp~rs,g~,rP;=`<%l+_~,xVOY-_Zw-_x#O-_#O#P-j#P;'S-_;'S;=`.l<%lO-_~-bPwx-e~-jOq~~-mUOY.PZw.Pwx-_x;'S.P;'S;=`.f<%lO.P~.SUOY.PZw.Pwx-ex;'S.P;'S;=`.f<%lO.P~.iP;=`<%l.P~.oP;=`<%l-_~.wO]~~.|O[~~/RO!U~~/WVo~!O!P/m!Q![0s!g!h0U!z!{1X#R#S0s#X#Y0U#l#m1X~/pP!Q![/s~/xSo~!Q![/s!g!h0U#R#S/s#X#Y0U~0XR{|0b}!O0b!Q![0h~0eP!Q![0h~0mQo~!Q![0h#R#S0h~0xTo~!O!P/m!Q![0s!g!h0U#R#S0s#X#Y0U~1[R!Q![1e!c!i1e#T#Z1e~1jRo~!Q![1e!c!i1e#T#Z1e~1xe$f~qr1sst1stu1suv1svw1sz{1s{|1s}!O1s!O!P1s!P!Q1s![!]1s!^!_1s!_!`1s!`!a1s!a!b1s!b!c1s#O#P1s#Q#R1s#p#q1s#r#s1s%#t%+t1s~3`X$a~wx3Z!Q![3Z!c!}3Z#R#S3Z#T#o3Z$g$Ii3Z%3d;'S3Z;'S;=`3{<%lO3Z~4OP;=`<%l3Z~4WO#k~~4]O#j~~4bX$`~wx4]!Q![4]!c!}4]#R#S4]#T#o4]$g$Ii4]%3d;'S4];'S;=`4}<%lO4]~5QP;=`<%l4]~5YOi~~5_O!k~~5dO!j~",
|
|
483
|
+
tokenizers: [comments, layout, fields, qualifiers, declNames, 0],
|
|
484
|
+
topRules: {"Module":[0,8]},
|
|
485
|
+
specialized: [{term: 154, get: (value) => spec_varid[value] || -1},{term: 159, get: (value) => spec_varsym[value] || -1},{term: 160, get: (value) => spec_consym[value] || -1}],
|
|
486
|
+
tokenPrec: 0
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
/// Snippets for the constructs people write most often in PureScript.
|
|
490
|
+
const snippets = [
|
|
491
|
+
autocomplete.snippetCompletion("${name} :: ${Type}\n${name} ${args} = ${}", {
|
|
492
|
+
label: "fun",
|
|
493
|
+
detail: "function with signature",
|
|
494
|
+
type: "keyword",
|
|
495
|
+
}),
|
|
496
|
+
autocomplete.snippetCompletion("${name} ${args}\n | ${condition} = ${}\n | otherwise = ${}", {
|
|
497
|
+
label: "guard",
|
|
498
|
+
detail: "function with guards",
|
|
499
|
+
type: "keyword",
|
|
500
|
+
}),
|
|
501
|
+
autocomplete.snippetCompletion("case ${expression} of\n ${pattern} -> ${}", {
|
|
502
|
+
label: "case",
|
|
503
|
+
detail: "expression",
|
|
504
|
+
type: "keyword",
|
|
505
|
+
}),
|
|
506
|
+
autocomplete.snippetCompletion("if ${condition} then ${} else ${}", {
|
|
507
|
+
label: "if",
|
|
508
|
+
detail: "then else",
|
|
509
|
+
type: "keyword",
|
|
510
|
+
}),
|
|
511
|
+
autocomplete.snippetCompletion("let\n ${name} = ${value}\nin ${}", {
|
|
512
|
+
label: "let",
|
|
513
|
+
detail: "in",
|
|
514
|
+
type: "keyword",
|
|
515
|
+
}),
|
|
516
|
+
autocomplete.snippetCompletion("where\n ${name} = ${}", {
|
|
517
|
+
label: "where",
|
|
518
|
+
detail: "block",
|
|
519
|
+
type: "keyword",
|
|
520
|
+
}),
|
|
521
|
+
autocomplete.snippetCompletion("do\n ${x} <- ${action}\n ${}", {
|
|
522
|
+
label: "do",
|
|
523
|
+
detail: "block",
|
|
524
|
+
type: "keyword",
|
|
525
|
+
}),
|
|
526
|
+
autocomplete.snippetCompletion("\\${x} -> ${}", {
|
|
527
|
+
label: "\\",
|
|
528
|
+
detail: "lambda",
|
|
529
|
+
type: "keyword",
|
|
530
|
+
}),
|
|
531
|
+
autocomplete.snippetCompletion("foldl (\\${acc} ${x} -> ${}) ${initial} ${xs}", {
|
|
532
|
+
label: "foldl",
|
|
533
|
+
detail: "fold with a lambda",
|
|
534
|
+
type: "keyword",
|
|
535
|
+
}),
|
|
536
|
+
autocomplete.snippetCompletion("data ${Name} = ${Constructor}", {
|
|
537
|
+
label: "data",
|
|
538
|
+
detail: "type definition",
|
|
539
|
+
type: "keyword",
|
|
540
|
+
}),
|
|
541
|
+
autocomplete.snippetCompletion("newtype ${Name} = ${Name} ${Type}", {
|
|
542
|
+
label: "newtype",
|
|
543
|
+
detail: "definition",
|
|
544
|
+
type: "keyword",
|
|
545
|
+
}),
|
|
546
|
+
autocomplete.snippetCompletion("type ${Name} = { ${field} :: ${Type} }", {
|
|
547
|
+
label: "type",
|
|
548
|
+
detail: "record synonym",
|
|
549
|
+
type: "keyword",
|
|
550
|
+
}),
|
|
551
|
+
autocomplete.snippetCompletion("class ${Name} ${a} where\n ${method} :: ${a} -> ${}", {
|
|
552
|
+
label: "class",
|
|
553
|
+
detail: "definition",
|
|
554
|
+
type: "keyword",
|
|
555
|
+
}),
|
|
556
|
+
autocomplete.snippetCompletion("instance ${Class} ${Type} where\n ${method} = ${}", {
|
|
557
|
+
label: "instance",
|
|
558
|
+
detail: "definition",
|
|
559
|
+
type: "keyword",
|
|
560
|
+
}),
|
|
561
|
+
autocomplete.snippetCompletion("derive instance ${Eq} ${Type}", {
|
|
562
|
+
label: "derive",
|
|
563
|
+
detail: "instance",
|
|
564
|
+
type: "keyword",
|
|
565
|
+
}),
|
|
566
|
+
autocomplete.snippetCompletion("import ${Data.Map} as ${Map}", {
|
|
567
|
+
label: "import",
|
|
568
|
+
detail: "as",
|
|
569
|
+
type: "keyword",
|
|
570
|
+
}),
|
|
571
|
+
autocomplete.snippetCompletion("module ${Name} (${exports}) where\n\nimport Prelude\n\n${}", {
|
|
572
|
+
label: "module",
|
|
573
|
+
detail: "header",
|
|
574
|
+
type: "keyword",
|
|
575
|
+
}),
|
|
576
|
+
];
|
|
577
|
+
const keywords = ("module import as hiding where let in do ado case of if then else " +
|
|
578
|
+
"data newtype type class instance derive foreign infix infixl infixr forall")
|
|
579
|
+
.split(" ")
|
|
580
|
+
.map((label) => ({ label, type: "keyword" }));
|
|
581
|
+
const constants = ["true", "false", "unit"].map((label) => ({ label, type: "constant" }));
|
|
582
|
+
// The functions exported by Prelude, and the ones people most often import
|
|
583
|
+
// from Data.Array, Data.Foldable, Data.Maybe, Data.String, Data.Tuple,
|
|
584
|
+
// Data.Either, Data.Map, Data.Int and Effect.Console.
|
|
585
|
+
const functions = [
|
|
586
|
+
// Prelude
|
|
587
|
+
"add", "append", "apply", "bind", "between", "bottom", "clamp", "compare",
|
|
588
|
+
"comparing", "conj", "const", "disj", "discard", "div", "eq", "flap", "flip",
|
|
589
|
+
"gcd", "identity", "join", "lcm", "liftA1", "liftM1", "map", "max", "mempty",
|
|
590
|
+
"min", "mod", "mul", "negate", "not", "notEq", "one", "otherwise", "pure",
|
|
591
|
+
"recip", "show", "sub", "top", "unless", "void", "when", "zero",
|
|
592
|
+
// Data.Array and Data.Foldable
|
|
593
|
+
"all", "any", "catMaybes", "concat", "concatMap", "cons", "drop", "dropWhile",
|
|
594
|
+
"elem", "filter", "find", "findIndex", "foldl", "foldMap", "foldr", "for_",
|
|
595
|
+
"fromFoldable", "group", "head", "index", "init", "insertAt", "intercalate",
|
|
596
|
+
"last", "length", "mapMaybe", "mapWithIndex", "maximum", "minimum", "notElem",
|
|
597
|
+
"nub", "null", "partition", "product", "range", "replicate", "reverse",
|
|
598
|
+
"singleton", "snoc", "sort", "sortBy", "sortWith", "span", "sum", "tail",
|
|
599
|
+
"take", "takeWhile", "toUnfoldable", "traverse", "traverse_", "uncons",
|
|
600
|
+
"unzip", "updateAt", "zip", "zipWith", "sequence", "for", "and", "or",
|
|
601
|
+
// Data.Maybe and Data.Either
|
|
602
|
+
"fromJust", "fromMaybe", "isJust", "isNothing", "maybe", "either", "isLeft",
|
|
603
|
+
"isRight", "hush", "note",
|
|
604
|
+
// Data.String and Data.String.CodeUnits
|
|
605
|
+
"charAt", "contains", "fromCharArray", "indexOf", "joinWith", "replace",
|
|
606
|
+
"replaceAll", "split", "toCharArray", "toLower", "toUpper", "trim",
|
|
607
|
+
// Data.Tuple
|
|
608
|
+
"curry", "fst", "snd", "swap", "uncurry",
|
|
609
|
+
// Data.Map
|
|
610
|
+
"alter", "empty", "insert", "insertWith", "keys", "lookup", "member",
|
|
611
|
+
"unionWith", "update", "values", "delete",
|
|
612
|
+
// Data.Int and Data.Char
|
|
613
|
+
"ceil", "even", "floor", "fromString", "odd", "pow", "quot", "rem", "round",
|
|
614
|
+
"toNumber", "fromCharCode", "toCharCode",
|
|
615
|
+
// Effect.Console
|
|
616
|
+
"log", "logShow",
|
|
617
|
+
];
|
|
618
|
+
const types = [
|
|
619
|
+
"Array", "Boolean", "Char", "Effect", "Either", "Int", "List", "Map", "Maybe",
|
|
620
|
+
"Number", "Ordering", "Record", "Set", "String", "Tuple", "Type", "Unit",
|
|
621
|
+
"Applicative", "Apply", "Bind", "Bounded", "CommutativeRing", "Eq",
|
|
622
|
+
"EuclideanRing", "Field", "Foldable", "Functor", "HeytingAlgebra", "Monad",
|
|
623
|
+
"Monoid", "Ord", "Ring", "Semigroup", "Semiring", "Show", "Traversable",
|
|
624
|
+
].map((label) => ({ label, type: "type" }));
|
|
625
|
+
const constructors = [
|
|
626
|
+
"Just", "Nothing", "Left", "Right", "Tuple", "LT", "EQ", "GT", "Nil", "Cons",
|
|
627
|
+
"Pattern", "Replacement",
|
|
628
|
+
].map((label) => ({ label, type: "constant" }));
|
|
629
|
+
const globals = [
|
|
630
|
+
...snippets,
|
|
631
|
+
...keywords,
|
|
632
|
+
...constants,
|
|
633
|
+
...[...new Set(functions)].map((label) => ({ label, type: "function" })),
|
|
634
|
+
...types,
|
|
635
|
+
...constructors,
|
|
636
|
+
];
|
|
637
|
+
// Every node here opens a scope: the names it binds are visible inside it and
|
|
638
|
+
// nowhere else. A `where` belongs to the binding or alternative above it, so it
|
|
639
|
+
// is read as part of that node's scope.
|
|
640
|
+
const ScopeNodes = new Set([
|
|
641
|
+
"Module",
|
|
642
|
+
"Bind",
|
|
643
|
+
"LambdaExpression",
|
|
644
|
+
"CaseAlternative",
|
|
645
|
+
"DoExpression",
|
|
646
|
+
"AdoExpression",
|
|
647
|
+
"LetExpression",
|
|
648
|
+
"GuardedEquation",
|
|
649
|
+
]);
|
|
650
|
+
// A pattern is written as an expression, so its variables are the unqualified
|
|
651
|
+
// `Variable` nodes in it. In a record pattern, `{ name }` binds `name`, and
|
|
652
|
+
// `{ name: n }` binds `n`.
|
|
653
|
+
const notPattern = new Set([
|
|
654
|
+
"Callee",
|
|
655
|
+
"Type",
|
|
656
|
+
"LambdaExpression",
|
|
657
|
+
"CaseAlternative",
|
|
658
|
+
"CaseExpression",
|
|
659
|
+
"DoExpression",
|
|
660
|
+
"AdoExpression",
|
|
661
|
+
"LetExpression",
|
|
662
|
+
]);
|
|
663
|
+
function patternVariables(node, def) {
|
|
664
|
+
var _a;
|
|
665
|
+
if (node.name == "Variable") {
|
|
666
|
+
if (!node.firstChild)
|
|
667
|
+
def(node, "variable");
|
|
668
|
+
}
|
|
669
|
+
else if (node.name == "FieldBind") {
|
|
670
|
+
const label = node.firstChild;
|
|
671
|
+
const value = (_a = label === null || label === void 0 ? void 0 : label.nextSibling) === null || _a === void 0 ? void 0 : _a.nextSibling;
|
|
672
|
+
if (value)
|
|
673
|
+
patternVariables(value, def);
|
|
674
|
+
else if ((label === null || label === void 0 ? void 0 : label.name) == "PropertyName")
|
|
675
|
+
def(label, "variable");
|
|
676
|
+
}
|
|
677
|
+
else if (!notPattern.has(node.name)) {
|
|
678
|
+
for (let ch = node.firstChild; ch; ch = ch.nextSibling)
|
|
679
|
+
patternVariables(ch, def);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
function isRhs(node) {
|
|
683
|
+
return (node.name == "=" || node.name == "->" || node.name == "GuardedEquation" || node.name == "WhereBlock");
|
|
684
|
+
}
|
|
685
|
+
// `x <+> y = ...` defines an operator, and the operands are its parameters.
|
|
686
|
+
function definesOperator(lhs) {
|
|
687
|
+
if (lhs.name != "OperatorExpression")
|
|
688
|
+
return false;
|
|
689
|
+
for (let ch = lhs.firstChild; ch; ch = ch.nextSibling)
|
|
690
|
+
if (ch.name == "Operator" || ch.name == "BacktickOperator")
|
|
691
|
+
return true;
|
|
692
|
+
return false;
|
|
693
|
+
}
|
|
694
|
+
// The name a type declaration introduces is the first constructor in its head,
|
|
695
|
+
// after any context. `class Eq a <= Ord a` declares `Ord`, and
|
|
696
|
+
// `class (Eq a) => Ord a` does too.
|
|
697
|
+
function declaredType(type) {
|
|
698
|
+
if (!type)
|
|
699
|
+
return null;
|
|
700
|
+
let found = null;
|
|
701
|
+
for (let ch = type.firstChild; ch; ch = ch.nextSibling) {
|
|
702
|
+
if (ch.name == "=>")
|
|
703
|
+
found = null;
|
|
704
|
+
else if (ch.name == "TypeOperator" && ch.to - ch.from == 2)
|
|
705
|
+
found = null;
|
|
706
|
+
else if (ch.name == "TypeConstructor" && !found)
|
|
707
|
+
found = ch;
|
|
708
|
+
}
|
|
709
|
+
return found;
|
|
710
|
+
}
|
|
711
|
+
function gatherTypeDeclaration(node, def) {
|
|
712
|
+
const name = declaredType(node.getChild("Type"));
|
|
713
|
+
if (name)
|
|
714
|
+
def(name, node.name == "ClassDeclaration" ? "class" : "type");
|
|
715
|
+
for (const con of node.getChildren("ConstructorDeclaration")) {
|
|
716
|
+
const type = con.getChild("Type");
|
|
717
|
+
const name = type === null || type === void 0 ? void 0 : type.getChild("TypeConstructor");
|
|
718
|
+
if (name)
|
|
719
|
+
def(name, "constant");
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
// What a node declares into the scope around it. Returning true stops the walk
|
|
723
|
+
// going into the node.
|
|
724
|
+
const gatherers = {
|
|
725
|
+
Bind(node, def) {
|
|
726
|
+
const first = node.firstChild;
|
|
727
|
+
if ((first === null || first === void 0 ? void 0 : first.name) == "DeclName") {
|
|
728
|
+
const hasParams = first.nextSibling && !isRhs(first.nextSibling);
|
|
729
|
+
def(first, hasParams ? "function" : "variable");
|
|
730
|
+
}
|
|
731
|
+
else if (first && !definesOperator(first)) {
|
|
732
|
+
patternVariables(first, def);
|
|
733
|
+
}
|
|
734
|
+
return true;
|
|
735
|
+
},
|
|
736
|
+
TypeSignature(node, def) {
|
|
737
|
+
var _a;
|
|
738
|
+
const isFunction = !!((_a = node.getChild("Type")) === null || _a === void 0 ? void 0 : _a.getChild("->"));
|
|
739
|
+
for (const n of node.getChildren("DeclName"))
|
|
740
|
+
def(n, isFunction ? "function" : "variable");
|
|
741
|
+
return true;
|
|
742
|
+
},
|
|
743
|
+
ForeignDeclaration(node, def) {
|
|
744
|
+
var _a, _b;
|
|
745
|
+
const isFunction = !!((_a = node.getChild("Type")) === null || _a === void 0 ? void 0 : _a.getChild("->"));
|
|
746
|
+
const name = (_b = node.getChild("DeclName")) !== null && _b !== void 0 ? _b : node.getChild("TypeConstructor");
|
|
747
|
+
if (name)
|
|
748
|
+
def(name, name.name == "DeclName" ? (isFunction ? "function" : "variable") : "type");
|
|
749
|
+
return true;
|
|
750
|
+
},
|
|
751
|
+
DataDeclaration(node, def) {
|
|
752
|
+
gatherTypeDeclaration(node, def);
|
|
753
|
+
return true;
|
|
754
|
+
},
|
|
755
|
+
NewtypeDeclaration(node, def) {
|
|
756
|
+
gatherTypeDeclaration(node, def);
|
|
757
|
+
return true;
|
|
758
|
+
},
|
|
759
|
+
TypeSynonym(node, def) {
|
|
760
|
+
gatherTypeDeclaration(node, def);
|
|
761
|
+
return true;
|
|
762
|
+
},
|
|
763
|
+
ClassDeclaration(node, def) {
|
|
764
|
+
gatherTypeDeclaration(node, def);
|
|
765
|
+
return false;
|
|
766
|
+
},
|
|
767
|
+
BindStatement(node, def) {
|
|
768
|
+
if (node.firstChild)
|
|
769
|
+
patternVariables(node.firstChild, def);
|
|
770
|
+
return false;
|
|
771
|
+
},
|
|
772
|
+
ImportDeclaration(node, def) {
|
|
773
|
+
var _a;
|
|
774
|
+
const alias = (_a = node.getChild("as")) === null || _a === void 0 ? void 0 : _a.nextSibling;
|
|
775
|
+
if ((alias === null || alias === void 0 ? void 0 : alias.name) == "ModuleName")
|
|
776
|
+
def(alias, "namespace");
|
|
777
|
+
return true;
|
|
778
|
+
},
|
|
779
|
+
InstanceDeclaration() {
|
|
780
|
+
return true;
|
|
781
|
+
},
|
|
782
|
+
};
|
|
783
|
+
// The names a scope node binds itself: a function's parameters, a lambda's
|
|
784
|
+
// arguments, the variables in a `case` pattern or a pattern guard.
|
|
785
|
+
function ownBindings(node, def) {
|
|
786
|
+
var _a;
|
|
787
|
+
switch (node.name) {
|
|
788
|
+
case "Bind": {
|
|
789
|
+
const first = node.firstChild;
|
|
790
|
+
if ((first === null || first === void 0 ? void 0 : first.name) == "DeclName") {
|
|
791
|
+
for (let ch = first.nextSibling; ch && !isRhs(ch); ch = ch.nextSibling)
|
|
792
|
+
patternVariables(ch, def);
|
|
793
|
+
}
|
|
794
|
+
else if (first && definesOperator(first)) {
|
|
795
|
+
patternVariables(first, def);
|
|
796
|
+
}
|
|
797
|
+
break;
|
|
798
|
+
}
|
|
799
|
+
case "LambdaExpression":
|
|
800
|
+
for (let ch = (_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.nextSibling; ch && ch.name != "->"; ch = ch.nextSibling)
|
|
801
|
+
patternVariables(ch, def);
|
|
802
|
+
break;
|
|
803
|
+
case "CaseAlternative":
|
|
804
|
+
for (let ch = node.firstChild; ch && !isRhs(ch); ch = ch.nextSibling)
|
|
805
|
+
patternVariables(ch, def);
|
|
806
|
+
break;
|
|
807
|
+
case "GuardedEquation":
|
|
808
|
+
for (let ch = node.firstChild; ch; ch = ch.nextSibling)
|
|
809
|
+
if (ch.name == "<-" && ch.prevSibling)
|
|
810
|
+
patternVariables(ch.prevSibling, def);
|
|
811
|
+
break;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
const cache = new common.NodeWeakMap();
|
|
815
|
+
function getScope(doc, node) {
|
|
816
|
+
const cached = cache.get(node);
|
|
817
|
+
if (cached)
|
|
818
|
+
return cached;
|
|
819
|
+
const completions = [];
|
|
820
|
+
const seen = new Set();
|
|
821
|
+
const def = (n, type) => {
|
|
822
|
+
const label = doc.sliceString(n.from, n.to);
|
|
823
|
+
if (!label || seen.has(label))
|
|
824
|
+
return;
|
|
825
|
+
seen.add(label);
|
|
826
|
+
completions.push({ label, type });
|
|
827
|
+
};
|
|
828
|
+
ownBindings(node, def);
|
|
829
|
+
const walk = (parent) => {
|
|
830
|
+
for (let ch = parent.firstChild; ch; ch = ch.nextSibling) {
|
|
831
|
+
const gather = gatherers[ch.name];
|
|
832
|
+
if (gather && gather(ch, def))
|
|
833
|
+
continue;
|
|
834
|
+
if (!ScopeNodes.has(ch.name))
|
|
835
|
+
walk(ch);
|
|
836
|
+
}
|
|
837
|
+
};
|
|
838
|
+
walk(node);
|
|
839
|
+
cache.set(node, completions);
|
|
840
|
+
return completions;
|
|
841
|
+
}
|
|
842
|
+
const Identifier = /^[\w'\xa1-]*$/;
|
|
843
|
+
const dontComplete = ["String", "Char", "Number", "LineComment", "BlockComment", "DocComment"];
|
|
844
|
+
// True if the word being typed follows a dot, as in `Map.l` or `person.n`.
|
|
845
|
+
// Neither asks for a name declared in scope.
|
|
846
|
+
function afterDot(context, from) {
|
|
847
|
+
return context.state.sliceDoc(Math.max(0, from - 1), from) == ".";
|
|
848
|
+
}
|
|
849
|
+
/// Completes the names declared in the file that are in scope at the cursor:
|
|
850
|
+
/// top-level functions, types and constructors, parameters, pattern
|
|
851
|
+
/// variables, and the bindings of `let`, `where`, `do` and `ado`.
|
|
852
|
+
const localCompletionSource = (context) => {
|
|
853
|
+
const inner = language.syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
854
|
+
if (dontComplete.includes(inner.name))
|
|
855
|
+
return null;
|
|
856
|
+
const word = context.matchBefore(/[\w'\xa1-]+/);
|
|
857
|
+
if (!word && !context.explicit)
|
|
858
|
+
return null;
|
|
859
|
+
const from = word ? word.from : context.pos;
|
|
860
|
+
if (afterDot(context, from))
|
|
861
|
+
return null;
|
|
862
|
+
let options = [];
|
|
863
|
+
for (let pos = inner; pos; pos = pos.parent)
|
|
864
|
+
if (ScopeNodes.has(pos.name))
|
|
865
|
+
options = options.concat(getScope(context.state.doc, pos));
|
|
866
|
+
return { options, from, validFor: Identifier };
|
|
867
|
+
};
|
|
868
|
+
/// Completes a field name after `record.`, from the record fields declared
|
|
869
|
+
/// and written in the file.
|
|
870
|
+
const fieldCompletionSource = (context) => {
|
|
871
|
+
const word = context.matchBefore(/[\w'\xa1-]*/);
|
|
872
|
+
const from = word ? word.from : context.pos;
|
|
873
|
+
const before = context.state.sliceDoc(Math.max(0, from - 2), from);
|
|
874
|
+
if (before.length < 2 || before[1] != "." || !/[\w')\]}]/.test(before[0]))
|
|
875
|
+
return null;
|
|
876
|
+
const tree = language.syntaxTree(context.state);
|
|
877
|
+
if (dontComplete.includes(tree.resolveInner(context.pos, -1).name))
|
|
878
|
+
return null;
|
|
879
|
+
const seen = new Set();
|
|
880
|
+
const options = [];
|
|
881
|
+
tree.iterate({
|
|
882
|
+
enter(node) {
|
|
883
|
+
if (node.name != "PropertyName" || (node.from <= context.pos && node.to >= context.pos))
|
|
884
|
+
return;
|
|
885
|
+
const label = context.state.sliceDoc(node.from, node.to);
|
|
886
|
+
if (seen.has(label))
|
|
887
|
+
return;
|
|
888
|
+
seen.add(label);
|
|
889
|
+
options.push({ label, type: "property" });
|
|
890
|
+
},
|
|
891
|
+
});
|
|
892
|
+
return { options, from, validFor: Identifier };
|
|
893
|
+
};
|
|
894
|
+
/// Keywords, snippets, and the functions, types and constructors from Prelude
|
|
895
|
+
/// and the most common modules. It offers nothing in strings and comments, or
|
|
896
|
+
/// after a dot.
|
|
897
|
+
const purescriptCompletion = autocomplete.ifNotIn(dontComplete, (context) => {
|
|
898
|
+
const word = context.matchBefore(/[\w'\xa1-]+/);
|
|
899
|
+
if (word && afterDot(context, word.from))
|
|
900
|
+
return null;
|
|
901
|
+
if (!word && context.matchBefore(/\.$/))
|
|
902
|
+
return null;
|
|
903
|
+
return autocomplete.completeFromList(globals)(context);
|
|
904
|
+
});
|
|
905
|
+
|
|
906
|
+
// Folding a block keeps its first line in view, which is the line that says
|
|
907
|
+
// what was folded away.
|
|
908
|
+
function foldBody(node, state) {
|
|
909
|
+
const line = state.doc.lineAt(node.from);
|
|
910
|
+
return node.to > line.to ? { from: line.to, to: node.to } : null;
|
|
911
|
+
}
|
|
912
|
+
// The tree can't say where a new line belongs, because a block ends at its last
|
|
913
|
+
// token and the new line is past that. So the line above decides. If it opens a
|
|
914
|
+
// block or leaves an expression unfinished, the new line is indented one step
|
|
915
|
+
// further. Otherwise the new line keeps the same indentation.
|
|
916
|
+
const opensBlock = /(^|[^\w'])(do|ado|where|of|let)$/;
|
|
917
|
+
const continuesLine = /(=|->|<-|=>|\$|#|\||,|\(|\[|\{|`|::|\bif|\bthen|\belse|\bcase)$/;
|
|
918
|
+
const wantsIndent = /^\s*(where|then|else)\b/;
|
|
919
|
+
const indentPurescript = language.indentService.of((context, pos) => {
|
|
920
|
+
const inside = language.syntaxTree(context.state).resolveInner(pos, -1).name;
|
|
921
|
+
if (inside == "BlockComment" || inside == "DocComment")
|
|
922
|
+
return null;
|
|
923
|
+
let line = context.lineAt(pos, -1);
|
|
924
|
+
while (!/\S/.test(line.text) && line.from > 0)
|
|
925
|
+
line = context.lineAt(line.from - 1, -1);
|
|
926
|
+
if (!/\S/.test(line.text))
|
|
927
|
+
return 0;
|
|
928
|
+
const code = line.text.replace(/\s*--(\s.*|-*)$/, "").trimEnd();
|
|
929
|
+
const base = context.lineIndent(line.from);
|
|
930
|
+
if (opensBlock.test(code) || continuesLine.test(code))
|
|
931
|
+
return base + context.unit;
|
|
932
|
+
if (wantsIndent.test(context.state.doc.sliceString(pos, pos + 20)))
|
|
933
|
+
return base + context.unit;
|
|
934
|
+
return base;
|
|
935
|
+
});
|
|
936
|
+
const purescriptLanguage = language.LRLanguage.define({
|
|
937
|
+
name: "purescript",
|
|
938
|
+
parser: parser.configure({
|
|
939
|
+
props: [
|
|
940
|
+
language.foldNodeProp.add({
|
|
941
|
+
"WhereBlock DoExpression AdoExpression CaseExpression LetExpression LetStatement": foldBody,
|
|
942
|
+
"DataDeclaration ClassDeclaration InstanceDeclaration Bind ExportList": foldBody,
|
|
943
|
+
"Record RecordType BlockComment DocComment": foldBody,
|
|
944
|
+
}),
|
|
945
|
+
highlight.styleTags({
|
|
946
|
+
"module import": highlight.tags.moduleKeyword,
|
|
947
|
+
"data newtype type class instance derive foreign": highlight.tags.definitionKeyword,
|
|
948
|
+
"where let in of": highlight.tags.definitionKeyword,
|
|
949
|
+
"case if then else do ado": highlight.tags.controlKeyword,
|
|
950
|
+
"infix infixl infixr as hiding kind forall": highlight.tags.keyword,
|
|
951
|
+
Boolean: highlight.tags.bool,
|
|
952
|
+
Number: highlight.tags.number,
|
|
953
|
+
String: highlight.tags.string,
|
|
954
|
+
Char: highlight.tags.character,
|
|
955
|
+
Wildcard: highlight.tags.atom,
|
|
956
|
+
"Hole/Variable": highlight.tags.special(highlight.tags.variableName),
|
|
957
|
+
"?": highlight.tags.special(highlight.tags.variableName),
|
|
958
|
+
LineComment: highlight.tags.lineComment,
|
|
959
|
+
BlockComment: highlight.tags.blockComment,
|
|
960
|
+
DocComment: highlight.tags.docComment,
|
|
961
|
+
Qualifier: highlight.tags.namespace,
|
|
962
|
+
OperatorQualifier: highlight.tags.namespace,
|
|
963
|
+
ModuleName: highlight.tags.namespace,
|
|
964
|
+
"ModuleName/Qualifier": highlight.tags.namespace,
|
|
965
|
+
DeclName: highlight.tags.definition(highlight.tags.variableName),
|
|
966
|
+
"Bind/DeclName": highlight.tags.definition(highlight.tags.function(highlight.tags.variableName)),
|
|
967
|
+
PropertyName: highlight.tags.propertyName,
|
|
968
|
+
"FieldDeclaration/PropertyName": highlight.tags.definition(highlight.tags.propertyName),
|
|
969
|
+
"Callee/Variable": highlight.tags.function(highlight.tags.variableName),
|
|
970
|
+
Variable: highlight.tags.variableName,
|
|
971
|
+
Constructor: highlight.tags.className,
|
|
972
|
+
TypeConstructor: highlight.tags.typeName,
|
|
973
|
+
TypeVariable: highlight.tags.typeName,
|
|
974
|
+
"Operator ConstructorOperator BacktickOperator": highlight.tags.operator,
|
|
975
|
+
"TypeOperator TypeConstructorOperator": highlight.tags.typeOperator,
|
|
976
|
+
"= <-": highlight.tags.definitionOperator,
|
|
977
|
+
":: -> =>": highlight.tags.typeOperator,
|
|
978
|
+
'| @ \\ ":"': highlight.tags.operator,
|
|
979
|
+
fieldDot: highlight.tags.derefOperator,
|
|
980
|
+
"` ,": highlight.tags.separator,
|
|
981
|
+
"( )": highlight.tags.paren,
|
|
982
|
+
"[ ]": highlight.tags.squareBracket,
|
|
983
|
+
"{ }": highlight.tags.brace,
|
|
984
|
+
}),
|
|
985
|
+
],
|
|
986
|
+
}),
|
|
987
|
+
languageData: {
|
|
988
|
+
commentTokens: { line: "--", block: { open: "{-", close: "-}" } },
|
|
989
|
+
closeBrackets: { brackets: ["(", "[", "{", '"'] },
|
|
990
|
+
indentOnInput: /^\s*(where|in|then|else|of)$/,
|
|
991
|
+
},
|
|
992
|
+
});
|
|
993
|
+
/// PureScript language support, with completion for keywords, snippets,
|
|
994
|
+
/// common library names, record fields and the names declared in the file.
|
|
995
|
+
function purescript() {
|
|
996
|
+
return new language.LanguageSupport(purescriptLanguage, [
|
|
997
|
+
indentPurescript,
|
|
998
|
+
purescriptLanguage.data.of({ autocomplete: purescriptCompletion }),
|
|
999
|
+
purescriptLanguage.data.of({ autocomplete: localCompletionSource }),
|
|
1000
|
+
purescriptLanguage.data.of({ autocomplete: fieldCompletionSource }),
|
|
1001
|
+
]);
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
exports.fieldCompletionSource = fieldCompletionSource;
|
|
1005
|
+
exports.localCompletionSource = localCompletionSource;
|
|
1006
|
+
exports.parser = parser;
|
|
1007
|
+
exports.purescript = purescript;
|
|
1008
|
+
exports.purescriptCompletion = purescriptCompletion;
|
|
1009
|
+
exports.purescriptLanguage = purescriptLanguage;
|
|
1010
|
+
exports.snippets = snippets;
|