@exercism/codemirror-lang-unison 0.0.0-stage → 1.0.1

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/dist/index.cjs ADDED
@@ -0,0 +1,1069 @@
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
+ Doc = 3,
13
+ Fold = 4,
14
+ DocLiteral = 5,
15
+ blockOpen = 114,
16
+ blockEnd = 115,
17
+ blockSep = 116,
18
+ DeclName = 6,
19
+ upperName = 117,
20
+ pipe = 7,
21
+ symbols = 124,
22
+ closeParen = 19,
23
+ openParen = 20,
24
+ comma = 26,
25
+ closeBracket = 27,
26
+ openBracket = 28,
27
+ closeBrace = 30,
28
+ openBrace = 31,
29
+ _with = 75,
30
+ then = 78,
31
+ _else = 79;
32
+
33
+ // The external tokenizers and the layout tracker for the Unison grammar. The
34
+ // layout approach follows the PureScript and Haskell grammars, which are
35
+ // adapted from https://codeberg.org/reeven/codemirror-lang-haskell (MIT, by
36
+ // CodinCod).
37
+ // How far back a line is read to find its indentation. A line indented
38
+ // further than this is read as a continuation, which is the harmless answer.
39
+ const maxIndentation = 400;
40
+ function isSpace(ch) {
41
+ return (ch == 32 /* Ch.Space */ ||
42
+ ch == 9 /* Ch.Tab */ ||
43
+ ch == 10 /* Ch.Newline */ ||
44
+ ch == 13 /* Ch.Return */ ||
45
+ ch == 12 /* Ch.FormFeed */ ||
46
+ ch == 11 /* Ch.VerticalTab */);
47
+ }
48
+ function isInlineSpace(ch) {
49
+ return ch == 32 /* Ch.Space */ || ch == 9 /* Ch.Tab */;
50
+ }
51
+ function isDigit(ch) {
52
+ return ch >= 48 /* Ch.Zero */ && ch <= 57 /* Ch.Nine */;
53
+ }
54
+ function isUpper(ch) {
55
+ return ch >= 65 /* Ch.UpperA */ && ch <= 90 /* Ch.UpperZ */;
56
+ }
57
+ function isLower(ch) {
58
+ return (ch >= 97 /* Ch.LowerA */ && ch <= 122 /* Ch.LowerZ */) || ch == 95 /* Ch.Underscore */ || ch >= 161 /* Ch.Latin1 */;
59
+ }
60
+ function isIdentifierStart(ch) {
61
+ return isLower(ch) || isUpper(ch);
62
+ }
63
+ // Unison names may end in `'` or `!`, as in `go'` and `toOptional!`.
64
+ function isIdentifierChar(ch) {
65
+ return isIdentifierStart(ch) || isDigit(ch) || ch == 39 /* Ch.Apostrophe */ || ch == 33 /* Ch.Bang */;
66
+ }
67
+ function isSymbol(ch) {
68
+ switch (ch) {
69
+ case 33 /* Ch.Bang */:
70
+ case 36 /* Ch.Dollar */:
71
+ case 37 /* Ch.Percent */:
72
+ case 94 /* Ch.Caret */:
73
+ case 38 /* Ch.Ampersand */:
74
+ case 42 /* Ch.Star */:
75
+ case 45 /* Ch.Minus */:
76
+ case 61 /* Ch.Equals */:
77
+ case 43 /* Ch.Plus */:
78
+ case 60 /* Ch.Less */:
79
+ case 62 /* Ch.Greater */:
80
+ case 126 /* Ch.Tilde */:
81
+ case 92 /* Ch.Backslash */:
82
+ case 47 /* Ch.Slash */:
83
+ case 124 /* Ch.Pipe */:
84
+ case 58 /* Ch.Colon */:
85
+ return true;
86
+ default:
87
+ return false;
88
+ }
89
+ }
90
+ // The word that starts `offset` characters ahead, or "" if no word starts there.
91
+ function wordAt(input, offset) {
92
+ let word = "";
93
+ for (let pos = offset; isIdentifierChar(input.peek(pos)); pos++) {
94
+ word += String.fromCharCode(input.peek(pos));
95
+ }
96
+ return word;
97
+ }
98
+ // A line comment is two or more dashes with no other symbol after them, so
99
+ // `-->` stays an operator.
100
+ function startsLineComment(input, offset = 0) {
101
+ if (input.peek(offset) != 45 /* Ch.Minus */ || input.peek(offset + 1) != 45 /* Ch.Minus */)
102
+ return false;
103
+ let pos = offset + 2;
104
+ while (input.peek(pos) == 45 /* Ch.Minus */)
105
+ pos++;
106
+ return !isSymbol(input.peek(pos));
107
+ }
108
+ // True if a comment or a doc starts `offset` characters ahead.
109
+ function startsComment(input, offset = 0) {
110
+ const next = input.peek(offset);
111
+ if (next == 123 /* Ch.BraceL */) {
112
+ const after = input.peek(offset + 1);
113
+ return after == 45 /* Ch.Minus */ || after == 123 /* Ch.BraceL */;
114
+ }
115
+ return startsLineComment(input, offset);
116
+ }
117
+ // ── Comments ──────────────────────────────────────────────────────────────────
118
+ // The position after the nested comment or doc that starts here, where `open`
119
+ // and `close` are the second character of its opening and closing marks.
120
+ function nestedEnd(input, open, close) {
121
+ let depth = 0;
122
+ for (let pos = 0;; pos++) {
123
+ const ch = input.peek(pos);
124
+ if (ch == -1 /* Ch.EOF */)
125
+ return pos;
126
+ if (ch == 123 /* Ch.BraceL */ && input.peek(pos + 1) == open) {
127
+ depth++;
128
+ pos++;
129
+ }
130
+ else if (ch == close && input.peek(pos + 1) == 125 /* Ch.BraceR */) {
131
+ depth--;
132
+ pos++;
133
+ if (!depth)
134
+ return pos + 1;
135
+ }
136
+ }
137
+ }
138
+ /// Line comments start with `--`, and block comments `{- -}` nest. A doc,
139
+ /// `{{ ... }}`, is read as one token, and is a `DocLiteral` where the parser
140
+ /// can take a value. A line that starts with `---` folds the
141
+ /// rest of the file away, so everything after it is one `Fold` token.
142
+ const comments = new lr.ExternalTokenizer((input, stack) => {
143
+ const next = input.next;
144
+ if (next == 45 /* Ch.Minus */) {
145
+ if (!startsLineComment(input))
146
+ return;
147
+ const before = input.peek(-1);
148
+ const lineStart = before == -1 /* Ch.EOF */ || before == 10 /* Ch.Newline */ || before == 13 /* Ch.Return */;
149
+ if (lineStart && input.peek(2) == 45 /* Ch.Minus */) {
150
+ let pos = 3;
151
+ while (input.peek(pos) != -1 /* Ch.EOF */)
152
+ pos++;
153
+ input.acceptToken(Fold, pos);
154
+ return;
155
+ }
156
+ let pos = 2;
157
+ while (input.peek(pos) != 10 /* Ch.Newline */ && input.peek(pos) != -1 /* Ch.EOF */)
158
+ pos++;
159
+ input.acceptToken(LineComment, pos);
160
+ return;
161
+ }
162
+ if (next != 123 /* Ch.BraceL */)
163
+ return;
164
+ const after = input.peek(1);
165
+ if (after == 45 /* Ch.Minus */)
166
+ input.acceptToken(BlockComment, nestedEnd(input, 45 /* Ch.Minus */, 45 /* Ch.Minus */));
167
+ else if (after == 123 /* Ch.BraceL */) {
168
+ // Where a block may open, the layout tokenizer opens it first, so the doc
169
+ // can be the block's value. A doc that starts its line documents what
170
+ // follows.
171
+ if (stack.canShift(blockOpen))
172
+ return;
173
+ const value = stack.canShift(DocLiteral) && !lineInfo(input).firstOnLine;
174
+ input.acceptToken(value ? DocLiteral : Doc, nestedEnd(input, 123 /* Ch.BraceL */, 125 /* Ch.BraceR */));
175
+ }
176
+ });
177
+ // ── Layout ────────────────────────────────────────────────────────────────────
178
+ /// One open block. Its items line up on `column`. A line that starts at
179
+ /// `base` or further left ends the block, where `base` is the indentation of
180
+ /// the line that opened the block. `depth` counts the brackets opened inside
181
+ /// the block and not yet closed, because indentation means nothing inside
182
+ /// them.
183
+ class Layout {
184
+ constructor(parent, column, base, depth) {
185
+ this.parent = parent;
186
+ this.column = column;
187
+ this.base = base;
188
+ this.depth = depth;
189
+ this.hash = ((parent ? parent.hash * 31 : 0) + column * 7 + base * 3 + depth) | 0;
190
+ }
191
+ withDepth(depth) {
192
+ return new Layout(this.parent, this.column, this.base, depth);
193
+ }
194
+ }
195
+ // Nothing is open yet. The file's own block opens at its first token.
196
+ const noLayout = new Layout(null, -1, -2, 0);
197
+ // The column a position stands in, whether only whitespace stands in front of
198
+ // it on its line, and the indentation of that line. Tabs advance to the next
199
+ // multiple of eight.
200
+ function lineInfo(input, offset = 0) {
201
+ const before = [];
202
+ for (let pos = offset - 1; pos > offset - maxIndentation; pos--) {
203
+ const ch = input.peek(pos);
204
+ if (ch == -1 /* Ch.EOF */ || ch == 10 /* Ch.Newline */ || ch == 13 /* Ch.Return */)
205
+ break;
206
+ before.push(ch);
207
+ }
208
+ let column = 0, indent = -1, firstOnLine = true;
209
+ for (let pos = before.length - 1; pos >= 0; pos--) {
210
+ const ch = before[pos];
211
+ if (!isSpace(ch) && indent < 0)
212
+ indent = column;
213
+ if (ch == 9 /* Ch.Tab */)
214
+ column += 8 - (column % 8);
215
+ else
216
+ column++;
217
+ if (!isSpace(ch))
218
+ firstOnLine = false;
219
+ }
220
+ return { column, firstOnLine, indent: indent < 0 ? column : indent, lineStart: -before.length };
221
+ }
222
+ // The nearest line above `offset` that holds code, as its indentation and its
223
+ // text. Blank lines and lines that hold only a comment don't count.
224
+ function previousCodeLine(input, offset) {
225
+ let pos = offset - 1;
226
+ for (let lines = 0; lines < 200; lines++) {
227
+ while (input.peek(pos) != 10 /* Ch.Newline */ && input.peek(pos) != -1 /* Ch.EOF */)
228
+ pos--;
229
+ if (input.peek(pos) == -1 /* Ch.EOF */)
230
+ return null;
231
+ // `pos` is at the newline that ends the line above.
232
+ let start = pos - 1;
233
+ while (input.peek(start) != 10 /* Ch.Newline */ && input.peek(start) != -1 /* Ch.EOF */)
234
+ start--;
235
+ let first = start + 1;
236
+ let indent = 0;
237
+ for (;;) {
238
+ const ch = input.peek(first);
239
+ if (ch == 32 /* Ch.Space */)
240
+ indent++;
241
+ else if (ch == 9 /* Ch.Tab */)
242
+ indent += 8 - (indent % 8);
243
+ else
244
+ break;
245
+ first++;
246
+ }
247
+ const ch = input.peek(first);
248
+ const blank = first >= pos || ch == 13 /* Ch.Return */;
249
+ if (!blank && !startsLineComment(input, first)) {
250
+ let text = "";
251
+ for (let p = first; p < pos && p < first + maxIndentation; p++)
252
+ text += String.fromCharCode(input.peek(p));
253
+ return { indent, text };
254
+ }
255
+ pos = start;
256
+ }
257
+ return null;
258
+ }
259
+ // The blocks after `then`, `else` and the `with` of a `match` may start at
260
+ // the column of the block around them, as in an `if` whose branches line up
261
+ // with it. A `then` block ends at its `else`.
262
+ const endsWithLooseOpener = /(^|[^\w'!])(then|else|with)\s*(--(\s.*|-*))?$/;
263
+ // The block that opens at the current position. If it opens on the line of
264
+ // the word that opens it, a line ends it by starting no further right than
265
+ // that line. If the block starts on a new line, a line ends it by starting no
266
+ // further right than the block around it.
267
+ function openLayout(context, input) {
268
+ const line = lineInfo(input);
269
+ if (!line.firstOnLine)
270
+ return new Layout(context, line.column, line.indent, 0);
271
+ const above = previousCodeLine(input, line.lineStart);
272
+ let base = above ? Math.min(context.column, above.indent) : -1;
273
+ if (above && endsWithLooseOpener.test(above.text))
274
+ base = Math.min(base, line.column - 1);
275
+ return new Layout(context, line.column, base, 0);
276
+ }
277
+ // These tokens often stand right after a block, so the tokenizer asks the
278
+ // parser whether it can take them. If it can't, the block ends there. That is
279
+ // what ends the block in `if a then b else c` on one line.
280
+ function closesBlock(input, stack) {
281
+ switch (input.next) {
282
+ case 41 /* Ch.ParenR */:
283
+ return !stack.canShift(closeParen);
284
+ case 93 /* Ch.BracketR */:
285
+ return !stack.canShift(closeBracket);
286
+ case 125 /* Ch.BraceR */:
287
+ return !stack.canShift(closeBrace);
288
+ case 44 /* Ch.Comma */:
289
+ return !stack.canShift(comma);
290
+ case 124 /* Ch.Pipe */:
291
+ return !isSymbol(input.peek(1)) && !stack.canShift(pipe);
292
+ }
293
+ if (!isIdentifierStart(input.next))
294
+ return false;
295
+ switch (wordAt(input, 0)) {
296
+ case "then":
297
+ return !stack.canShift(then);
298
+ case "else":
299
+ return !stack.canShift(_else);
300
+ case "with":
301
+ return !stack.canShift(_with);
302
+ default:
303
+ return false;
304
+ }
305
+ }
306
+ // True if the next token is `then`, `else` or `with` and the parser can take
307
+ // it. Then it continues the `if`, `match` or `handle` that is still open, and
308
+ // the line is no new item.
309
+ function continuesKeyword(input, stack) {
310
+ if (!isLower(input.next))
311
+ return false;
312
+ switch (wordAt(input, 0)) {
313
+ case "then":
314
+ return stack.canShift(then);
315
+ case "else":
316
+ return stack.canShift(_else);
317
+ case "with":
318
+ return stack.canShift(_with);
319
+ default:
320
+ return false;
321
+ }
322
+ }
323
+ // True if the line starts with an infix operator, as in a pipeline written
324
+ // one step per line. No statement starts with one. `!` forces a value, and
325
+ // `-1` is a number, so neither counts.
326
+ function startsWithOperator(input, stack) {
327
+ if (!isSymbol(input.next))
328
+ return false;
329
+ let end = 0;
330
+ while (isSymbol(input.peek(end)))
331
+ end++;
332
+ if (end == 1 && (input.next == 33 /* Ch.Bang */ || input.next == 124 /* Ch.Pipe */ || input.next == 61 /* Ch.Equals */))
333
+ return false;
334
+ if ((input.next == 45 /* Ch.Minus */ || input.next == 43 /* Ch.Plus */) && end == 1 && isDigit(input.peek(1)))
335
+ return false;
336
+ return stack.canShift(symbols);
337
+ }
338
+ /// The braces and semicolons that Unison leaves out. A block opens at its
339
+ /// first token. An item starts wherever a line begins at exactly the block's
340
+ /// column. The block ends at the first line that starts no further right than
341
+ /// the line that opened it, where the parser would fail, or at the end of the
342
+ /// file.
343
+ const layout = new lr.ExternalTokenizer((input, stack) => {
344
+ const cx = stack.context;
345
+ const open = cx.parent != null;
346
+ if (input.next == -1 /* Ch.EOF */) {
347
+ if (stack.canShift(blockOpen))
348
+ input.acceptToken(blockOpen);
349
+ else if (open && stack.canShift(blockEnd))
350
+ input.acceptToken(blockEnd);
351
+ return;
352
+ }
353
+ // The grammar skips whitespace and comments, so layout is decided in front
354
+ // of the tokens that are left. A doc may be a value, so a block may open
355
+ // in front of one.
356
+ if (isSpace(input.next))
357
+ return;
358
+ const doc = input.next == 123 /* Ch.BraceL */ && input.peek(1) == 123 /* Ch.BraceL */;
359
+ if (startsComment(input) && !doc)
360
+ return;
361
+ if (stack.canShift(blockOpen)) {
362
+ input.acceptToken(blockOpen);
363
+ return;
364
+ }
365
+ if (!open || cx.depth > 0 || doc)
366
+ return;
367
+ // A block whose first token stands no further right than the line that
368
+ // opened it is empty.
369
+ if (cx.column <= cx.base && stack.canShift(blockEnd)) {
370
+ input.acceptToken(blockEnd);
371
+ return;
372
+ }
373
+ if (continuesKeyword(input, stack))
374
+ return;
375
+ if (closesBlock(input, stack) && stack.canShift(blockEnd)) {
376
+ input.acceptToken(blockEnd);
377
+ return;
378
+ }
379
+ const { column, firstOnLine } = lineInfo(input);
380
+ if (!firstOnLine)
381
+ return;
382
+ if (column <= cx.base && stack.canShift(blockEnd)) {
383
+ input.acceptToken(blockEnd);
384
+ return;
385
+ }
386
+ if (column != cx.column)
387
+ return;
388
+ // At the top level, `> expr` is a watch, so an operator there starts an
389
+ // item.
390
+ if (cx.parent != noLayout && startsWithOperator(input, stack))
391
+ return;
392
+ if (stack.canShift(blockSep))
393
+ input.acceptToken(blockSep);
394
+ }, { contextual: true });
395
+ /// The stack of open blocks, and the brackets open inside each one.
396
+ const trackLayout = new lr.ContextTracker({
397
+ start: noLayout,
398
+ shift(context, term, stack, input) {
399
+ var _a;
400
+ switch (term) {
401
+ case blockOpen:
402
+ return openLayout(context, input);
403
+ case blockEnd:
404
+ return (_a = context.parent) !== null && _a !== void 0 ? _a : context;
405
+ case openParen:
406
+ case openBracket:
407
+ case openBrace:
408
+ return context.withDepth(context.depth + 1);
409
+ case closeParen:
410
+ case closeBracket:
411
+ case closeBrace:
412
+ return context.depth > 0 ? context.withDepth(context.depth - 1) : context;
413
+ default:
414
+ return context;
415
+ }
416
+ },
417
+ hash: (context) => context.hash,
418
+ });
419
+ // ── Names ─────────────────────────────────────────────────────────────────────
420
+ /// `|` gets its own term, so the layout tokenizer can ask whether the parser
421
+ /// can take one.
422
+ /// A name gets the `upperName` term if its last segment starts with a capital
423
+ /// letter.
424
+ const specializeName = (value) => {
425
+ const last = value.lastIndexOf(".") + 1;
426
+ const ch = value.charCodeAt(last);
427
+ return ch >= 65 /* Ch.UpperA */ && ch <= 90 /* Ch.UpperZ */ ? upperName : -1;
428
+ };
429
+ const specializeSymbols = (value) => (value == "|" ? pipe : -1);
430
+ const reserved = new Set([
431
+ "ability",
432
+ "cases",
433
+ "do",
434
+ "else",
435
+ "false",
436
+ "forall",
437
+ "handle",
438
+ "if",
439
+ "let",
440
+ "match",
441
+ "namespace",
442
+ "structural",
443
+ "then",
444
+ "true",
445
+ "type",
446
+ "unique",
447
+ "use",
448
+ "where",
449
+ "with",
450
+ ]);
451
+ // The position after the qualified name that starts at `pos`, such as
452
+ // `List.map`.
453
+ function nameEnd(input, pos) {
454
+ for (;;) {
455
+ while (isIdentifierChar(input.peek(pos)))
456
+ pos++;
457
+ if (input.peek(pos) == 46 /* Ch.Dot */ && isIdentifierStart(input.peek(pos + 1)))
458
+ pos++;
459
+ else
460
+ return pos;
461
+ }
462
+ }
463
+ // The position after the text that starts at `pos`, or -1 if it doesn't close
464
+ // on its line.
465
+ function textEnd(input, pos) {
466
+ for (pos++;; pos++) {
467
+ const ch = input.peek(pos);
468
+ if (ch == -1 /* Ch.EOF */ || ch == 10 /* Ch.Newline */)
469
+ return -1;
470
+ if (ch == 92 /* Ch.Backslash */)
471
+ pos++;
472
+ else if (ch == 34 /* Ch.Quote */)
473
+ return pos + 1;
474
+ }
475
+ }
476
+ // The position after the bracketed group that starts at `pos`, or -1 if it
477
+ // doesn't close.
478
+ function groupEnd(input, pos) {
479
+ let depth = 0;
480
+ for (let steps = 0; steps < 2000; steps++, pos++) {
481
+ const ch = input.peek(pos);
482
+ if (ch == -1 /* Ch.EOF */)
483
+ return -1;
484
+ if (ch == 40 /* Ch.ParenL */ || ch == 91 /* Ch.BracketL */ || ch == 123 /* Ch.BraceL */)
485
+ depth++;
486
+ else if (ch == 41 /* Ch.ParenR */ || ch == 93 /* Ch.BracketR */ || ch == 125 /* Ch.BraceR */) {
487
+ depth--;
488
+ if (!depth)
489
+ return pos + 1;
490
+ }
491
+ else if (ch == 34 /* Ch.Quote */) {
492
+ pos = textEnd(input, pos) - 1;
493
+ if (pos < 0)
494
+ return -1;
495
+ }
496
+ else if (ch == 63 /* Ch.Question */)
497
+ pos += input.peek(pos + 1) == 92 /* Ch.Backslash */ ? 2 : 1;
498
+ }
499
+ return -1;
500
+ }
501
+ /// The name a definition defines. `f x = x` defines `f`, and `f : Nat -> Nat`
502
+ /// declares its type, but `f x` on its own calls `f`. The tokenizer reads
503
+ /// ahead on the line, over the patterns that may stand between the name and
504
+ /// the `=`, to decide.
505
+ const declNames = new lr.ExternalTokenizer((input, stack) => {
506
+ if (!isIdentifierStart(input.next) || !stack.canShift(DeclName))
507
+ return;
508
+ const end = nameEnd(input, 0);
509
+ // The last segment of a value's name starts with a lowercase letter.
510
+ let last = end - 1;
511
+ while (last > 0 && input.peek(last - 1) != 46 /* Ch.Dot */)
512
+ last--;
513
+ if (!isLower(input.peek(last)))
514
+ return;
515
+ const name = wordAt(input, 0);
516
+ if (end == name.length && (reserved.has(name) || name == "_"))
517
+ return;
518
+ let pos = end, params = 0;
519
+ for (;;) {
520
+ while (isInlineSpace(input.peek(pos)))
521
+ pos++;
522
+ const ch = input.peek(pos);
523
+ if (isSymbol(ch)) {
524
+ if (isSymbol(input.peek(pos + 1)))
525
+ return;
526
+ if (ch == 61 /* Ch.Equals */ || (ch == 58 /* Ch.Colon */ && !params))
527
+ input.acceptToken(DeclName, end);
528
+ return;
529
+ }
530
+ if (isIdentifierStart(ch)) {
531
+ const word = wordAt(input, pos);
532
+ if (reserved.has(word))
533
+ return;
534
+ pos = nameEnd(input, pos);
535
+ }
536
+ else if (isDigit(ch)) {
537
+ while (isIdentifierChar(input.peek(pos)) || input.peek(pos) == 46 /* Ch.Dot */)
538
+ pos++;
539
+ }
540
+ else if (ch == 34 /* Ch.Quote */) {
541
+ pos = textEnd(input, pos);
542
+ if (pos < 0)
543
+ return;
544
+ }
545
+ else if (ch == 40 /* Ch.ParenL */ || ch == 91 /* Ch.BracketL */ || ch == 123 /* Ch.BraceL */) {
546
+ pos = groupEnd(input, pos);
547
+ if (pos < 0)
548
+ return;
549
+ }
550
+ else if (ch == 63 /* Ch.Question */) {
551
+ pos += input.peek(pos + 1) == 92 /* Ch.Backslash */ ? 3 : 2;
552
+ }
553
+ else if (ch == 64 /* Ch.At */) {
554
+ pos++;
555
+ continue;
556
+ }
557
+ else {
558
+ return;
559
+ }
560
+ params++;
561
+ }
562
+ });
563
+
564
+ // This file was generated by lezer-generator. You probably shouldn't edit it.
565
+ const spec_lowerName = {__proto__:null,structural:20, unique:22, type:24, forall:48, ability:76, where:78, namespace:90, use:98, _:266, true:106, false:108, do:130, let:134, cases:138, match:148, with:150, if:154, then:156, else:158, handle:164};
566
+ const spec_symbols = {__proto__:null,"=":30, "->":46, ":":72, "!":180, ">":185};
567
+ const parser = lr.LRParser.deserialize({
568
+ version: 14,
569
+ states: "DSOcQZOOO#hQ_O'#ExQOQXOOO#oQXO'#DiOOQR'#D['#D[OOQR'#D]'#D]OOQR'#Da'#DaO&^QZO'#DkOOQP'#F]'#F]O'pQZO'#F]OOQR'#F^'#F^O)SQXO'#DjOOQR'#F['#F[OOQR'#FZ'#FZO*dQZO'#FYOOQR'#FY'#FYO+XQXO'#EUO,dQXO'#EVO)SQXO'#EWOOQR'#FU'#FUO,kQ]O'#E]OOQR'#Ey'#EyOOQP,5;d,5;dO,uQZO,5;dOOQP'#Ez'#EzO,}QXO'#CeO-SQXO'#CeO,}QXO'#DRO-[QXO'#DYO-uQZO'#D^OOQR'#Db'#DbO.PQZO'#DnO.PQZO'#DpO.UQZO'#DrO+[QXO'#DwO+[QXO'#DzO+[QXO'#EPO.ZQXO'#D`O.eQXO'#D`O+[QXO'#EZO.jQXO'#DUO+cQXO'#EXOOQR'#DW'#DWOOQR'#FR'#FRO.oQXO,59qO.tQZO'#FZO/lQXO'#FXOOQR'#FX'#FXOOQP'#FW'#FWO#oQXO'#DiOOQR,5:T,5:TO/wQXO,5:TO+cQXO,5:WO0PQZO'#FTOOQR,5:U,5:UO1cQZO,5:UOOQR'#FT'#FTOOQR'#Eg'#EgO+[QXO,5:jO2cQXO,5:jOOQR,5:p,5:pO2kQXO,5:pO2sQXO'#FbOOQP'#Fb'#FbOOQR,5:q,5:qO3XQXO,5:qOOQR,5:r,5:rO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V#a#|$d$w%a[!`a!w#g$z%O%QR$f#d!XZPR`adrstw!R![!h!t!w#V#_#a#d#g#|$a$d$w$z%O%Q%ax]PR`drstw!R![!h!t#V#_#a#|$a$d$w%aQ!WZQ!dbR#Z!XQ!uoQ!vpQ$O!}Q$X#SQ%U#{Q%W#}Q%|%PQ&g%yQ&i&QR&v&hQ#v!tR%s$wQ!xqR%T#zQ!caS#w!w%QQ$h#gQ%v$zR%{%O",
572
+ nodeNames: "⚠ LineComment BlockComment Doc Fold DocLiteral DeclName | Program TypeDeclaration structural unique type TypeName TypeVariable = ConstructorDeclaration DeclConstructor ' ) ( ParenType Type -> forall . , ] [ ListType } { AbilityList RecordType FieldDeclaration FieldName : AbilityDeclaration ability where Signature DeclOperator Operator QualifiedOperator Namespace namespace Variable Constructor Use use Binding Wildcard Boolean true false Number Text Char Hash ParenExpression ApplyExpression Callee AsPattern @ DoExpression do LetExpression let CasesExpression cases MatchCase OperatorExpression Guard MatchExpression match with IfExpression if then else OperatorExpression HandleExpression handle Lambda Annotation ParenOperator ListExpression EffectPattern Delay Force ! Watch > TestWatch test>",
573
+ maxTerm: 144,
574
+ context: trackLayout,
575
+ nodeProps: [
576
+ ["openedBy", 19,"(",27,"[",30,"{"],
577
+ ["closedBy", 20,")",28,"]",31,"}"],
578
+ ["isolate", 56,""]
579
+ ],
580
+ skippedNodes: [0,1,2,3,4],
581
+ repeatNodeCount: 18,
582
+ tokenData: "8y~R}XY$OYZ$OZ[$O[]$O]^$Opq$Oqr$grs%nst)dtu$guv$gvw$gwx*[xy*ayz*fz{$g{|*k|}/j}!O*k!O!P/o!P!Q$g!Q!R+x!R![-v![!]$g!^!_$g!_!`$g!`!a$g!a!b3q!b!c4r!c!}0W!}#O4w#O#P$g#P#Q4|#Q#R$g#R#S0W#T#h0W#h#i5R#i#o0W#o#p8o#p#q$g#q#r8t#r#s$g$g;'S0W;'S;=`3k<%lO0W~$TU#k~XY$OYZ$OZ[$O[]$O]^$Opq$O~$l`#p~qr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ofqr2dtu2duv2dvw2dz{2d{|2d}!O2d!P!Q2d![!]2d!^!_2d!_!`2d!`!a2d!c!}0W#O#P2d#Q#R2d#R#S0W#T#o0W#p#q2d#r#s2d$g;'S0W;'S;=`3k<%lO0W~2i`{~qr2dtu2duv2dvw2dz{2d{|2d}!O2d!P!Q2d![!]2d!^!_2d!_!`2d!`!a2d#O#P2d#Q#R2d#p#q2d#r#s2d~3nP;=`<%l0W~3tUOY4WZ#O4W#O#P4]#P;'S4W;'S;=`4l<%lO4W~4]O!Z~~4`SOY4WZ;'S4W;'S;=`4l<%lO4W~4oP;=`<%l4W~4wO!a~~4|Ol~~5ROk~~5W[#o~qr0Wwx0W!O!P0{!Q![0W!c!}0W#R#S0W#T#X0W#X#Y5|#Y#o0W$g;'S0W;'S;=`3k<%lO0W~6R[#o~qr0Wwx0W!O!P0{!Q![0W!c!}0W#R#S0W#T#g0W#g#h6w#h#o0W$g;'S0W;'S;=`3k<%lO0W~6|[#o~qr0Wwx0W!O!P0{!Q![0W!c!}0W#R#S0W#T#h0W#h#i7r#i#o0W$g;'S0W;'S;=`3k<%lO0W~7wZ#o~qr0Wwx0W!O!P0{!Q![0W!`!a8j!c!}0W#R#S0W#T#o0W$g;'S0W;'S;=`3k<%lO0W~8oO#Q~~8tOo~~8yOn~",
583
+ tokenizers: [comments, layout, declNames, 0],
584
+ topRules: {"Program":[0,8]},
585
+ specialized: [{term: 123, get: (value, stack) => (specializeName(value) << 1), external: specializeName},{term: 124, get: (value, stack) => (specializeSymbols(value) << 1), external: specializeSymbols},{term: 123, get: (value) => spec_lowerName[value] || -1},{term: 124, get: (value) => spec_symbols[value] || -1}],
586
+ tokenPrec: 1625
587
+ });
588
+
589
+ /// Snippets for the constructs people write most often in Unison.
590
+ const snippets = [
591
+ autocomplete.snippetCompletion("${name} : ${Type}\n${name} ${args} =\n ${}", {
592
+ label: "fun",
593
+ detail: "function with signature",
594
+ type: "keyword",
595
+ }),
596
+ autocomplete.snippetCompletion("cases\n ${pattern} -> ${}", {
597
+ label: "cases",
598
+ detail: "function by cases",
599
+ type: "keyword",
600
+ }),
601
+ autocomplete.snippetCompletion("match ${expression} with\n ${pattern} -> ${}", {
602
+ label: "match",
603
+ detail: "with",
604
+ type: "keyword",
605
+ }),
606
+ autocomplete.snippetCompletion("${pattern} | ${condition} -> ${}\n | otherwise -> ${}", {
607
+ label: "guard",
608
+ detail: "case with guards",
609
+ type: "keyword",
610
+ }),
611
+ autocomplete.snippetCompletion("if ${condition} then ${} else ${}", {
612
+ label: "if",
613
+ detail: "then else",
614
+ type: "keyword",
615
+ }),
616
+ autocomplete.snippetCompletion("do\n ${}", {
617
+ label: "do",
618
+ detail: "delayed block",
619
+ type: "keyword",
620
+ }),
621
+ autocomplete.snippetCompletion("let\n ${name} = ${value}\n ${}", {
622
+ label: "let",
623
+ detail: "block",
624
+ type: "keyword",
625
+ }),
626
+ autocomplete.snippetCompletion("(${x} -> ${})", {
627
+ label: "->",
628
+ detail: "lambda",
629
+ type: "keyword",
630
+ }),
631
+ autocomplete.snippetCompletion("List.foldLeft (${acc} ${x} -> ${}) ${initial} ${xs}", {
632
+ label: "foldLeft",
633
+ detail: "fold with a lambda",
634
+ type: "keyword",
635
+ }),
636
+ autocomplete.snippetCompletion("type ${Name} = ${Constructor}", {
637
+ label: "type",
638
+ detail: "definition",
639
+ type: "keyword",
640
+ }),
641
+ autocomplete.snippetCompletion("type ${Name} = { ${field} : ${Type} }", {
642
+ label: "record",
643
+ detail: "type definition",
644
+ type: "keyword",
645
+ }),
646
+ autocomplete.snippetCompletion("ability ${Name} where\n ${operation} : ${Type}", {
647
+ label: "ability",
648
+ detail: "definition",
649
+ type: "keyword",
650
+ }),
651
+ autocomplete.snippetCompletion("handle ${computation} with cases\n { ${result} } -> ${}\n { ${operation} -> ${resume} } -> ${}", {
652
+ label: "handle",
653
+ detail: "with a handler",
654
+ type: "keyword",
655
+ }),
656
+ autocomplete.snippetCompletion("use ${List}", {
657
+ label: "use",
658
+ detail: "namespace",
659
+ type: "keyword",
660
+ }),
661
+ autocomplete.snippetCompletion("test> ${name}.tests.ex1 = check (${})", {
662
+ label: "test>",
663
+ detail: "test watch",
664
+ type: "keyword",
665
+ }),
666
+ ];
667
+ const keywords = ("use type ability structural unique where match with cases if then else do let handle forall namespace")
668
+ .split(" ")
669
+ .map((label) => ({ label, type: "keyword" }));
670
+ const constants = ["true", "false"].map((label) => ({ label, type: "constant" }));
671
+ // Names that base exports under a short suffix, so they can be written
672
+ // without their namespace, such as `printLine` for `base.io.console.printLine`.
673
+ const functions = [
674
+ "printLine", "bug", "todo", "abort", "throw", "raise", "check", "ensure",
675
+ "ensureEqual", "verify", "labeled", "id", "const", "not", "otherwise", "at1",
676
+ "at2", "at3", "Universal.compare", "Universal.ordering", "toText",
677
+ "toCharList", "fromCharList", "isDigit", "isLetter", "isUpper", "isLower",
678
+ "isWhitespace", "increment", "decrement", "splitmix", "Random.natIn",
679
+ "Random.nat", "catch", "toEither", "toOptional!", "toBag",
680
+ ];
681
+ const types = [
682
+ "Nat", "Int", "Float", "Boolean", "Text", "Char", "Bytes", "List", "Optional",
683
+ "Either", "Map", "Set", "Bag", "Tuple", "Unit", "Request", "IO", "Exception",
684
+ "Abort", "Throw", "Store", "Random", "Each", "Ask", "Failure",
685
+ ].map((label) => ({ label, type: "type" }));
686
+ const constructors = ["Some", "None", "Left", "Right", "Less", "Equal", "Greater"].map((label) => ({
687
+ label,
688
+ type: "constant",
689
+ }));
690
+ const globals = [
691
+ ...snippets,
692
+ ...keywords,
693
+ ...constants,
694
+ ...functions.map((label) => ({ label, type: "function" })),
695
+ ...types,
696
+ ...constructors,
697
+ ];
698
+ // The common members of the base namespaces that people use most, offered
699
+ // after `List.`, `Text.` and the others.
700
+ const namespaces = {
701
+ List: "map filter foldLeft foldRight size isEmpty head tail last init reverse take " +
702
+ "drop takeWhile dropWhile dropLast contains indexOf at unsafeAt cons snoc " +
703
+ "range rangeClosed replicate fill zip zipWith unzip flatMap flatten filterMap " +
704
+ "somes sort sortBy distinct any all find findIndex partition span chunk " +
705
+ "indexed mapIndexed maximum minimum product singleton empty unfold uncons " +
706
+ "unsnoc splitAt intersperse slice slices transpose scanLeft count " +
707
+ "countElement toMap of forEach",
708
+ Text: "size isEmpty toCharList fromCharList join split take drop reverse uncons " +
709
+ "unsnoc splitAt indexOf contains startsWith endsWith filter map " +
710
+ "toLowercase toUppercase toNat toInt toFloat toBag leftPad rightPad repeat " +
711
+ "trim segmentBy replace empty",
712
+ Nat: "toInt toText toFloat fromText mod div pow sum product max min diff " +
713
+ "subtractToInt isEven isOdd isSetBit shiftLeft shiftRight and or xor " +
714
+ "toTextBase range rangeClosed inRange increment decrement eq neq gt lt " +
715
+ "sqrt drop",
716
+ Int: "abs toText toNat toFloat fromText negate mod div pow sum product max min " +
717
+ "isEven isOdd signum inRange truncate0 toRepresentation fromRepresentation " +
718
+ "increment decrement",
719
+ Optional: "map flatMap getOrElse getOrBug orElse fold isSome isNone toList map2 " +
720
+ "filter contains toAbort",
721
+ Map: "empty singleton fromList toList insert insertWith delete lookup get " +
722
+ "contains keys values size isEmpty alter adjust update updateWithKey " +
723
+ "union unionWith map mapWithKey filter foldLeft foldRight getOrAbort",
724
+ Char: "toNat fromNat toText isDigit isLetter isUpper isLower isWhitespace " +
725
+ "toLowercase toUppercase inRange",
726
+ Set: "empty singleton fromList toList insert delete contains size isEmpty " +
727
+ "union intersect difference map filter foldLeft",
728
+ };
729
+ const namespaceOptions = {};
730
+ for (const name in namespaces)
731
+ namespaceOptions[name] = namespaces[name].split(" ").map((label) => ({ label, type: "function" }));
732
+ // Every node here opens a scope: the names it binds are visible inside it and
733
+ // nowhere else.
734
+ const ScopeNodes = new Set([
735
+ "Program",
736
+ "Binding",
737
+ "Lambda",
738
+ "MatchCase",
739
+ "Guard",
740
+ "DoExpression",
741
+ "LetExpression",
742
+ "IfExpression",
743
+ ]);
744
+ // The nodes a pattern can't bind names in. A `Constructor` names an existing
745
+ // value, and a qualified `Variable` such as `List.empty` does too.
746
+ const notPattern = new Set([
747
+ "Constructor",
748
+ "Type",
749
+ "Lambda",
750
+ "MatchCase",
751
+ "CasesExpression",
752
+ "MatchExpression",
753
+ "DoExpression",
754
+ "LetExpression",
755
+ "IfExpression",
756
+ "HandleExpression",
757
+ "Operator",
758
+ "QualifiedOperator",
759
+ ]);
760
+ function patternVariables(doc, node, def) {
761
+ if (node.name == "Variable") {
762
+ if (!doc.sliceString(node.from, node.to).includes("."))
763
+ def(node, "variable");
764
+ }
765
+ else if (node.name == "EffectPattern") {
766
+ effectPatternVariables(doc, node, def);
767
+ }
768
+ else if (!notPattern.has(node.name)) {
769
+ for (let ch = node.firstChild; ch; ch = ch.nextSibling)
770
+ patternVariables(doc, ch, def);
771
+ }
772
+ }
773
+ // `{ ask x -> resume }` binds `x` and `resume`, but `ask` names the request.
774
+ // `{ result }` binds `result`.
775
+ function effectPatternVariables(doc, node, def) {
776
+ var _a;
777
+ const arrow = node.getChild("->");
778
+ if (!arrow) {
779
+ for (let ch = node.firstChild; ch; ch = ch.nextSibling)
780
+ patternVariables(doc, ch, def);
781
+ return;
782
+ }
783
+ for (let ch = node.firstChild; ch; ch = ch.nextSibling) {
784
+ if (ch.from >= arrow.to)
785
+ patternVariables(doc, ch, def);
786
+ else if (ch.name == "ApplyExpression")
787
+ for (let arg = (_a = ch.firstChild) === null || _a === void 0 ? void 0 : _a.nextSibling; arg; arg = arg.nextSibling)
788
+ patternVariables(doc, arg, def);
789
+ }
790
+ }
791
+ function isFunctionType(type) {
792
+ return !!type && (!!type.getChild("->") || !!type.getChild("'"));
793
+ }
794
+ // The last segment of a qualified name, which Unison lets code use on its own.
795
+ // `sublist.isSuperlist` can be called as `isSuperlist`.
796
+ function suffix(name) {
797
+ const dot = name.lastIndexOf(".");
798
+ return dot > 0 && dot < name.length - 1 ? name.slice(dot + 1) : null;
799
+ }
800
+ function isRhs(node) {
801
+ return node.name == "=";
802
+ }
803
+ // What a node declares into the scope around it. Returning true stops the walk
804
+ // going into the node.
805
+ const gatherers = {
806
+ Binding(doc, node, def) {
807
+ const first = node.firstChild;
808
+ if ((first === null || first === void 0 ? void 0 : first.name) == "DeclName") {
809
+ const hasParams = first.nextSibling && !isRhs(first.nextSibling);
810
+ def(first, hasParams ? "function" : "variable");
811
+ }
812
+ else if (first && first.name != "OperatorExpression") {
813
+ patternVariables(doc, first, def);
814
+ }
815
+ return true;
816
+ },
817
+ Signature(doc, node, def) {
818
+ const name = node.getChild("DeclName");
819
+ if (name)
820
+ def(name, isFunctionType(node.getChild("Type")) ? "function" : "variable");
821
+ return true;
822
+ },
823
+ TypeDeclaration(doc, node, def) {
824
+ const name = node.getChild("TypeName");
825
+ if (name)
826
+ def(name, "type");
827
+ for (const con of node.getChildren("ConstructorDeclaration")) {
828
+ const ctor = con.getChild("DeclConstructor");
829
+ if (ctor)
830
+ def(ctor, "constant");
831
+ }
832
+ return true;
833
+ },
834
+ AbilityDeclaration(doc, node, def) {
835
+ const name = node.getChild("TypeName");
836
+ if (name)
837
+ def(name, "type");
838
+ return false;
839
+ },
840
+ };
841
+ // The names a scope node binds itself: a function's parameters, a lambda's
842
+ // arguments, or the variables in a case's pattern.
843
+ function ownBindings(doc, node, def) {
844
+ switch (node.name) {
845
+ case "Binding": {
846
+ const first = node.firstChild;
847
+ if ((first === null || first === void 0 ? void 0 : first.name) == "DeclName") {
848
+ for (let ch = first.nextSibling; ch && !isRhs(ch); ch = ch.nextSibling)
849
+ patternVariables(doc, ch, def);
850
+ }
851
+ else if ((first === null || first === void 0 ? void 0 : first.name) == "OperatorExpression") {
852
+ // `a +++ b = ...` defines `+++`, and `a` and `b` are its parameters.
853
+ patternVariables(doc, first, def);
854
+ }
855
+ break;
856
+ }
857
+ case "Lambda":
858
+ if (node.firstChild)
859
+ patternVariables(doc, node.firstChild, def);
860
+ break;
861
+ case "MatchCase":
862
+ for (let ch = node.firstChild; ch && ch.name != "->" && ch.name != "Guard"; ch = ch.nextSibling)
863
+ patternVariables(doc, ch, def);
864
+ break;
865
+ }
866
+ }
867
+ const cache = new common.NodeWeakMap();
868
+ function getScope(doc, node) {
869
+ const cached = cache.get(node);
870
+ if (cached)
871
+ return cached;
872
+ const completions = [];
873
+ const seen = new Set();
874
+ const add = (label, type) => {
875
+ if (!label || seen.has(label))
876
+ return;
877
+ seen.add(label);
878
+ completions.push({ label, type });
879
+ };
880
+ const def = (n, type) => {
881
+ const label = doc.sliceString(n.from, n.to);
882
+ add(label, type);
883
+ const short = suffix(label);
884
+ if (short)
885
+ add(short, type);
886
+ };
887
+ // A guard sees the variables of the case it belongs to, which the case's
888
+ // own scope gives it.
889
+ if (node.name != "Guard")
890
+ ownBindings(doc, node, def);
891
+ const walk = (parent) => {
892
+ for (let ch = parent.firstChild; ch; ch = ch.nextSibling) {
893
+ const gather = gatherers[ch.name];
894
+ if (gather && gather(doc, ch, def))
895
+ continue;
896
+ if (!ScopeNodes.has(ch.name))
897
+ walk(ch);
898
+ }
899
+ };
900
+ walk(node);
901
+ cache.set(node, completions);
902
+ return completions;
903
+ }
904
+ const Identifier = /^[\w'!\xa1-￿]*$/;
905
+ const dontComplete = ["Text", "Char", "Number", "LineComment", "BlockComment", "Doc", "DocLiteral", "Fold"];
906
+ // True if the word being typed follows a dot, as in `List.ma`.
907
+ function afterDot(context, from) {
908
+ return context.state.sliceDoc(Math.max(0, from - 1), from) == ".";
909
+ }
910
+ /// Completes the names declared in the file that are in scope at the cursor:
911
+ /// top-level definitions, types, constructors and ability operations,
912
+ /// parameters, pattern variables, lambda arguments, and the bindings of the
913
+ /// blocks around the cursor.
914
+ const localCompletionSource = (context) => {
915
+ const inner = language.syntaxTree(context.state).resolveInner(context.pos, -1);
916
+ if (dontComplete.includes(inner.name))
917
+ return null;
918
+ const word = context.matchBefore(/[\w'!\xa1-￿]+/);
919
+ if (!word && !context.explicit)
920
+ return null;
921
+ const from = word ? word.from : context.pos;
922
+ if (afterDot(context, from))
923
+ return null;
924
+ let options = [];
925
+ for (let pos = inner; pos; pos = pos.parent)
926
+ if (ScopeNodes.has(pos.name))
927
+ options = options.concat(getScope(context.state.doc, pos));
928
+ return { options, from, validFor: Identifier };
929
+ };
930
+ /// Completes a name after a namespace and a dot, as in `List.` or `Nat.`. It
931
+ /// offers the common members of the base namespaces, and the names the file
932
+ /// declares in that namespace, such as `isSuperlist` after `sublist.`.
933
+ const namespaceCompletionSource = (context) => {
934
+ var _a;
935
+ const match = context.matchBefore(/(?:[A-Za-z_][\w'!]*\.)+[\w'!]*/);
936
+ if (!match)
937
+ return null;
938
+ const tree = language.syntaxTree(context.state);
939
+ if (dontComplete.includes(tree.resolveInner(context.pos, -1).name))
940
+ return null;
941
+ const dot = match.text.lastIndexOf(".");
942
+ const namespace = match.text.slice(0, dot);
943
+ const from = match.from + dot + 1;
944
+ const options = [...((_a = namespaceOptions[namespace]) !== null && _a !== void 0 ? _a : [])];
945
+ const seen = new Set(options.map((o) => o.label));
946
+ const prefix = namespace + ".";
947
+ for (const option of getScope(context.state.doc, tree.topNode)) {
948
+ if (!option.label.startsWith(prefix))
949
+ continue;
950
+ const rest = option.label.slice(prefix.length);
951
+ if (!rest || seen.has(rest))
952
+ continue;
953
+ seen.add(rest);
954
+ options.push({ label: rest, type: option.type });
955
+ }
956
+ if (!options.length)
957
+ return null;
958
+ return { options, from, validFor: Identifier };
959
+ };
960
+ /// Keywords, snippets, and the common functions, types and constructors from
961
+ /// base. It offers nothing in texts and comments, or after a dot.
962
+ const unisonCompletion = autocomplete.ifNotIn(dontComplete, (context) => {
963
+ const word = context.matchBefore(/[\w'!>\xa1-￿]+/);
964
+ if (word && afterDot(context, word.from))
965
+ return null;
966
+ if (!word && context.matchBefore(/\.$/))
967
+ return null;
968
+ return autocomplete.completeFromList(globals)(context);
969
+ });
970
+
971
+ // Folding a block keeps its first line in view, which is the line that says
972
+ // what was folded away.
973
+ function foldBody(node, state) {
974
+ const line = state.doc.lineAt(node.from);
975
+ return node.to > line.to ? { from: line.to, to: node.to } : null;
976
+ }
977
+ // The tree can't say where a new line belongs, because a block ends at its last
978
+ // token and the new line is past that. So the line above decides. If it opens a
979
+ // block or leaves an expression unfinished, the new line is indented one step
980
+ // further. Otherwise the new line keeps the same indentation.
981
+ const opensBlock = /(^|[^\w'!])(do|let|cases|with|then|else|where|handle)$/;
982
+ const continuesLine = /(=|->|\||\(|\[|\{|,|:|\|>|<\||&&|\|\||\+\+|\bif|\bmatch)$/;
983
+ const wantsIndent = /^\s*(then|else|with)\b/;
984
+ const indentUnison = language.indentService.of((context, pos) => {
985
+ const inside = language.syntaxTree(context.state).resolveInner(pos, -1).name;
986
+ if (inside == "BlockComment" || inside == "Doc" || inside == "Text")
987
+ return null;
988
+ let line = context.lineAt(pos, -1);
989
+ while (!/\S/.test(line.text) && line.from > 0)
990
+ line = context.lineAt(line.from - 1, -1);
991
+ if (!/\S/.test(line.text))
992
+ return 0;
993
+ const code = line.text.replace(/\s*--(\s.*|-*)$/, "").trimEnd();
994
+ const base = context.lineIndent(line.from);
995
+ if (opensBlock.test(code) || continuesLine.test(code))
996
+ return base + context.unit;
997
+ if (wantsIndent.test(context.state.doc.sliceString(pos, pos + 20)))
998
+ return base + context.unit;
999
+ return base;
1000
+ });
1001
+ const unisonLanguage = language.LRLanguage.define({
1002
+ name: "unison",
1003
+ parser: parser.configure({
1004
+ props: [
1005
+ language.foldNodeProp.add({
1006
+ "Binding Signature TypeDeclaration AbilityDeclaration": foldBody,
1007
+ "DoExpression LetExpression CasesExpression MatchExpression MatchCase": foldBody,
1008
+ "IfExpression HandleExpression ListExpression BlockComment Doc": foldBody,
1009
+ }),
1010
+ highlight.styleTags({
1011
+ "use namespace": highlight.tags.moduleKeyword,
1012
+ "type ability structural unique where": highlight.tags.definitionKeyword,
1013
+ "match with cases if then else do let handle": highlight.tags.controlKeyword,
1014
+ forall: highlight.tags.keyword,
1015
+ Boolean: highlight.tags.bool,
1016
+ Number: highlight.tags.number,
1017
+ Text: highlight.tags.string,
1018
+ Char: highlight.tags.character,
1019
+ Wildcard: highlight.tags.atom,
1020
+ LineComment: highlight.tags.lineComment,
1021
+ BlockComment: highlight.tags.blockComment,
1022
+ "Doc DocLiteral Fold": highlight.tags.docComment,
1023
+ Hash: highlight.tags.special(highlight.tags.variableName),
1024
+ "test> >": highlight.tags.keyword,
1025
+ DeclName: highlight.tags.definition(highlight.tags.variableName),
1026
+ "Binding/DeclName": highlight.tags.definition(highlight.tags.function(highlight.tags.variableName)),
1027
+ "Callee/Variable": highlight.tags.function(highlight.tags.variableName),
1028
+ Variable: highlight.tags.variableName,
1029
+ Constructor: highlight.tags.className,
1030
+ DeclConstructor: highlight.tags.definition(highlight.tags.className),
1031
+ "TypeDeclaration/TypeName AbilityDeclaration/TypeName": highlight.tags.definition(highlight.tags.typeName),
1032
+ TypeName: highlight.tags.typeName,
1033
+ TypeVariable: highlight.tags.typeName,
1034
+ FieldName: highlight.tags.definition(highlight.tags.propertyName),
1035
+ "Operator QualifiedOperator": highlight.tags.operator,
1036
+ "= :": highlight.tags.definitionOperator,
1037
+ "->": highlight.tags.typeOperator,
1038
+ '"|" "@" "\'" "!"': highlight.tags.operator,
1039
+ ". ,": highlight.tags.separator,
1040
+ "( )": highlight.tags.paren,
1041
+ "[ ]": highlight.tags.squareBracket,
1042
+ "{ }": highlight.tags.brace,
1043
+ }),
1044
+ ],
1045
+ }),
1046
+ languageData: {
1047
+ commentTokens: { line: "--", block: { open: "{-", close: "-}" } },
1048
+ closeBrackets: { brackets: ["(", "[", "{", '"'] },
1049
+ indentOnInput: /^\s*(then|else|with)$/,
1050
+ },
1051
+ });
1052
+ /// Unison language support, with completion for keywords, snippets, common
1053
+ /// base library names and the names declared in the file.
1054
+ function unison() {
1055
+ return new language.LanguageSupport(unisonLanguage, [
1056
+ indentUnison,
1057
+ unisonLanguage.data.of({ autocomplete: unisonCompletion }),
1058
+ unisonLanguage.data.of({ autocomplete: namespaceCompletionSource }),
1059
+ unisonLanguage.data.of({ autocomplete: localCompletionSource }),
1060
+ ]);
1061
+ }
1062
+
1063
+ exports.localCompletionSource = localCompletionSource;
1064
+ exports.namespaceCompletionSource = namespaceCompletionSource;
1065
+ exports.parser = parser;
1066
+ exports.snippets = snippets;
1067
+ exports.unison = unison;
1068
+ exports.unisonCompletion = unisonCompletion;
1069
+ exports.unisonLanguage = unisonLanguage;