@exercism/codemirror-lang-elm 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/LICENSE +21 -0
- package/README.md +98 -2
- package/dist/index.cjs +839 -0
- package/dist/index.d.cts +25 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +829 -0
- package/package.json +51 -4
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,839 @@
|
|
|
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 = 120,
|
|
14
|
+
blockSep = 121,
|
|
15
|
+
blockEnd = 122,
|
|
16
|
+
accessDot = 123,
|
|
17
|
+
Qualifier = 4,
|
|
18
|
+
closeBrace = 12,
|
|
19
|
+
closeParen = 27,
|
|
20
|
+
comma = 32,
|
|
21
|
+
closeBracket = 34,
|
|
22
|
+
then = 47,
|
|
23
|
+
_else = 48,
|
|
24
|
+
of = 51,
|
|
25
|
+
_in = 80;
|
|
26
|
+
|
|
27
|
+
// The tokenizer reads back this far to find the start of a line. A line that is
|
|
28
|
+
// indented further than this counts as a continuation, which is harmless.
|
|
29
|
+
const maxIndentation = 400;
|
|
30
|
+
function isSpace(ch) {
|
|
31
|
+
return ch == 32 /* Ch.Space */ || ch == 9 /* Ch.Tab */ || ch == 10 /* Ch.Newline */ || ch == 13 /* Ch.Return */;
|
|
32
|
+
}
|
|
33
|
+
function isUpper(ch) {
|
|
34
|
+
return ch >= 65 /* Ch.UpperA */ && ch <= 90 /* Ch.UpperZ */;
|
|
35
|
+
}
|
|
36
|
+
function isLower(ch) {
|
|
37
|
+
return ch >= 97 /* Ch.LowerA */ && ch <= 122 /* Ch.LowerZ */;
|
|
38
|
+
}
|
|
39
|
+
function isIdentChar(ch) {
|
|
40
|
+
return (isUpper(ch) ||
|
|
41
|
+
isLower(ch) ||
|
|
42
|
+
(ch >= 48 /* Ch.Zero */ && ch <= 57 /* Ch.Nine */) ||
|
|
43
|
+
ch == 95 /* Ch.Underscore */ ||
|
|
44
|
+
ch >= 161 /* Ch.Latin1 */);
|
|
45
|
+
}
|
|
46
|
+
function wordAt(input, offset) {
|
|
47
|
+
let word = "";
|
|
48
|
+
for (let pos = offset; isIdentChar(input.peek(pos)); pos++)
|
|
49
|
+
word += String.fromCharCode(input.peek(pos));
|
|
50
|
+
return word;
|
|
51
|
+
}
|
|
52
|
+
function startsComment(input) {
|
|
53
|
+
return ((input.next == 45 /* Ch.Minus */ && input.peek(1) == 45 /* Ch.Minus */) ||
|
|
54
|
+
(input.next == 123 /* Ch.BraceL */ && input.peek(1) == 45 /* Ch.Minus */));
|
|
55
|
+
}
|
|
56
|
+
// ── Comments ──────────────────────────────────────────────────────────────────
|
|
57
|
+
/// Elm's block comments nest, so `{- {- -} -}` is one comment. A token rule
|
|
58
|
+
/// can't count the nesting, so comments are read here. `{-|` starts a
|
|
59
|
+
/// documentation comment.
|
|
60
|
+
const comments = new lr.ExternalTokenizer((input) => {
|
|
61
|
+
if (input.next == 45 /* Ch.Minus */) {
|
|
62
|
+
if (input.peek(1) != 45 /* Ch.Minus */)
|
|
63
|
+
return;
|
|
64
|
+
let pos = 2;
|
|
65
|
+
while (input.peek(pos) != 10 /* Ch.Newline */ && input.peek(pos) != -1 /* Ch.EOF */)
|
|
66
|
+
pos++;
|
|
67
|
+
input.acceptToken(LineComment, pos);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (input.next != 123 /* Ch.BraceL */ || input.peek(1) != 45 /* Ch.Minus */)
|
|
71
|
+
return;
|
|
72
|
+
const term = input.peek(2) == 124 /* Ch.Pipe */ ? DocComment : BlockComment;
|
|
73
|
+
let depth = 0;
|
|
74
|
+
for (let pos = 0;; pos++) {
|
|
75
|
+
const ch = input.peek(pos);
|
|
76
|
+
if (ch == -1 /* Ch.EOF */) {
|
|
77
|
+
input.acceptToken(term, pos);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (ch == 123 /* Ch.BraceL */ && input.peek(pos + 1) == 45 /* Ch.Minus */) {
|
|
81
|
+
depth++;
|
|
82
|
+
pos++;
|
|
83
|
+
}
|
|
84
|
+
else if (ch == 45 /* Ch.Minus */ && input.peek(pos + 1) == 125 /* Ch.BraceR */) {
|
|
85
|
+
depth--;
|
|
86
|
+
pos++;
|
|
87
|
+
if (!depth) {
|
|
88
|
+
input.acceptToken(term, pos + 1);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
// ── Layout ────────────────────────────────────────────────────────────────────
|
|
95
|
+
/// One open block, and the column its items line up on. The file is the
|
|
96
|
+
/// outermost block, at column 0.
|
|
97
|
+
class Layout {
|
|
98
|
+
constructor(parent, column) {
|
|
99
|
+
this.parent = parent;
|
|
100
|
+
this.column = column;
|
|
101
|
+
this.hash = (parent ? parent.hash * 31 : 0) + column + 1;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const topLayout = new Layout(null, 0);
|
|
105
|
+
// The column of the current position, and whether it is the first thing on its
|
|
106
|
+
// line. A tab moves to the next multiple of four, which is what elm-format
|
|
107
|
+
// would turn it into.
|
|
108
|
+
function lineInfo(input) {
|
|
109
|
+
let column = 0;
|
|
110
|
+
let firstOnLine = true;
|
|
111
|
+
let offset = -1;
|
|
112
|
+
for (; offset > -maxIndentation; offset--) {
|
|
113
|
+
const ch = input.peek(offset);
|
|
114
|
+
if (ch == -1 /* Ch.EOF */ || ch == 10 /* Ch.Newline */ || ch == 13 /* Ch.Return */)
|
|
115
|
+
break;
|
|
116
|
+
if (!isSpace(ch))
|
|
117
|
+
firstOnLine = false;
|
|
118
|
+
}
|
|
119
|
+
if (offset == -maxIndentation)
|
|
120
|
+
return { column: maxIndentation, firstOnLine: false };
|
|
121
|
+
for (let pos = offset + 1; pos < 0; pos++) {
|
|
122
|
+
if (input.peek(pos) == 9 /* Ch.Tab */)
|
|
123
|
+
column += 4 - (column % 4);
|
|
124
|
+
else
|
|
125
|
+
column++;
|
|
126
|
+
}
|
|
127
|
+
return { column, firstOnLine };
|
|
128
|
+
}
|
|
129
|
+
// A block closes in front of a token that can't go inside it. In
|
|
130
|
+
// `let x = 1 in x`, the `in` ends the block although it is on the same line.
|
|
131
|
+
function closesBlock(input, stack) {
|
|
132
|
+
switch (input.next) {
|
|
133
|
+
case 41 /* Ch.ParenR */:
|
|
134
|
+
return !stack.canShift(closeParen);
|
|
135
|
+
case 93 /* Ch.BracketR */:
|
|
136
|
+
return !stack.canShift(closeBracket);
|
|
137
|
+
case 125 /* Ch.BraceR */:
|
|
138
|
+
return !stack.canShift(closeBrace);
|
|
139
|
+
case 44 /* Ch.Comma */:
|
|
140
|
+
return !stack.canShift(comma);
|
|
141
|
+
}
|
|
142
|
+
if (!isLower(input.next))
|
|
143
|
+
return false;
|
|
144
|
+
switch (wordAt(input, 0)) {
|
|
145
|
+
case "in":
|
|
146
|
+
return !stack.canShift(_in);
|
|
147
|
+
case "then":
|
|
148
|
+
return !stack.canShift(then);
|
|
149
|
+
case "else":
|
|
150
|
+
return !stack.canShift(_else);
|
|
151
|
+
case "of":
|
|
152
|
+
return !stack.canShift(of);
|
|
153
|
+
default:
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/// The block markers Elm doesn't write. A block opens at the first token after
|
|
158
|
+
/// `let` or `of`. A line that starts at the block's column starts its next
|
|
159
|
+
/// item. The block ends at the first line that starts further left, in front of
|
|
160
|
+
/// a token that can't go inside it, or at the end of the file.
|
|
161
|
+
const layout = new lr.ExternalTokenizer((input, stack) => {
|
|
162
|
+
const cx = stack.context;
|
|
163
|
+
const nested = cx.parent != null;
|
|
164
|
+
if (input.next == -1 /* Ch.EOF */) {
|
|
165
|
+
if (stack.canShift(blockOpen))
|
|
166
|
+
input.acceptToken(blockOpen);
|
|
167
|
+
else if (nested && stack.canShift(blockEnd))
|
|
168
|
+
input.acceptToken(blockEnd);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
// The grammar skips whitespace and comments, so layout is decided in front
|
|
172
|
+
// of the tokens that are left.
|
|
173
|
+
if (isSpace(input.next) || startsComment(input))
|
|
174
|
+
return;
|
|
175
|
+
if (stack.canShift(blockOpen)) {
|
|
176
|
+
input.acceptToken(blockOpen);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (nested && closesBlock(input, stack) && stack.canShift(blockEnd)) {
|
|
180
|
+
input.acceptToken(blockEnd);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const { column, firstOnLine } = lineInfo(input);
|
|
184
|
+
if (!firstOnLine)
|
|
185
|
+
return;
|
|
186
|
+
if (nested && column < cx.column && stack.canShift(blockEnd))
|
|
187
|
+
input.acceptToken(blockEnd);
|
|
188
|
+
else if (column == cx.column && stack.canShift(blockSep))
|
|
189
|
+
input.acceptToken(blockSep);
|
|
190
|
+
}, { contextual: true });
|
|
191
|
+
/// The stack of open blocks. Each block remembers the column of its first
|
|
192
|
+
/// token, and the tokenizer above compares every line with it.
|
|
193
|
+
const trackLayout = new lr.ContextTracker({
|
|
194
|
+
start: topLayout,
|
|
195
|
+
shift(context, term, stack, input) {
|
|
196
|
+
var _a;
|
|
197
|
+
if (term == blockOpen)
|
|
198
|
+
return new Layout(context, lineInfo(input).column);
|
|
199
|
+
if (term == blockEnd)
|
|
200
|
+
return (_a = context.parent) !== null && _a !== void 0 ? _a : context;
|
|
201
|
+
return context;
|
|
202
|
+
},
|
|
203
|
+
hash: (context) => context.hash,
|
|
204
|
+
});
|
|
205
|
+
// ── Dots ──────────────────────────────────────────────────────────────────────
|
|
206
|
+
/// Two kinds of dot that a token rule can't tell apart.
|
|
207
|
+
///
|
|
208
|
+
/// The module part of a qualified name, such as `List.` in `List.map` or
|
|
209
|
+
/// `Html.Attributes.` in `Html.Attributes.class`, becomes one `Qualifier`
|
|
210
|
+
/// token. That way `Maybe.Just` is one constructor and `Dict.Dict` is one type.
|
|
211
|
+
///
|
|
212
|
+
/// A dot written straight after a name or a closing bracket reads a field, as
|
|
213
|
+
/// in `model.count` or `(f x).name`. A dot with a space in front of it starts
|
|
214
|
+
/// an accessor function, as in `List.map .name people`.
|
|
215
|
+
const dots = new lr.ExternalTokenizer((input, stack) => {
|
|
216
|
+
if (input.next == 46 /* Ch.Dot */) {
|
|
217
|
+
if (!isLower(input.peek(1)))
|
|
218
|
+
return;
|
|
219
|
+
const before = input.peek(-1);
|
|
220
|
+
if (!(isIdentChar(before) || before == 41 /* Ch.ParenR */ || before == 125 /* Ch.BraceR */))
|
|
221
|
+
return;
|
|
222
|
+
if (stack.canShift(accessDot))
|
|
223
|
+
input.acceptToken(accessDot, 1);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (!isUpper(input.next))
|
|
227
|
+
return;
|
|
228
|
+
let pos = 0;
|
|
229
|
+
let end = 0;
|
|
230
|
+
while (isUpper(input.peek(pos))) {
|
|
231
|
+
while (isIdentChar(input.peek(pos)))
|
|
232
|
+
pos++;
|
|
233
|
+
if (input.peek(pos) != 46 /* Ch.Dot */)
|
|
234
|
+
break;
|
|
235
|
+
const after = input.peek(pos + 1);
|
|
236
|
+
if (!isUpper(after) && !isLower(after))
|
|
237
|
+
break;
|
|
238
|
+
pos++;
|
|
239
|
+
end = pos;
|
|
240
|
+
}
|
|
241
|
+
if (end && stack.canShift(Qualifier))
|
|
242
|
+
input.acceptToken(Qualifier, end);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
246
|
+
const spec_lowerIdent = {__proto__:null,port:14, effect:16, module:18, where:22, if:92, then:94, else:96, case:100, of:102, as:108, let:134, in:160, exposing:168, import:180, type:186, alias:188, infix:204};
|
|
247
|
+
const spec_operatorToken = {__proto__:null,"=":34, "-":40, "::":42, "|":78, "->":130, ":":140, "..":170};
|
|
248
|
+
const parser = lr.LRParser.deserialize({
|
|
249
|
+
version: 14,
|
|
250
|
+
states: "EtQ`QXOOOOQT'#Ds'#DsOOQR'#FO'#FOQwQZOOO!qQ]O'#DrO!{Q]O'#CbO#TQXO'#CbO#]QXO'#CbO!{Q]O'#EXO#bQXO'#EaO#jQXO'#EeO`QXO'#EvQwQZOOOOQV'#Cs'#CsO#oQXO'#CsOOQT'#De'#DeO#tQ]O'#DjO#{Q]O'#DmO$SQXO'#DnOOQT'#FY'#FYOOQT'#Ej'#EjO$[Q]O,5:hO$cQXO'#DiO$hQ]O,5:^O$yQ]O,5:hOOQR'#Cf'#CfO%zQXO'#CfO&PQXO,58|O!{Q]O,58|O&XQXO,5;OO&^QZO,5:sOOQP'#E_'#E_O#eQXO,5:vO&lQXO,5:{O&tQXO,5;POOQR,5;b,5;bOOQR-E8t-E8tOOQV,59_,59_OOQT,5:U,5:UO&yQXO,5:WO'UQ]O'#FYOOQP'#FX'#FXO'lQXO'#FXOOQT,5:X,5:XO(QQXO,5:XOOQT,5:Y,5:YO(]QXO,5:YOOQT-E8h-E8hO$yQ]O1G0SOOQT,5:T,5:TOOQV'#Dw'#DwO(eQXO'#DwOOQV'#Dx'#DxO(jQ]O'#DyO(qQXO'#DzO(yQ_O'#F]OOQV'#F]'#F]OOQR'#F['#F[O)dQZO'#DuOOQR1G/x1G/xO){QZO1G0SOOQV'#Cr'#CrO*aQXO'#CrO+gQ]O'#CzO+wQ]O'#DQO,OQ_O'#FUOOQV'#FW'#FWO-zQ_O'#FVO.nQ_O'#FVO/bQ]O'#DWOOQR'#FU'#FUOOQR'#FS'#FSO0SQXO'#CjO/bQ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%wQ#f![R$u#fQ&V%^R&n&VQ&]%eR&s&]Q!{qQ$Y!xT$[!{$YQ%m$`Q&`%kT&a%m&`Q[RRt[QRORsZQ!^hQ#Z!QQ#l!aQ#p!bQ#|!lQ#}!mQ$w#jQ%x$yQ&Q%VQ&R%WQ&X%_Q&l&TQ&w&iQ&}&pQ'P&xR'T&|n#j!^#Z#l#p#|#}%x&Q&R&X&l&w&}'P'TT#n!a$ap!ch!Q!a!b!l!m#j$y%V%W%_&T&i&p&x&|U#s!f!g#uT#{!k#op!fh!Q!a!b!l!m#j$y%V%W%_&T&i&p&x&|Z#t!f!g!k#o#uQw`Q|aQ$c#OQ$g#TT&j&S&y^dSex!o#S$P%Y]z`a#O#T&S&yQ%^$OR&m&U^![g!V!u$Z$l$r%iR$v#g`!Zg!V!u#g$Z$l$r%iX#d!X#e$_%lT%]$O&UQ%e$QR&r&[",
|
|
253
|
+
nodeNames: "⚠ LineComment BlockComment DocComment Qualifier Program ModuleDeclaration port effect module ModuleName where } { RecordExpression FieldAssignment FieldName = BinaryExpression Operator - :: Variable Constructor Number String Char ) ( ParenExpression UnitExpression TupleExpression , ParenOperator ] [ ListExpression RecordUpdateExpression RecordBase | AccessorFunction FieldAccess CallExpression Callee NegateExpression IfExpression if then else CaseExpression case of CaseBranch AsPattern as PatternVariable ConsPattern ConstructorPattern Wildcard NegativeNumber UnitPattern TuplePattern ParenPattern ListPattern RecordPattern -> LetExpression let TypeAnnotation DeclName : Type TypeApplication TypeConstructor TypeVariable ParenType RecordType FieldType ValueDeclaration DestructuringDeclaration in LambdaExpression \\ ExposingList exposing .. ExposedValue ExposedType ExposedOperator ImportDeclaration import ModuleAlias TypeAliasDeclaration type alias TypeName TypeParameter TypeDeclaration ConstructorDefinition ConstructorName PortDeclaration InfixDeclaration infix",
|
|
254
|
+
maxTerm: 141,
|
|
255
|
+
context: trackLayout,
|
|
256
|
+
nodeProps: [
|
|
257
|
+
["openedBy", 12,"{",27,"(",34,"["],
|
|
258
|
+
["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value) => spec_operatorToken[value] || -1}],
|
|
267
|
+
tokenPrec: 1784
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
// The functions, types and constructors of the modules that every Exercism Elm
|
|
271
|
+
// exercise can import: elm/core, plus elm/regex, elm/parser, elm/time,
|
|
272
|
+
// elm/random and elm/json from the track's `elm.json`.
|
|
273
|
+
const words = (text) => text.split(/\s+/).filter(Boolean);
|
|
274
|
+
const modules = {
|
|
275
|
+
Basics: {
|
|
276
|
+
values: words(`
|
|
277
|
+
toFloat round floor ceiling truncate max min compare not xor modBy
|
|
278
|
+
remainderBy negate abs clamp sqrt logBase e pi cos sin tan acos asin atan
|
|
279
|
+
atan2 degrees radians turns toPolar fromPolar isNaN isInfinite identity
|
|
280
|
+
always never`),
|
|
281
|
+
types: words("Int Float Bool Order Never"),
|
|
282
|
+
constructors: words("True False LT EQ GT"),
|
|
283
|
+
},
|
|
284
|
+
List: {
|
|
285
|
+
values: words(`
|
|
286
|
+
singleton repeat range map indexedMap foldl foldr filter filterMap length
|
|
287
|
+
reverse member all any maximum minimum sum product append concat concatMap
|
|
288
|
+
intersperse map2 map3 map4 map5 sort sortBy sortWith isEmpty head tail
|
|
289
|
+
take drop partition unzip`),
|
|
290
|
+
types: words("List"),
|
|
291
|
+
},
|
|
292
|
+
String: {
|
|
293
|
+
values: words(`
|
|
294
|
+
isEmpty length reverse repeat replace append concat split join words lines
|
|
295
|
+
slice left right dropLeft dropRight contains startsWith endsWith indexes
|
|
296
|
+
indices toInt fromInt toFloat fromFloat fromChar cons uncons toList
|
|
297
|
+
fromList toUpper toLower pad padLeft padRight trim trimLeft trimRight map
|
|
298
|
+
filter foldl foldr any all`),
|
|
299
|
+
types: words("String"),
|
|
300
|
+
},
|
|
301
|
+
Char: {
|
|
302
|
+
values: words(`
|
|
303
|
+
isUpper isLower isAlpha isAlphaNum isDigit isOctDigit isHexDigit toUpper
|
|
304
|
+
toLower toLocaleUpper toLocaleLower toCode fromCode`),
|
|
305
|
+
types: words("Char"),
|
|
306
|
+
},
|
|
307
|
+
Maybe: {
|
|
308
|
+
values: words("withDefault map map2 map3 map4 map5 andThen"),
|
|
309
|
+
types: words("Maybe"),
|
|
310
|
+
constructors: words("Just Nothing"),
|
|
311
|
+
},
|
|
312
|
+
Result: {
|
|
313
|
+
values: words("map map2 map3 map4 map5 andThen withDefault toMaybe fromMaybe mapError"),
|
|
314
|
+
types: words("Result"),
|
|
315
|
+
constructors: words("Ok Err"),
|
|
316
|
+
},
|
|
317
|
+
Tuple: {
|
|
318
|
+
values: words("pair first second mapFirst mapSecond mapBoth"),
|
|
319
|
+
},
|
|
320
|
+
Dict: {
|
|
321
|
+
values: words(`
|
|
322
|
+
empty singleton insert update remove isEmpty member get size keys values
|
|
323
|
+
toList fromList map foldl foldr filter partition union intersect diff
|
|
324
|
+
merge`),
|
|
325
|
+
types: words("Dict"),
|
|
326
|
+
},
|
|
327
|
+
Set: {
|
|
328
|
+
values: words(`
|
|
329
|
+
empty singleton insert remove isEmpty member size union intersect diff
|
|
330
|
+
toList fromList map foldl foldr filter partition`),
|
|
331
|
+
types: words("Set"),
|
|
332
|
+
},
|
|
333
|
+
Array: {
|
|
334
|
+
values: words(`
|
|
335
|
+
empty initialize repeat fromList isEmpty length get set push append slice
|
|
336
|
+
toList toIndexedList map indexedMap foldl foldr filter`),
|
|
337
|
+
types: words("Array"),
|
|
338
|
+
},
|
|
339
|
+
Bitwise: {
|
|
340
|
+
values: words("and or xor complement shiftLeftBy shiftRightBy shiftRightZfBy"),
|
|
341
|
+
},
|
|
342
|
+
Debug: {
|
|
343
|
+
values: words("toString log todo"),
|
|
344
|
+
},
|
|
345
|
+
Regex: {
|
|
346
|
+
values: words(`
|
|
347
|
+
fromString fromStringWith never contains split find replace splitAtMost
|
|
348
|
+
findAtMost replaceAtMost`),
|
|
349
|
+
types: words("Regex Options Match"),
|
|
350
|
+
},
|
|
351
|
+
Parser: {
|
|
352
|
+
values: words(`
|
|
353
|
+
run int float number symbol keyword variable end succeed problem oneOf map
|
|
354
|
+
backtrackable commit andThen lazy loop sequence spaces lineComment
|
|
355
|
+
multiComment getChompedString chompIf chompWhile chompUntil
|
|
356
|
+
chompUntilEndOr mapChompedString withIndent getIndent getPosition getRow
|
|
357
|
+
getCol getOffset getSource token deadEndsToString`),
|
|
358
|
+
types: words("Parser DeadEnd Problem Step Trailing Nestable"),
|
|
359
|
+
constructors: words("Loop Done Forbidden Optional Mandatory NotNestable Nestable"),
|
|
360
|
+
},
|
|
361
|
+
Time: {
|
|
362
|
+
values: words(`
|
|
363
|
+
now every posixToMillis millisToPosix utc here toYear toMonth toDay
|
|
364
|
+
toWeekday toHour toMinute toSecond toMillis customZone`),
|
|
365
|
+
types: words("Posix Zone Month Weekday"),
|
|
366
|
+
constructors: words(`
|
|
367
|
+
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Mon Tue Wed Thu Fri Sat
|
|
368
|
+
Sun`),
|
|
369
|
+
},
|
|
370
|
+
Random: {
|
|
371
|
+
values: words(`
|
|
372
|
+
generate step initialSeed int float uniform weighted constant list pair
|
|
373
|
+
map map2 map3 andThen lazy independentSeed minInt maxInt`),
|
|
374
|
+
types: words("Generator Seed"),
|
|
375
|
+
},
|
|
376
|
+
"Json.Decode": {
|
|
377
|
+
values: words(`
|
|
378
|
+
string bool int float nullable list array dict keyValuePairs oneOrMore
|
|
379
|
+
field at index maybe oneOf decodeString decodeValue map map2 map3 lazy
|
|
380
|
+
value null succeed fail andThen errorToString`),
|
|
381
|
+
types: words("Decoder Value Error"),
|
|
382
|
+
},
|
|
383
|
+
"Json.Encode": {
|
|
384
|
+
values: words("encode string int float bool null list array set object dict"),
|
|
385
|
+
types: words("Value"),
|
|
386
|
+
},
|
|
387
|
+
};
|
|
388
|
+
// Elm imports these into every module, and exposes the names listed here
|
|
389
|
+
// without a module prefix.
|
|
390
|
+
const defaultImports = words("Basics List Maybe Result String Char Tuple Debug Platform Cmd Sub");
|
|
391
|
+
const defaultExposed = {
|
|
392
|
+
values: modules.Basics.values,
|
|
393
|
+
types: [
|
|
394
|
+
...modules.Basics.types,
|
|
395
|
+
"List",
|
|
396
|
+
"Maybe",
|
|
397
|
+
"Result",
|
|
398
|
+
"String",
|
|
399
|
+
"Char",
|
|
400
|
+
"Program",
|
|
401
|
+
"Cmd",
|
|
402
|
+
"Sub",
|
|
403
|
+
],
|
|
404
|
+
constructors: [...modules.Basics.constructors, "Just", "Nothing", "Ok", "Err"],
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
/// Snippets for the constructs people write most often in Elm.
|
|
408
|
+
const snippets = [
|
|
409
|
+
autocomplete.snippetCompletion("${name} : ${Type} -> ${Type}\n${name} ${arg} =\n\t${}", {
|
|
410
|
+
label: "fun",
|
|
411
|
+
detail: "function with annotation",
|
|
412
|
+
type: "keyword",
|
|
413
|
+
}),
|
|
414
|
+
autocomplete.snippetCompletion("case ${expression} of\n\t${pattern} ->\n\t\t${}", {
|
|
415
|
+
label: "case",
|
|
416
|
+
detail: "of",
|
|
417
|
+
type: "keyword",
|
|
418
|
+
}),
|
|
419
|
+
autocomplete.snippetCompletion("if ${condition} then\n\t${}\n\nelse\n\t${}", {
|
|
420
|
+
label: "if",
|
|
421
|
+
detail: "then else",
|
|
422
|
+
type: "keyword",
|
|
423
|
+
}),
|
|
424
|
+
autocomplete.snippetCompletion("let\n\t${name} =\n\t\t${value}\nin\n${}", {
|
|
425
|
+
label: "let",
|
|
426
|
+
detail: "in",
|
|
427
|
+
type: "keyword",
|
|
428
|
+
}),
|
|
429
|
+
autocomplete.snippetCompletion("\\${x} -> ${}", {
|
|
430
|
+
label: "\\",
|
|
431
|
+
detail: "lambda",
|
|
432
|
+
type: "keyword",
|
|
433
|
+
}),
|
|
434
|
+
autocomplete.snippetCompletion("type ${Name}\n\t= ${First}\n\t| ${Second}", {
|
|
435
|
+
label: "type",
|
|
436
|
+
detail: "custom type",
|
|
437
|
+
type: "keyword",
|
|
438
|
+
}),
|
|
439
|
+
autocomplete.snippetCompletion("type alias ${Name} =\n\t{ ${field} : ${Type}\n\t}", {
|
|
440
|
+
label: "type alias",
|
|
441
|
+
detail: "record",
|
|
442
|
+
type: "keyword",
|
|
443
|
+
}),
|
|
444
|
+
autocomplete.snippetCompletion("module ${Name} exposing (${names})\n\n${}", {
|
|
445
|
+
label: "module",
|
|
446
|
+
detail: "header",
|
|
447
|
+
type: "keyword",
|
|
448
|
+
}),
|
|
449
|
+
autocomplete.snippetCompletion("import ${Module} exposing (${names})", {
|
|
450
|
+
label: "import",
|
|
451
|
+
detail: "exposing",
|
|
452
|
+
type: "keyword",
|
|
453
|
+
}),
|
|
454
|
+
];
|
|
455
|
+
const keywords = "if then else case of let in type alias module exposing import as port"
|
|
456
|
+
.split(" ")
|
|
457
|
+
.map((label) => ({ label, type: "keyword" }));
|
|
458
|
+
function membersToCompletions(members) {
|
|
459
|
+
var _a, _b;
|
|
460
|
+
return [
|
|
461
|
+
...members.values.map((label) => ({ label, type: "function" })),
|
|
462
|
+
...((_a = members.types) !== null && _a !== void 0 ? _a : []).map((label) => ({ label, type: "type" })),
|
|
463
|
+
...((_b = members.constructors) !== null && _b !== void 0 ? _b : []).map((label) => ({ label, type: "enum" })),
|
|
464
|
+
];
|
|
465
|
+
}
|
|
466
|
+
const moduleNames = Object.keys(modules)
|
|
467
|
+
.filter((name) => !name.includes("."))
|
|
468
|
+
.concat("Json")
|
|
469
|
+
.map((label) => ({ label, type: "namespace" }));
|
|
470
|
+
const dontComplete = ["String", "Char", "LineComment", "BlockComment", "DocComment"];
|
|
471
|
+
const Identifier = /^\w*$/;
|
|
472
|
+
// A word straight after a dot names a member of a module or a field of a
|
|
473
|
+
// record, and the sources for bare names have nothing useful to say there.
|
|
474
|
+
function afterDot(context) {
|
|
475
|
+
const word = context.matchBefore(/\w*/);
|
|
476
|
+
const from = word ? word.from : context.pos;
|
|
477
|
+
return from > 0 && context.state.sliceDoc(from - 1, from) == ".";
|
|
478
|
+
}
|
|
479
|
+
const fixedNames = autocomplete.completeFromList([
|
|
480
|
+
...snippets,
|
|
481
|
+
...keywords,
|
|
482
|
+
...membersToCompletions(defaultExposed),
|
|
483
|
+
...moduleNames,
|
|
484
|
+
]);
|
|
485
|
+
/// Keywords, snippets, the names Elm imports into every module, and the module
|
|
486
|
+
/// names. It offers nothing inside strings and comments, or after a dot.
|
|
487
|
+
const elmCompletion = autocomplete.ifNotIn(dontComplete, (context) => afterDot(context) ? null : fixedNames(context));
|
|
488
|
+
function imports(state) {
|
|
489
|
+
const found = [];
|
|
490
|
+
const doc = state.doc;
|
|
491
|
+
const top = language.syntaxTree(state).topNode;
|
|
492
|
+
for (const node of top.getChildren("ImportDeclaration")) {
|
|
493
|
+
const name = node.getChild("ModuleName");
|
|
494
|
+
if (!name)
|
|
495
|
+
continue;
|
|
496
|
+
const alias = node.getChild("ModuleAlias");
|
|
497
|
+
const exposing = node.getChild("ExposingList");
|
|
498
|
+
const exposed = [];
|
|
499
|
+
let exposesAll = false;
|
|
500
|
+
if (exposing) {
|
|
501
|
+
exposesAll = !!exposing.getChild("..");
|
|
502
|
+
for (const item of exposing.getChildren("ExposedValue"))
|
|
503
|
+
exposed.push(doc.sliceString(item.from, item.to));
|
|
504
|
+
for (const item of exposing.getChildren("ExposedType")) {
|
|
505
|
+
const type = item.firstChild;
|
|
506
|
+
if (type)
|
|
507
|
+
exposed.push(doc.sliceString(item.from, type.to));
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
found.push({
|
|
511
|
+
module: doc.sliceString(name.from, name.to),
|
|
512
|
+
alias: alias ? doc.sliceString(alias.from, alias.to) : null,
|
|
513
|
+
exposesAll,
|
|
514
|
+
exposed,
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
return found;
|
|
518
|
+
}
|
|
519
|
+
/// The members of a module after its name and a dot: `List.` offers `map` and
|
|
520
|
+
/// `foldl`, and after `import Dict as D`, `D.` offers what `Dict.` does.
|
|
521
|
+
const moduleCompletionSource = (context) => {
|
|
522
|
+
const inner = language.syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
523
|
+
if (dontComplete.includes(inner.name))
|
|
524
|
+
return null;
|
|
525
|
+
const match = context.matchBefore(/(?:[A-Z]\w*\.)+\w*/);
|
|
526
|
+
if (!match)
|
|
527
|
+
return null;
|
|
528
|
+
const lastDot = match.text.lastIndexOf(".");
|
|
529
|
+
const qualifier = match.text.slice(0, lastDot);
|
|
530
|
+
const from = match.from + lastDot + 1;
|
|
531
|
+
let module = qualifier;
|
|
532
|
+
for (const imp of imports(context.state))
|
|
533
|
+
if (imp.alias == qualifier)
|
|
534
|
+
module = imp.module;
|
|
535
|
+
const members = modules[module];
|
|
536
|
+
if (members)
|
|
537
|
+
return { from, options: membersToCompletions(members), validFor: Identifier };
|
|
538
|
+
// `Json.` is the start of `Json.Decode` and `Json.Encode`.
|
|
539
|
+
const prefix = module + ".";
|
|
540
|
+
const submodules = Object.keys(modules)
|
|
541
|
+
.filter((name) => name.startsWith(prefix))
|
|
542
|
+
.map((name) => ({ label: name.slice(prefix.length), type: "namespace" }));
|
|
543
|
+
return submodules.length ? { from, options: submodules, validFor: Identifier } : null;
|
|
544
|
+
};
|
|
545
|
+
/// The names an import brings in without a prefix: those in its `exposing`
|
|
546
|
+
/// list, or every member for `exposing (..)`.
|
|
547
|
+
const importedCompletionSource = (context) => {
|
|
548
|
+
const inner = language.syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
549
|
+
if (dontComplete.includes(inner.name) || afterDot(context))
|
|
550
|
+
return null;
|
|
551
|
+
const word = context.matchBefore(/\w+/);
|
|
552
|
+
if (!word && !context.explicit)
|
|
553
|
+
return null;
|
|
554
|
+
const options = [];
|
|
555
|
+
for (const imp of imports(context.state)) {
|
|
556
|
+
if (defaultImports.includes(imp.module) && !imp.exposesAll && !imp.exposed.length)
|
|
557
|
+
continue;
|
|
558
|
+
const members = modules[imp.module];
|
|
559
|
+
if (imp.exposesAll && members)
|
|
560
|
+
options.push(...membersToCompletions(members));
|
|
561
|
+
for (const label of imp.exposed)
|
|
562
|
+
options.push({ label, type: /^[A-Z]/.test(label) ? "type" : "function" });
|
|
563
|
+
}
|
|
564
|
+
return options.length
|
|
565
|
+
? { from: word ? word.from : context.pos, options, validFor: Identifier }
|
|
566
|
+
: null;
|
|
567
|
+
};
|
|
568
|
+
// ── Fields ────────────────────────────────────────────────────────────────────
|
|
569
|
+
/// The field names written in the file, after a record and a dot, as in
|
|
570
|
+
/// `model.` or `.` at the start of an accessor function.
|
|
571
|
+
const fieldCompletionSource = (context) => {
|
|
572
|
+
const inner = language.syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
573
|
+
if (dontComplete.includes(inner.name))
|
|
574
|
+
return null;
|
|
575
|
+
const match = context.matchBefore(/(^|[^\w.]|[a-z_]\w*|[)}])\.\w*/);
|
|
576
|
+
if (!match || /^[A-Z]/.test(match.text))
|
|
577
|
+
return null;
|
|
578
|
+
const from = match.from + match.text.lastIndexOf(".") + 1;
|
|
579
|
+
const doc = context.state.doc;
|
|
580
|
+
const seen = new Set();
|
|
581
|
+
const options = [];
|
|
582
|
+
language.syntaxTree(context.state).iterate({
|
|
583
|
+
enter(node) {
|
|
584
|
+
if (node.name != "FieldName")
|
|
585
|
+
return;
|
|
586
|
+
const label = doc.sliceString(node.from, node.to);
|
|
587
|
+
if (!label || seen.has(label) || node.to == context.pos)
|
|
588
|
+
return;
|
|
589
|
+
seen.add(label);
|
|
590
|
+
options.push({ label, type: "property" });
|
|
591
|
+
},
|
|
592
|
+
});
|
|
593
|
+
return options.length ? { from, options, validFor: Identifier } : null;
|
|
594
|
+
};
|
|
595
|
+
// ── Names declared in the file ────────────────────────────────────────────────
|
|
596
|
+
// Every node here opens a scope: the names it binds are visible inside it and
|
|
597
|
+
// nowhere else. The declarations of a `let` can see each other, so the whole
|
|
598
|
+
// `LetExpression` is one scope.
|
|
599
|
+
const ScopeNodes = new Set([
|
|
600
|
+
"Program",
|
|
601
|
+
"ValueDeclaration",
|
|
602
|
+
"LetExpression",
|
|
603
|
+
"CaseBranch",
|
|
604
|
+
"LambdaExpression",
|
|
605
|
+
]);
|
|
606
|
+
function patternVariables(node, def) {
|
|
607
|
+
if (node.name == "PatternVariable")
|
|
608
|
+
def(node, "variable");
|
|
609
|
+
else
|
|
610
|
+
for (let ch = node.firstChild; ch; ch = ch.nextSibling)
|
|
611
|
+
patternVariables(ch, def);
|
|
612
|
+
}
|
|
613
|
+
// What a declaration adds to the scope around it. Returning true stops the walk
|
|
614
|
+
// going inside it.
|
|
615
|
+
const gatherers = {
|
|
616
|
+
ValueDeclaration(node, def) {
|
|
617
|
+
var _a;
|
|
618
|
+
const name = node.getChild("DeclName");
|
|
619
|
+
const hasParams = ((_a = name === null || name === void 0 ? void 0 : name.nextSibling) === null || _a === void 0 ? void 0 : _a.name) != "=";
|
|
620
|
+
if (name)
|
|
621
|
+
def(name, hasParams ? "function" : "variable");
|
|
622
|
+
return true;
|
|
623
|
+
},
|
|
624
|
+
TypeAnnotation(node, def) {
|
|
625
|
+
var _a;
|
|
626
|
+
const name = node.getChild("DeclName");
|
|
627
|
+
const isFunction = !!((_a = node.getChild("Type")) === null || _a === void 0 ? void 0 : _a.getChild("->"));
|
|
628
|
+
if (name)
|
|
629
|
+
def(name, isFunction ? "function" : "variable");
|
|
630
|
+
return true;
|
|
631
|
+
},
|
|
632
|
+
PortDeclaration(node, def) {
|
|
633
|
+
const name = node.getChild("DeclName");
|
|
634
|
+
if (name)
|
|
635
|
+
def(name, "function");
|
|
636
|
+
return true;
|
|
637
|
+
},
|
|
638
|
+
DestructuringDeclaration(node, def) {
|
|
639
|
+
if (node.firstChild)
|
|
640
|
+
patternVariables(node.firstChild, def);
|
|
641
|
+
return true;
|
|
642
|
+
},
|
|
643
|
+
TypeDeclaration(node, def) {
|
|
644
|
+
const name = node.getChild("TypeName");
|
|
645
|
+
if (name)
|
|
646
|
+
def(name, "type");
|
|
647
|
+
for (const con of node.getChildren("ConstructorDefinition")) {
|
|
648
|
+
const conName = con.getChild("ConstructorName");
|
|
649
|
+
if (conName)
|
|
650
|
+
def(conName, "enum");
|
|
651
|
+
}
|
|
652
|
+
return true;
|
|
653
|
+
},
|
|
654
|
+
TypeAliasDeclaration(node, def) {
|
|
655
|
+
const name = node.getChild("TypeName");
|
|
656
|
+
if (name)
|
|
657
|
+
def(name, "type");
|
|
658
|
+
return true;
|
|
659
|
+
},
|
|
660
|
+
ModuleDeclaration() {
|
|
661
|
+
return true;
|
|
662
|
+
},
|
|
663
|
+
ImportDeclaration(node, def) {
|
|
664
|
+
const alias = node.getChild("ModuleAlias");
|
|
665
|
+
if (alias)
|
|
666
|
+
def(alias, "namespace");
|
|
667
|
+
return true;
|
|
668
|
+
},
|
|
669
|
+
};
|
|
670
|
+
// The names a scope node binds itself: a function's parameters, a lambda's
|
|
671
|
+
// arguments and the variables in a `case` pattern.
|
|
672
|
+
function ownBindings(node, def) {
|
|
673
|
+
switch (node.name) {
|
|
674
|
+
case "ValueDeclaration":
|
|
675
|
+
case "LambdaExpression":
|
|
676
|
+
case "CaseBranch":
|
|
677
|
+
for (let ch = node.firstChild; ch && ch.name != "=" && ch.name != "->"; ch = ch.nextSibling)
|
|
678
|
+
if (ch.name != "DeclName")
|
|
679
|
+
patternVariables(ch, def);
|
|
680
|
+
break;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
const cache = new common.NodeWeakMap();
|
|
684
|
+
function getScope(doc, node) {
|
|
685
|
+
const cached = cache.get(node);
|
|
686
|
+
if (cached)
|
|
687
|
+
return cached;
|
|
688
|
+
const completions = [];
|
|
689
|
+
const seen = new Set();
|
|
690
|
+
const def = (n, type) => {
|
|
691
|
+
const label = doc.sliceString(n.from, n.to);
|
|
692
|
+
if (!label || seen.has(label))
|
|
693
|
+
return;
|
|
694
|
+
seen.add(label);
|
|
695
|
+
completions.push({ label, type });
|
|
696
|
+
};
|
|
697
|
+
ownBindings(node, def);
|
|
698
|
+
const walk = (parent) => {
|
|
699
|
+
for (let ch = parent.firstChild; ch; ch = ch.nextSibling) {
|
|
700
|
+
const gather = gatherers[ch.name];
|
|
701
|
+
if (gather && gather(ch, def))
|
|
702
|
+
continue;
|
|
703
|
+
if (!ScopeNodes.has(ch.name))
|
|
704
|
+
walk(ch);
|
|
705
|
+
}
|
|
706
|
+
};
|
|
707
|
+
walk(node);
|
|
708
|
+
cache.set(node, completions);
|
|
709
|
+
return completions;
|
|
710
|
+
}
|
|
711
|
+
/// Completes the names declared in the file that are in scope at the cursor:
|
|
712
|
+
/// top-level functions, types and constructors, parameters, and the names bound
|
|
713
|
+
/// by `let`, `case` and lambdas.
|
|
714
|
+
const localCompletionSource = (context) => {
|
|
715
|
+
const inner = language.syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
716
|
+
if (dontComplete.includes(inner.name) || afterDot(context))
|
|
717
|
+
return null;
|
|
718
|
+
const word = context.matchBefore(/\w+/);
|
|
719
|
+
if (!word && !context.explicit)
|
|
720
|
+
return null;
|
|
721
|
+
let options = [];
|
|
722
|
+
for (let pos = inner; pos; pos = pos.parent)
|
|
723
|
+
if (ScopeNodes.has(pos.name))
|
|
724
|
+
options = options.concat(getScope(context.state.doc, pos));
|
|
725
|
+
// The name being typed is in the tree as a declaration of its own, and
|
|
726
|
+
// offering it back as its own completion helps nobody.
|
|
727
|
+
if (word)
|
|
728
|
+
options = options.filter((o) => o.label != word.text);
|
|
729
|
+
return { options, from: word ? word.from : context.pos, validFor: Identifier };
|
|
730
|
+
};
|
|
731
|
+
|
|
732
|
+
// Folding a declaration or block keeps its first line in view, which is the
|
|
733
|
+
// line that says what was folded away.
|
|
734
|
+
function foldBody(node, state) {
|
|
735
|
+
const line = state.doc.lineAt(node.from);
|
|
736
|
+
return node.to > line.to ? { from: line.to, to: node.to } : null;
|
|
737
|
+
}
|
|
738
|
+
// The tree can't say where a new line belongs, because a block ends at its last
|
|
739
|
+
// token and the new line is past that. So the line above decides. A line that
|
|
740
|
+
// ends by opening something is followed by one indented under it, as
|
|
741
|
+
// elm-format lays it out, and any other line is followed by one at its own
|
|
742
|
+
// indentation.
|
|
743
|
+
const opensBlock = /(=|->|\bof|\blet|\bthen|\belse|\bin|\(|\[|\{|,|\|>|<\||\+\+|&&|\|\|)$/;
|
|
744
|
+
const startsDeclaration = /^\s*(in|else)\b/;
|
|
745
|
+
const indentElm = language.indentService.of((context, pos) => {
|
|
746
|
+
const inside = language.syntaxTree(context.state).resolveInner(pos, -1).name;
|
|
747
|
+
if (inside == "BlockComment" || inside == "DocComment" || inside == "String")
|
|
748
|
+
return null;
|
|
749
|
+
let line = context.lineAt(pos, -1);
|
|
750
|
+
while (!/\S/.test(line.text) && line.from > 0)
|
|
751
|
+
line = context.lineAt(line.from - 1, -1);
|
|
752
|
+
if (!/\S/.test(line.text))
|
|
753
|
+
return 0;
|
|
754
|
+
const code = line.text.replace(/\s*--.*$/, "").trimEnd();
|
|
755
|
+
const base = context.lineIndent(line.from);
|
|
756
|
+
if (startsDeclaration.test(context.state.doc.sliceString(pos, pos + 10)))
|
|
757
|
+
return Math.max(0, base - context.unit);
|
|
758
|
+
if (/\bin$/.test(code))
|
|
759
|
+
return base;
|
|
760
|
+
if (opensBlock.test(code))
|
|
761
|
+
return base + context.unit;
|
|
762
|
+
return base;
|
|
763
|
+
});
|
|
764
|
+
const elmLanguage = language.LRLanguage.define({
|
|
765
|
+
name: "elm",
|
|
766
|
+
parser: parser.configure({
|
|
767
|
+
props: [
|
|
768
|
+
language.foldNodeProp.add({
|
|
769
|
+
"ValueDeclaration TypeDeclaration TypeAliasDeclaration": foldBody,
|
|
770
|
+
"LetExpression CaseExpression CaseBranch": foldBody,
|
|
771
|
+
"ListExpression RecordExpression RecordUpdateExpression RecordType": foldBody,
|
|
772
|
+
"BlockComment DocComment": foldBody,
|
|
773
|
+
}),
|
|
774
|
+
highlight.styleTags({
|
|
775
|
+
"module import exposing port effect where": highlight.tags.moduleKeyword,
|
|
776
|
+
"type alias as infix": highlight.tags.definitionKeyword,
|
|
777
|
+
"let in": highlight.tags.definitionKeyword,
|
|
778
|
+
"if then else case of": highlight.tags.controlKeyword,
|
|
779
|
+
Number: highlight.tags.number,
|
|
780
|
+
String: highlight.tags.string,
|
|
781
|
+
Char: highlight.tags.character,
|
|
782
|
+
Wildcard: highlight.tags.atom,
|
|
783
|
+
LineComment: highlight.tags.lineComment,
|
|
784
|
+
BlockComment: highlight.tags.blockComment,
|
|
785
|
+
DocComment: highlight.tags.docComment,
|
|
786
|
+
Qualifier: highlight.tags.namespace,
|
|
787
|
+
"ModuleName ModuleAlias": highlight.tags.namespace,
|
|
788
|
+
"DeclName": highlight.tags.definition(highlight.tags.variableName),
|
|
789
|
+
"ValueDeclaration/DeclName TypeAnnotation/DeclName PortDeclaration/DeclName": highlight.tags.definition(highlight.tags.function(highlight.tags.variableName)),
|
|
790
|
+
PatternVariable: highlight.tags.definition(highlight.tags.variableName),
|
|
791
|
+
"Callee/Variable": highlight.tags.function(highlight.tags.variableName),
|
|
792
|
+
Variable: highlight.tags.variableName,
|
|
793
|
+
"ExposedValue": highlight.tags.variableName,
|
|
794
|
+
"Constructor ConstructorName": highlight.tags.className,
|
|
795
|
+
"TypeName ExposedType": highlight.tags.definition(highlight.tags.typeName),
|
|
796
|
+
TypeConstructor: highlight.tags.typeName,
|
|
797
|
+
"TypeVariable TypeParameter": highlight.tags.typeName,
|
|
798
|
+
"FieldName RecordBase": highlight.tags.propertyName,
|
|
799
|
+
AccessorFunction: highlight.tags.propertyName,
|
|
800
|
+
Operator: highlight.tags.operator,
|
|
801
|
+
"- ::": highlight.tags.operator,
|
|
802
|
+
"= ->": highlight.tags.definitionOperator,
|
|
803
|
+
":": highlight.tags.typeOperator,
|
|
804
|
+
'| .. "\\\\"': highlight.tags.operator,
|
|
805
|
+
", accessDot": highlight.tags.separator,
|
|
806
|
+
"( )": highlight.tags.paren,
|
|
807
|
+
"[ ]": highlight.tags.squareBracket,
|
|
808
|
+
"{ }": highlight.tags.brace,
|
|
809
|
+
}),
|
|
810
|
+
],
|
|
811
|
+
}),
|
|
812
|
+
languageData: {
|
|
813
|
+
commentTokens: { line: "--", block: { open: "{-", close: "-}" } },
|
|
814
|
+
closeBrackets: { brackets: ["(", "[", "{", '"'] },
|
|
815
|
+
indentOnInput: /^\s*(in|else)$/,
|
|
816
|
+
},
|
|
817
|
+
});
|
|
818
|
+
/// Elm language support, with completion for keywords, snippets, the core
|
|
819
|
+
/// modules and the names declared in the file.
|
|
820
|
+
function elm() {
|
|
821
|
+
return new language.LanguageSupport(elmLanguage, [
|
|
822
|
+
indentElm,
|
|
823
|
+
elmLanguage.data.of({ autocomplete: elmCompletion }),
|
|
824
|
+
elmLanguage.data.of({ autocomplete: moduleCompletionSource }),
|
|
825
|
+
elmLanguage.data.of({ autocomplete: importedCompletionSource }),
|
|
826
|
+
elmLanguage.data.of({ autocomplete: fieldCompletionSource }),
|
|
827
|
+
elmLanguage.data.of({ autocomplete: localCompletionSource }),
|
|
828
|
+
]);
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
exports.elm = elm;
|
|
832
|
+
exports.elmCompletion = elmCompletion;
|
|
833
|
+
exports.elmLanguage = elmLanguage;
|
|
834
|
+
exports.fieldCompletionSource = fieldCompletionSource;
|
|
835
|
+
exports.importedCompletionSource = importedCompletionSource;
|
|
836
|
+
exports.localCompletionSource = localCompletionSource;
|
|
837
|
+
exports.moduleCompletionSource = moduleCompletionSource;
|
|
838
|
+
exports.parser = parser;
|
|
839
|
+
exports.snippets = snippets;
|