@exercism/codemirror-lang-r 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/dist/index.js ADDED
@@ -0,0 +1,588 @@
1
+ import { ContextTracker, ExternalTokenizer, LRParser } from '@lezer/lr';
2
+ import { syntaxTree, LRLanguage, indentNodeProp, continuedIndent, delimitedIndent, foldNodeProp, foldInside, LanguageSupport } from '@codemirror/language';
3
+ import { styleTags, tags } from '@lezer/highlight';
4
+ import { snippetCompletion, ifNotIn, completeFromList } from '@codemirror/autocomplete';
5
+ import { NodeWeakMap } from '@lezer/common';
6
+
7
+ // This file was generated by lezer-generator. You probably shouldn't edit it.
8
+ const insertSemi = 126,
9
+ DoubleStart = 1,
10
+ DoubleContent = 2,
11
+ DoubleEnd = 3,
12
+ SingleStart = 4,
13
+ SingleContent = 5,
14
+ SingleEnd = 6,
15
+ Escape = 7,
16
+ RawString = 8,
17
+ space = 128,
18
+ newline = 129,
19
+ LineComment = 9,
20
+ DocComment = 10;
21
+
22
+ // ── Line breaks ───────────────────────────────────────────────────────────────
23
+ // Whether a line break stands between the last token that meant anything and
24
+ // the cursor. Whitespace and comments carry the answer forward, because a
25
+ // comment on its own line must not hide the break that follows it; everything
26
+ // else replaces it.
27
+ const trackNewline = /*@__PURE__*/new ContextTracker({
28
+ start: false,
29
+ shift(context, term) {
30
+ return term == LineComment || term == DocComment || term == space
31
+ ? context
32
+ : term == newline;
33
+ },
34
+ strict: false
35
+ });
36
+ function isSpace(ch) {
37
+ return (ch == 32 /* Ch.Space */ || ch == 9 /* Ch.Tab */ || ch == 10 /* Ch.Newline */ || ch == 13 /* Ch.Return */ ||
38
+ ch == 11 /* Ch.VTab */ || ch == 12 /* Ch.FormFeed */ || ch == 160 || ch == 0xfeff);
39
+ }
40
+ function isLetter(ch) {
41
+ return (ch >= 97 /* Ch.LowerA */ && ch <= 122 /* Ch.LowerZ */) || (ch >= 65 /* Ch.UpperA */ && ch <= 90 /* Ch.UpperZ */);
42
+ }
43
+ function isNameChar(ch) {
44
+ return (isLetter(ch) ||
45
+ (ch >= 48 /* Ch.Digit0 */ && ch <= 57 /* Ch.Digit9 */) ||
46
+ ch == 95 /* Ch.Underscore */ ||
47
+ ch == 46 ||
48
+ ch >= 161 /* Ch.NonAscii */);
49
+ }
50
+ // The one word in R a line break may stand in front of.
51
+ //
52
+ // if (n > 0)
53
+ // "some"
54
+ // else
55
+ // "none"
56
+ //
57
+ // R itself refuses this at the top of a file and accepts it inside braces,
58
+ // where the rest of the expression is still to come. The distinction is not
59
+ // worth keeping: a highlighter that reads the second `if` of a chain as a
60
+ // statement of its own colours the same words the same way and then loses the
61
+ // tree that folding and indentation are read from.
62
+ function continuesLine(input) {
63
+ if (input.next != 101 /* Ch.LowerE */)
64
+ return false;
65
+ const word = [101 /* Ch.LowerE */, 108 /* Ch.LowerL */, 115 /* Ch.LowerS */, 101 /* Ch.LowerE */];
66
+ for (let i = 0; i < word.length; i++)
67
+ if (input.peek(i) != word[i])
68
+ return false;
69
+ return !isNameChar(input.peek(word.length));
70
+ }
71
+ // The line break that finished an expression, as a token of no width.
72
+ //
73
+ // R's own parser is handed every line break and decides what to do with it by
74
+ // the state it is in, and `canShift` is the same question asked from the other
75
+ // side: it is true exactly where an expression may end, which is nowhere inside
76
+ // a bracket and nowhere after an operator that is still waiting for its right
77
+ // hand side. That is the whole rule. R never continues an expression that could
78
+ // have stood on its own, which is why `x <- 1` and a following line holding
79
+ // `-2` are two expressions rather than a subtraction.
80
+ const insertSemicolon = /*@__PURE__*/new ExternalTokenizer((input, stack) => {
81
+ const next = input.next;
82
+ // Whitespace and comments are skipped by the grammar. Both carry the line
83
+ // break forward, so the decision is only postponed to the token they precede.
84
+ if (isSpace(next) || next == 35 /* Ch.Hash */)
85
+ return;
86
+ if (!stack.canShift(insertSemi))
87
+ return;
88
+ // A brace closes whatever the last expression in it was, and so does the end
89
+ // of the file, whether or not a line break came first.
90
+ if (next == 125 /* Ch.BraceR */ || next == -1 /* Ch.EOF */)
91
+ return input.acceptToken(insertSemi);
92
+ if (!stack.context)
93
+ return;
94
+ if (continuesLine(input))
95
+ return;
96
+ input.acceptToken(insertSemi);
97
+ }, { contextual: true });
98
+ // ── Strings ───────────────────────────────────────────────────────────────────
99
+ // A string is handed over in pieces so that the escapes inside it can be
100
+ // coloured apart from the text around them. The two quote characters have a set
101
+ // of tokens each, which is what tells the tokenizer which quote it is looking
102
+ // for: asking the parser whether it could shift the content of a double quoted
103
+ // string answers it without any state being kept here.
104
+ //
105
+ // R's strings may hold a line break, and plenty of the messages in its own
106
+ // standard library do.
107
+ const strings = /*@__PURE__*/new ExternalTokenizer((input, stack) => {
108
+ if (stack.canShift(DoubleContent))
109
+ return readQuoted(input, 34 /* Ch.Quote */, DoubleContent, DoubleEnd);
110
+ if (stack.canShift(SingleContent))
111
+ return readQuoted(input, 39 /* Ch.Apostrophe */, SingleContent, SingleEnd);
112
+ if (input.next == 114 /* Ch.LowerR */ || input.next == 82 /* Ch.UpperR */)
113
+ return readRaw(input);
114
+ if (input.next == 34 /* Ch.Quote */) {
115
+ input.advance();
116
+ return input.acceptToken(DoubleStart);
117
+ }
118
+ if (input.next == 39 /* Ch.Apostrophe */) {
119
+ input.advance();
120
+ return input.acceptToken(SingleStart);
121
+ }
122
+ });
123
+ function readQuoted(input, quote, content, end) {
124
+ if (input.next == quote) {
125
+ input.advance();
126
+ return input.acceptToken(end);
127
+ }
128
+ if (input.next == 92 /* Ch.Backslash */)
129
+ return readEscape(input);
130
+ let length = 0;
131
+ for (;;) {
132
+ const ch = input.peek(length);
133
+ if (ch == -1 /* Ch.EOF */ || ch == quote || ch == 92 /* Ch.Backslash */)
134
+ break;
135
+ length++;
136
+ }
137
+ if (!length)
138
+ return;
139
+ input.advance(length);
140
+ input.acceptToken(content);
141
+ }
142
+ /**
143
+ The escapes R's parser accepts, which are C's with two spellings of a code
144
+ point added: `é`, `\u{e9}` and their eight digit twins.
145
+ */
146
+ function readEscape(input) {
147
+ let length = 1;
148
+ const marker = input.peek(1);
149
+ if (marker == 120 /* Ch.LowerX */) {
150
+ length = 2;
151
+ while (length < 4 && isHex(input.peek(length)))
152
+ length++;
153
+ }
154
+ else if (marker == 117 /* Ch.LowerU */ || marker == 85 /* Ch.UpperU */) {
155
+ const limit = marker == 117 /* Ch.LowerU */ ? 4 : 8;
156
+ length = 2;
157
+ if (input.peek(2) == 123 /* Ch.BraceL */) {
158
+ length = 3;
159
+ while (isHex(input.peek(length)))
160
+ length++;
161
+ if (input.peek(length) == 125 /* Ch.BraceR */)
162
+ length++;
163
+ }
164
+ else {
165
+ while (length < 2 + limit && isHex(input.peek(length)))
166
+ length++;
167
+ }
168
+ }
169
+ else if (marker >= 48 /* Ch.Digit0 */ && marker <= 55 /* Ch.Digit7 */) {
170
+ length = 2;
171
+ while (length < 4 && input.peek(length) >= 48 /* Ch.Digit0 */ && input.peek(length) <= 55 /* Ch.Digit7 */)
172
+ length++;
173
+ }
174
+ else if (marker == -1 /* Ch.EOF */) {
175
+ return;
176
+ }
177
+ else {
178
+ length = 2;
179
+ }
180
+ input.advance(length);
181
+ input.acceptToken(Escape);
182
+ }
183
+ function isHex(ch) {
184
+ return ((ch >= 48 /* Ch.Digit0 */ && ch <= 57 /* Ch.Digit9 */) ||
185
+ (ch >= 97 /* Ch.LowerA */ && ch <= 97 /* Ch.LowerA */ + 5) ||
186
+ (ch >= 65 /* Ch.UpperA */ && ch <= 65 /* Ch.UpperA */ + 5));
187
+ }
188
+ /**
189
+ The bracket that closes the one a raw string opened with.
190
+ */
191
+ function closingBracket(ch) {
192
+ return ch == 40 /* Ch.ParenL */ ? 41 /* Ch.ParenR */ : ch == 91 /* Ch.BracketL */ ? 93 /* Ch.BracketR */ : ch == 123 /* Ch.BraceL */ ? 125 /* Ch.BraceR */ : 0;
193
+ }
194
+ // `r"(...)"` holds whatever is between its brackets, backslashes included,
195
+ // which is what makes it the way a regular expression is written in R since
196
+ // 4.0. The dashes are there for text that holds the closing bracket itself:
197
+ // `r"---(a)"b)---"` ends at the three dashes it opened with and nowhere else,
198
+ // so the opener has to be counted and matched.
199
+ function readRaw(input) {
200
+ const quote = input.peek(1);
201
+ if (quote != 34 /* Ch.Quote */ && quote != 39 /* Ch.Apostrophe */)
202
+ return;
203
+ let dashes = 0;
204
+ while (input.peek(2 + dashes) == 45 /* Ch.Dash */)
205
+ dashes++;
206
+ const open = input.peek(2 + dashes);
207
+ const close = closingBracket(open);
208
+ if (!close)
209
+ return;
210
+ let length = 3 + dashes;
211
+ for (;;) {
212
+ const ch = input.peek(length);
213
+ if (ch == -1 /* Ch.EOF */)
214
+ break;
215
+ if (ch == close) {
216
+ let after = length + 1, seen = 0;
217
+ while (seen < dashes && input.peek(after) == 45 /* Ch.Dash */) {
218
+ after++;
219
+ seen++;
220
+ }
221
+ if (seen == dashes && input.peek(after) == quote) {
222
+ length = after + 1;
223
+ break;
224
+ }
225
+ }
226
+ length++;
227
+ }
228
+ input.advance(length);
229
+ input.acceptToken(RawString);
230
+ }
231
+
232
+ // This file was generated by lezer-generator. You probably shouldn't edit it.
233
+ const spec_Identifier = {__proto__:null,"...":266, TRUE:268, FALSE:270, NULL:272, NA:274, NA_integer_:276, NA_real_:278, NA_character_:280, NA_complex_:282, Inf:284, NaN:286, function:64, if:84, else:86, for:90, in:92, while:96, repeat:100, break:104, next:108};
234
+ const parser = /*@__PURE__*/LRParser.deserialize({
235
+ version: 14,
236
+ states: "6nQ#rQUOOO#yQUO'#CpO$UQUO'#CpO$aQUO'#CwO$hQUO'#CzOOQO'#C}'#C}O&wQSO'#C{O(sQTO'#FTO+dQTO'#DpO+tQSO'#DoOOQQ'#Dz'#DzOOQQ'#D}'#D}OOQQ'#EP'#EPO$hQUO'#DyO$hQUO'#DyO$hQUO'#DyOOQQ'#Ek'#EkO$hQUO'#EjO+|QSO'#ElOOQP'#FU'#FUOOQP'#FT'#FTO,[QTO'#FSOOQQ'#FS'#FSOOQQ'#Ex'#Ex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!a!b!c!d!e!f!g!h!i!k!t!v!z!|#w#|#}$U$V$W$h$i_!iV#^#s#u$X$]$ejbORShir{!O!v$U$W$h$i!Q!o]^_a!P!R!S!`!a!b!c!d!e!f!g!h!i!t!z!|#w#|#}$VR#o!kT!tb!og!kV!r#^#m#n#q#s#u$X$]$ekdORShir{!O!v$U$W$h$iR!vbShOiQ{RT!yh{QvPR#OvQyQR#QyQ#y#WR$Z#yQ$O#_Q$Q#`Q$S#aV$_$O$Q$SZgORhi{YeORhi{Q|SQ!}rQ#X!OQ#r!vQ$d$UQ$f$WQ$j$hR$k$ijVORShir{!O!v$U$W$h$iQ!n]Q!p^Q!q_Q!raW#^!P!R!S#}Q#d!`Q#e!aQ#f!bQ#g!cQ#h!dQ#i!eQ#j!fQ#k!gQ#l!hQ#m!iQ#n!kQ#q!tQ#s!zQ#u!|Q$X#wQ$]#|R$e$VQ#_!PQ#`!RQ#a!SR$^#}R!xe",
239
+ nodeNames: "⚠ DoubleStart DoubleContent DoubleEnd SingleStart SingleContent SingleEnd Escape RawString LineComment DocComment Program Shebang Identifier Dots BacktickName Placeholder Number Integer Complex String Boolean Null NA Special } { Block ) ( ParenExpression FunctionDefinition function Lambda \\ ParamList Param ParamName DefaultOp = , IfExpression if else ForExpression for in WhileExpression while RepeatExpression repeat BreakExpression break NextExpression next CallExpression ArgList NamedArg ArgName ArgOp ] SubsetExpression [ Subset2Expression [[ NamespaceExpression PackageName NamespaceOp :: ::: DollarExpression DollarOp $ @ PropertyName UnaryExpression ArithOp + - LogicOp ! FormulaOp ~ BinaryExpression ArithOp ^ ** RangeOp : PipeBindOp => SpecialOp PipeOp |> ArithOp * / ArithOp CompareOp LogicOp & && LogicOp | || FormulaOp HelpExpression HelpOp Assignment AssignTarget LeftAssignOp <- <<- := RightAssignOp -> ->> Assignment EqAssignOp ;",
240
+ maxTerm: 146,
241
+ context: trackNewline,
242
+ nodeProps: [
243
+ ["isolate", 9,""],
244
+ ["openedBy", 25,"{",28,"("],
245
+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~8lP;=`<%l7R~8tOj~~8yQ#Z~!`!a9P#p#q9U~9UO#P~~9ZO#[~~9`Oi~~9eO!t~",
250
+ tokenizers: [insertSemicolon, strings, 0],
251
+ topRules: {"Program":[0,11]},
252
+ specialized: [{term: 13, get: (value) => spec_Identifier[value] || -1}],
253
+ tokenPrec: 2192
254
+ });
255
+
256
+ /**
257
+ Snippets for the constructs people write most often in R.
258
+ */
259
+ const snippets = [
260
+ /*@__PURE__*/snippetCompletion("${name} <- function(${params}) {\n\t${}\n}", {
261
+ label: "function",
262
+ detail: "definition",
263
+ type: "keyword"
264
+ }),
265
+ /*@__PURE__*/snippetCompletion("\\(${x}) ${}", {
266
+ label: "\\",
267
+ detail: "lambda",
268
+ type: "keyword"
269
+ }),
270
+ /*@__PURE__*/snippetCompletion("if (${condition}) {\n\t${}\n}", {
271
+ label: "if",
272
+ detail: "block",
273
+ type: "keyword"
274
+ }),
275
+ /*@__PURE__*/snippetCompletion("if (${condition}) {\n\t${}\n} else {\n\t\n}", {
276
+ label: "if",
277
+ detail: "/ else block",
278
+ type: "keyword"
279
+ }),
280
+ /*@__PURE__*/snippetCompletion("for (${i} in ${seq_along(x)}) {\n\t${}\n}", {
281
+ label: "for",
282
+ detail: "loop",
283
+ type: "keyword"
284
+ }),
285
+ /*@__PURE__*/snippetCompletion("while (${condition}) {\n\t${}\n}", {
286
+ label: "while",
287
+ detail: "loop",
288
+ type: "keyword"
289
+ }),
290
+ /*@__PURE__*/snippetCompletion("repeat {\n\t${}\n\tif (${condition}) break\n}", {
291
+ label: "repeat",
292
+ detail: "loop",
293
+ type: "keyword"
294
+ }),
295
+ /*@__PURE__*/snippetCompletion("switch(${x},\n\t${name} = ${value},\n\t${default}\n)", {
296
+ label: "switch",
297
+ detail: "by value",
298
+ type: "keyword"
299
+ }),
300
+ /*@__PURE__*/snippetCompletion("tryCatch({\n\t${}\n}, error = function(e) {\n\t\n})", {
301
+ label: "tryCatch",
302
+ detail: "handle errors",
303
+ type: "keyword"
304
+ })
305
+ ];
306
+ // R scopes names by function. A name assigned anywhere in a function body,
307
+ // inside an `if` or a loop as well, can be read anywhere in that body. A name
308
+ // assigned at the top of the file can be read everywhere.
309
+ const ScopeNodes = /*@__PURE__*/new Set(["Program", "FunctionDefinition"]);
310
+ const nameNodes = /*@__PURE__*/new Set(["Identifier", "BacktickName", "Dots"]);
311
+ // The name an assignment gives a value is the whole of its target. A target
312
+ // such as `names(x)`, `x[1]` or `x$a` changes a value that already has a name,
313
+ // so it declares nothing.
314
+ function assignedName(assignment) {
315
+ const target = assignment.getChild("AssignTarget");
316
+ const name = target === null || target === void 0 ? void 0 : target.firstChild;
317
+ if (!name || name.nextSibling)
318
+ return null;
319
+ return nameNodes.has(name.name) || name.name == "String" ? name : null;
320
+ }
321
+ function isSuperAssign(assignment, doc) {
322
+ const op = assignment.getChild("LeftAssignOp");
323
+ return op ? doc.sliceString(op.from, op.to) == "<<-" : false;
324
+ }
325
+ function isFunctionValue(assignment) {
326
+ const target = assignment.getChild("AssignTarget");
327
+ for (let ch = assignment.firstChild; ch; ch = ch.nextSibling)
328
+ if (ch != target && ch.name == "FunctionDefinition")
329
+ return true;
330
+ return false;
331
+ }
332
+ function walk(node, doc, def, mode) {
333
+ for (let ch = node.firstChild; ch; ch = ch.nextSibling) {
334
+ if (ch.name == "ParamList")
335
+ continue;
336
+ if (ch.name == "Assignment") {
337
+ const name = assignedName(ch);
338
+ const counts = isSuperAssign(ch, doc) ? mode != "function" : mode != "super";
339
+ if (name && counts)
340
+ def(name, isFunctionValue(ch) ? "function" : "variable");
341
+ }
342
+ else if (ch.name == "ForExpression" && mode != "super") {
343
+ const variable = ch.getChild("Identifier") || ch.getChild("BacktickName");
344
+ if (variable)
345
+ def(variable, "variable");
346
+ }
347
+ if (ch.name == "FunctionDefinition") {
348
+ if (mode != "function")
349
+ walk(ch, doc, def, "super");
350
+ }
351
+ else {
352
+ walk(ch, doc, def, mode);
353
+ }
354
+ }
355
+ }
356
+ function functionScope(node, doc, def) {
357
+ var _a;
358
+ const params = node.getChild("ParamList");
359
+ if (params)
360
+ for (const param of params.getChildren("Param")) {
361
+ const name = (_a = param.getChild("ParamName")) === null || _a === void 0 ? void 0 : _a.firstChild;
362
+ if (name)
363
+ def(name, "variable");
364
+ }
365
+ walk(node, doc, def, "function");
366
+ }
367
+ const cache = /*@__PURE__*/new NodeWeakMap();
368
+ function nameText(node, doc) {
369
+ const text = doc.sliceString(node.from, node.to);
370
+ return node.name == "String" ? text.slice(1, -1) : text;
371
+ }
372
+ function scopeNames(node, doc) {
373
+ const cached = cache.get(node);
374
+ if (cached)
375
+ return cached;
376
+ const options = [];
377
+ const seen = new Set();
378
+ const def = (name, type) => {
379
+ const label = nameText(name, doc);
380
+ if (!label || seen.has(label))
381
+ return;
382
+ seen.add(label);
383
+ options.push({ label, type });
384
+ };
385
+ if (node.name == "Program") {
386
+ walk(node, doc, def, "file");
387
+ }
388
+ else {
389
+ functionScope(node, doc, def);
390
+ }
391
+ cache.set(node, options);
392
+ return options;
393
+ }
394
+ // Completion makes no sense inside these, so neither source offers anything
395
+ // there.
396
+ const dontComplete = ["String", "RawString", "LineComment", "DocComment"];
397
+ // After `df$`, `obj@` or `pkg::` the name belongs to a column, a slot or a
398
+ // package, which this file cannot know. This reads the text, because the tree
399
+ // of a half typed `pkg::na` is not always a namespace yet.
400
+ const afterAccessor = /(::|\$|@)[\p{L}\w.]*$/u;
401
+ /**
402
+ Wraps a completion source so that it offers nothing inside strings,
403
+ comments, or after `$`, `@` and `::`.
404
+ */
405
+ function outsideLiterals(source) {
406
+ const inner = ifNotIn(dontComplete, source);
407
+ return context => (context.matchBefore(afterAccessor) ? null : inner(context));
408
+ }
409
+ const identifier = /^[\p{L}\w.]*$/u;
410
+ /**
411
+ Completes the names assigned in the file and the parameters of the
412
+ functions around the cursor.
413
+ */
414
+ const localCompletionSource = /*@__PURE__*/outsideLiterals((context) => {
415
+ const word = context.matchBefore(/[\p{L}\w.]+$/u);
416
+ if (!word && !context.explicit)
417
+ return null;
418
+ const inner = syntaxTree(context.state).resolveInner(context.pos, -1);
419
+ const options = [];
420
+ const seen = new Set();
421
+ for (let pos = inner; pos; pos = pos.parent) {
422
+ if (!ScopeNodes.has(pos.name))
423
+ continue;
424
+ for (const option of scopeNames(pos, context.state.doc)) {
425
+ if (seen.has(option.label))
426
+ continue;
427
+ seen.add(option.label);
428
+ options.push(option);
429
+ }
430
+ }
431
+ return {
432
+ from: word ? word.from : context.pos,
433
+ options,
434
+ validFor: identifier
435
+ };
436
+ });
437
+
438
+ const bracketed = "ArgList ParamList ParenExpression";
439
+ const subscripted = "SubsetExpression Subset2Expression";
440
+ const rLanguage = /*@__PURE__*/LRLanguage.define({
441
+ name: "r",
442
+ parser: /*@__PURE__*/parser.configure({
443
+ props: [
444
+ /*@__PURE__*/indentNodeProp.add({
445
+ Block: /*@__PURE__*/delimitedIndent({ closing: "}" }),
446
+ [bracketed]: /*@__PURE__*/delimitedIndent({ closing: ")" }),
447
+ [subscripted]: /*@__PURE__*/delimitedIndent({ closing: "]" }),
448
+ // A body written without braces is one line of its own, and the line
449
+ // after it belongs to whatever held the body rather than to the body.
450
+ "IfExpression ForExpression WhileExpression RepeatExpression": /*@__PURE__*/continuedIndent({ except: /^\s*(else\b|\})/ }),
451
+ FunctionDefinition: /*@__PURE__*/continuedIndent({ except: /^\s*\}/ })
452
+ }),
453
+ /*@__PURE__*/foldNodeProp.add({
454
+ Block: foldInside,
455
+ [bracketed]: foldInside,
456
+ [subscripted]: foldInside
457
+ }),
458
+ /*@__PURE__*/styleTags({
459
+ "if else for while repeat break next": tags.controlKeyword,
460
+ function: tags.definitionKeyword,
461
+ "Lambda/...": tags.definitionKeyword,
462
+ in: tags.operatorKeyword,
463
+ Boolean: tags.bool,
464
+ Null: tags.null,
465
+ "NA Special": tags.atom,
466
+ Number: tags.number,
467
+ Integer: tags.integer,
468
+ Complex: tags.number,
469
+ "String RawString": tags.string,
470
+ "DoubleStart DoubleContent DoubleEnd": tags.string,
471
+ "SingleStart SingleContent SingleEnd": tags.string,
472
+ Escape: tags.escape,
473
+ Shebang: tags.processingInstruction,
474
+ LineComment: tags.lineComment,
475
+ DocComment: tags.docComment,
476
+ Dots: /*@__PURE__*/tags.special(tags.variableName),
477
+ Placeholder: /*@__PURE__*/tags.special(tags.variableName),
478
+ // The name a function is given, which in R is the name a value is given
479
+ // and nothing else. `AssignTarget` is the one place a name is being
480
+ // written rather than read.
481
+ "AssignTarget/Identifier AssignTarget/BacktickName": /*@__PURE__*/tags.definition(tags.variableName),
482
+ "AssignTarget/String": /*@__PURE__*/tags.definition(tags.string),
483
+ "ParamName/Identifier": /*@__PURE__*/tags.definition(tags.variableName),
484
+ "ParamName/Dots": /*@__PURE__*/tags.definition(/*@__PURE__*/tags.special(tags.variableName)),
485
+ "CallExpression/Identifier CallExpression/BacktickName": /*@__PURE__*/tags.function(tags.variableName),
486
+ "CallExpression/NamespaceExpression/Identifier": /*@__PURE__*/tags.function(tags.variableName),
487
+ "CallExpression/DollarExpression/PropertyName/Identifier": /*@__PURE__*/tags.function(tags.propertyName),
488
+ "PackageName/Identifier PackageName/String": tags.namespace,
489
+ "PropertyName/Identifier PropertyName/BacktickName PropertyName/String": tags.propertyName,
490
+ "ArgName/Identifier ArgName/String ArgName/BacktickName": tags.labelName,
491
+ "Identifier BacktickName": tags.variableName,
492
+ // An operator node holds the characters it is made of as a child, and a
493
+ // tag on the parent is covered by an untagged child standing over the
494
+ // same text. The `/...` selector is the one that reaches through.
495
+ // `CompareOp` and `SpecialOp` are tokens and have nothing to reach.
496
+ "ArithOp/...": tags.arithmeticOperator,
497
+ "LogicOp/...": tags.logicOperator,
498
+ CompareOp: tags.compareOperator,
499
+ SpecialOp: tags.operator,
500
+ "PipeOp/... PipeBindOp/...": tags.controlOperator,
501
+ "FormulaOp/... RangeOp/...": tags.operator,
502
+ HelpOp: tags.operator,
503
+ "LeftAssignOp/... RightAssignOp/... EqAssignOp/...": tags.definitionOperator,
504
+ "ArgOp/... DefaultOp/...": tags.definitionOperator,
505
+ "DollarOp/... NamespaceOp/...": tags.derefOperator,
506
+ "( )": tags.paren,
507
+ "[ [[ ]": tags.squareBracket,
508
+ "{ }": tags.brace,
509
+ ", ;": tags.separator
510
+ })
511
+ ]
512
+ }),
513
+ languageData: {
514
+ commentTokens: { line: "#" },
515
+ closeBrackets: { brackets: ["(", "[", "{", "'", '"', "`"] },
516
+ indentOnInput: /^\s*[}\])]$/
517
+ }
518
+ });
519
+ const keywords = /*@__PURE__*/("if else for while repeat function break next in TRUE FALSE NULL NA Inf NaN " +
520
+ "NA_integer_ NA_real_ NA_character_ NA_complex_")
521
+ .split(" ")
522
+ .map(label => ({ label, type: "keyword" }));
523
+ // The corner of base R somebody reaches for without looking it up. Anything a
524
+ // package brings with it is left out: `library` proposes it and this list
525
+ // cannot know what was loaded.
526
+ const functions = /*@__PURE__*/[
527
+ "c", "vector", "list", "length", "names", "rev", "sort", "order", "unique",
528
+ "seq", "seq_len", "seq_along", "rep", "head", "tail", "which", "which.max",
529
+ "which.min", "match", "setdiff", "union", "intersect", "any", "all", "is.na",
530
+ "is.null", "is.numeric", "is.character", "is.logical", "is.function",
531
+ "as.numeric", "as.integer", "as.character", "as.logical", "as.factor",
532
+ "factor", "levels", "nchar", "substr", "substring", "strsplit", "paste",
533
+ "paste0", "sprintf", "format", "formatC", "trimws", "toupper", "tolower",
534
+ "gsub", "sub", "grepl", "grep", "regmatches", "startsWith", "endsWith",
535
+ "sum", "mean", "median", "var", "sd", "min", "max", "range", "abs", "round",
536
+ "signif", "floor", "ceiling", "sqrt", "exp", "log", "log2", "log10",
537
+ "cumsum", "prod", "diff", "table", "tabulate", "quantile", "scale",
538
+ "matrix", "array", "dim", "nrow", "ncol", "rownames", "colnames", "t",
539
+ "cbind", "rbind", "apply", "lapply", "sapply", "vapply", "mapply", "Map",
540
+ "Reduce", "Filter", "do.call", "outer", "aggregate", "split", "by",
541
+ "data.frame", "merge", "subset", "transform", "with", "within", "str",
542
+ "summary", "print", "cat", "message", "warning", "stop", "stopifnot",
543
+ "tryCatch", "try", "on.exit", "invisible", "identical", "all.equal",
544
+ "inherits", "class", "attr", "attributes", "structure", "unlist", "setNames",
545
+ "readline", "readLines", "writeLines", "readRDS", "saveRDS", "read.csv",
546
+ "write.csv", "file", "nchar", "Sys.time", "Sys.Date", "set.seed", "sample",
547
+ "runif", "rnorm", "library", "require", "requireNamespace", "source",
548
+ "suppressWarnings", "suppressMessages", "Recall", "missing", "nargs",
549
+ "environment", "new.env", "get", "exists", "assign", "rm", "ls",
550
+ "UseMethod", "NextMethod", "setClass", "setGeneric", "setMethod", "new",
551
+ "R6Class", "switch", "ifelse", "nlevels", "rapply", "return", "numeric",
552
+ "character", "logical", "integer", "double", "append", "unname", "strrep",
553
+ "utf8ToInt", "intToUtf8", "chartr", "casefold", "charToRaw", "rawToChar",
554
+ "strtoi", "bitwAnd", "bitwOr", "bitwXor", "bitwNot", "bitwShiftL",
555
+ "bitwShiftR", "intToBits", "as.hexmode", "as.roman", "choose", "factorial",
556
+ "trunc", "sign", "pmin", "pmax", "cumprod", "cummax", "cummin", "rank",
557
+ "duplicated", "anyDuplicated", "is.element", "isTRUE", "isFALSE", "xor",
558
+ "nchar", "typeof", "mode", "is.list", "is.vector", "is.integer",
559
+ "is.double", "as.list", "as.vector", "as.double", "row.names", "rowSums",
560
+ "colSums", "rowMeans", "colMeans", "diag", "Re", "Im", "Mod", "Conj",
561
+ "regexpr", "gregexpr", "regexec", "sprintf", "toString", "Negate", "Find",
562
+ "Position", "identity", "Vectorize", "local", "vapply", "mapply",
563
+ "conditionMessage", "simpleError", "warningCondition", "errorCondition",
564
+ "as.Date", "as.POSIXct", "as.POSIXlt", "difftime", "strftime", "strptime",
565
+ "weekdays", "months", "ISOdate", "ISOdatetime", "nchar", "max", "min",
566
+ "emptyenv", "globalenv", "sys.function", "match.arg", "is.environment"
567
+ ].filter((label, i, all) => all.indexOf(label) == i).map(label => ({ label, type: "function" }));
568
+ const constants = /*@__PURE__*/[
569
+ "T", "F", "pi", "letters", "LETTERS", "month.name", "month.abb"
570
+ ].map(label => ({ label, type: "constant" }));
571
+ /**
572
+ Autocompletion for R's reserved words, the snippets, and the part of base R
573
+ that is reached for often enough to be worth proposing. It offers nothing
574
+ inside strings and comments.
575
+ */
576
+ const rCompletion = /*@__PURE__*/outsideLiterals(/*@__PURE__*/completeFromList([...snippets, ...keywords, ...functions, ...constants]));
577
+ /**
578
+ R language support, with completion for the reserved words, snippets, base R
579
+ and the names assigned in the file.
580
+ */
581
+ function r() {
582
+ return new LanguageSupport(rLanguage, [
583
+ rLanguage.data.of({ autocomplete: rCompletion }),
584
+ rLanguage.data.of({ autocomplete: localCompletionSource })
585
+ ]);
586
+ }
587
+
588
+ export { localCompletionSource, parser, r, rCompletion, rLanguage, snippets };
package/package.json CHANGED
@@ -1,6 +1,57 @@
1
1
  {
2
2
  "name": "@exercism/codemirror-lang-r",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "R language support for the CodeMirror code editor",
5
+ "keywords": [
6
+ "editor",
7
+ "code",
8
+ "r",
9
+ "statistics",
10
+ "codemirror"
11
+ ],
12
+ "author": "CodinCod <hello@codincod.com>",
13
+ "license": "MIT",
14
+ "type": "module",
15
+ "main": "dist/index.cjs",
16
+ "exports": {
17
+ "import": "./dist/index.js",
18
+ "require": "./dist/index.cjs"
19
+ },
20
+ "module": "dist/index.js",
21
+ "types": "dist/index.d.ts",
22
+ "sideEffects": false,
23
+ "files": [
24
+ "dist",
25
+ "CHANGELOG.md"
26
+ ],
27
+ "scripts": {
28
+ "build": "rm -rf dist && lezer-generator src/r.grammar -o src/parser.js && cm-buildhelper src/r.ts",
29
+ "build-debug": "lezer-generator src/r.grammar --names -o src/parser.js && cm-buildhelper src/r.ts",
30
+ "prepare": "npm run build",
31
+ "test": "npm run build && node --test \"test/*.test.ts\""
32
+ },
33
+ "dependencies": {
34
+ "@codemirror/autocomplete": "^6.0.0",
35
+ "@codemirror/language": "^6.10.1",
36
+ "@codemirror/state": "^6.7.1",
37
+ "@lezer/common": "^1.0.0",
38
+ "@lezer/highlight": "^1.2.0",
39
+ "@lezer/lr": "^1.4.0"
40
+ },
41
+ "devDependencies": {
42
+ "@codemirror/buildhelper": "^1.0.2",
43
+ "@lezer/generator": "^1.7.0",
44
+ "typescript": "^5.6.0"
45
+ },
46
+ "homepage": "https://github.com/exercism/codemirror-lang-r",
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "https://github.com/exercism/codemirror-lang-r"
50
+ },
51
+ "publishConfig": {
52
+ "access": "public"
53
+ },
54
+ "bugs": {
55
+ "url": "https://github.com/exercism/codemirror-lang-r/issues"
56
+ }
57
+ }