@exercism/codemirror-lang-r 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/CHANGELOG.md +31 -0
- package/LICENSE +21 -0
- package/README.md +110 -2
- package/dist/index.cjs +595 -0
- package/dist/index.d.cts +98 -0
- package/dist/index.d.ts +98 -0
- package/dist/index.js +588 -0
- package/package.json +55 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { LRParser } from '@lezer/lr';
|
|
2
|
+
import { LanguageSupport, LRLanguage } from '@codemirror/language';
|
|
3
|
+
import { CompletionSource } from '@codemirror/autocomplete';
|
|
4
|
+
|
|
5
|
+
declare const parser: LRParser
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
Snippets for the constructs people write most often in R.
|
|
9
|
+
*/
|
|
10
|
+
declare const snippets = [
|
|
11
|
+
snip("${name} <- function(${params}) {\n\t${}\n}", {
|
|
12
|
+
label: "function",
|
|
13
|
+
detail: "definition",
|
|
14
|
+
type: "keyword"
|
|
15
|
+
}),
|
|
16
|
+
snip("\\(${x}) ${}", {
|
|
17
|
+
label: "\\",
|
|
18
|
+
detail: "lambda",
|
|
19
|
+
type: "keyword"
|
|
20
|
+
}),
|
|
21
|
+
snip("if (${condition}) {\n\t${}\n}", {
|
|
22
|
+
label: "if",
|
|
23
|
+
detail: "block",
|
|
24
|
+
type: "keyword"
|
|
25
|
+
}),
|
|
26
|
+
snip("if (${condition}) {\n\t${}\n} else {\n\t\n}", {
|
|
27
|
+
label: "if",
|
|
28
|
+
detail: "/ else block",
|
|
29
|
+
type: "keyword"
|
|
30
|
+
}),
|
|
31
|
+
snip("for (${i} in ${seq_along(x)}) {\n\t${}\n}", {
|
|
32
|
+
label: "for",
|
|
33
|
+
detail: "loop",
|
|
34
|
+
type: "keyword"
|
|
35
|
+
}),
|
|
36
|
+
snip("while (${condition}) {\n\t${}\n}", {
|
|
37
|
+
label: "while",
|
|
38
|
+
detail: "loop",
|
|
39
|
+
type: "keyword"
|
|
40
|
+
}),
|
|
41
|
+
snip("repeat {\n\t${}\n\tif (${condition}) break\n}", {
|
|
42
|
+
label: "repeat",
|
|
43
|
+
detail: "loop",
|
|
44
|
+
type: "keyword"
|
|
45
|
+
}),
|
|
46
|
+
snip("switch(${x},\n\t${name} = ${value},\n\t${default}\n)", {
|
|
47
|
+
label: "switch",
|
|
48
|
+
detail: "by value",
|
|
49
|
+
type: "keyword"
|
|
50
|
+
}),
|
|
51
|
+
snip("tryCatch({\n\t${}\n}, error = function(e) {\n\t\n})", {
|
|
52
|
+
label: "tryCatch",
|
|
53
|
+
detail: "handle errors",
|
|
54
|
+
type: "keyword"
|
|
55
|
+
})
|
|
56
|
+
];
|
|
57
|
+
/**
|
|
58
|
+
Completes the names assigned in the file and the parameters of the
|
|
59
|
+
functions around the cursor.
|
|
60
|
+
*/
|
|
61
|
+
declare const localCompletionSource = outsideLiterals((context) => {
|
|
62
|
+
const word = context.matchBefore(/[\p{L}\w.]+$/u);
|
|
63
|
+
if (!word && !context.explicit)
|
|
64
|
+
return null;
|
|
65
|
+
const inner = syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
66
|
+
const options = [];
|
|
67
|
+
const seen = new Set();
|
|
68
|
+
for (let pos = inner; pos; pos = pos.parent) {
|
|
69
|
+
if (!ScopeNodes.has(pos.name))
|
|
70
|
+
continue;
|
|
71
|
+
for (const option of scopeNames(pos, context.state.doc)) {
|
|
72
|
+
if (seen.has(option.label))
|
|
73
|
+
continue;
|
|
74
|
+
seen.add(option.label);
|
|
75
|
+
options.push(option);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
from: word ? word.from : context.pos,
|
|
80
|
+
options,
|
|
81
|
+
validFor: identifier
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
declare const rLanguage: LRLanguage;
|
|
86
|
+
/**
|
|
87
|
+
Autocompletion for R's reserved words, the snippets, and the part of base R
|
|
88
|
+
that is reached for often enough to be worth proposing. It offers nothing
|
|
89
|
+
inside strings and comments.
|
|
90
|
+
*/
|
|
91
|
+
declare const rCompletion: CompletionSource;
|
|
92
|
+
/**
|
|
93
|
+
R language support, with completion for the reserved words, snippets, base R
|
|
94
|
+
and the names assigned in the file.
|
|
95
|
+
*/
|
|
96
|
+
declare function r(): LanguageSupport;
|
|
97
|
+
|
|
98
|
+
export { localCompletionSource, parser, r, rCompletion, rLanguage, snippets };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { LRParser } from '@lezer/lr';
|
|
2
|
+
import { LanguageSupport, LRLanguage } from '@codemirror/language';
|
|
3
|
+
import { CompletionSource } from '@codemirror/autocomplete';
|
|
4
|
+
|
|
5
|
+
declare const parser: LRParser
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
Snippets for the constructs people write most often in R.
|
|
9
|
+
*/
|
|
10
|
+
declare const snippets = [
|
|
11
|
+
snip("${name} <- function(${params}) {\n\t${}\n}", {
|
|
12
|
+
label: "function",
|
|
13
|
+
detail: "definition",
|
|
14
|
+
type: "keyword"
|
|
15
|
+
}),
|
|
16
|
+
snip("\\(${x}) ${}", {
|
|
17
|
+
label: "\\",
|
|
18
|
+
detail: "lambda",
|
|
19
|
+
type: "keyword"
|
|
20
|
+
}),
|
|
21
|
+
snip("if (${condition}) {\n\t${}\n}", {
|
|
22
|
+
label: "if",
|
|
23
|
+
detail: "block",
|
|
24
|
+
type: "keyword"
|
|
25
|
+
}),
|
|
26
|
+
snip("if (${condition}) {\n\t${}\n} else {\n\t\n}", {
|
|
27
|
+
label: "if",
|
|
28
|
+
detail: "/ else block",
|
|
29
|
+
type: "keyword"
|
|
30
|
+
}),
|
|
31
|
+
snip("for (${i} in ${seq_along(x)}) {\n\t${}\n}", {
|
|
32
|
+
label: "for",
|
|
33
|
+
detail: "loop",
|
|
34
|
+
type: "keyword"
|
|
35
|
+
}),
|
|
36
|
+
snip("while (${condition}) {\n\t${}\n}", {
|
|
37
|
+
label: "while",
|
|
38
|
+
detail: "loop",
|
|
39
|
+
type: "keyword"
|
|
40
|
+
}),
|
|
41
|
+
snip("repeat {\n\t${}\n\tif (${condition}) break\n}", {
|
|
42
|
+
label: "repeat",
|
|
43
|
+
detail: "loop",
|
|
44
|
+
type: "keyword"
|
|
45
|
+
}),
|
|
46
|
+
snip("switch(${x},\n\t${name} = ${value},\n\t${default}\n)", {
|
|
47
|
+
label: "switch",
|
|
48
|
+
detail: "by value",
|
|
49
|
+
type: "keyword"
|
|
50
|
+
}),
|
|
51
|
+
snip("tryCatch({\n\t${}\n}, error = function(e) {\n\t\n})", {
|
|
52
|
+
label: "tryCatch",
|
|
53
|
+
detail: "handle errors",
|
|
54
|
+
type: "keyword"
|
|
55
|
+
})
|
|
56
|
+
];
|
|
57
|
+
/**
|
|
58
|
+
Completes the names assigned in the file and the parameters of the
|
|
59
|
+
functions around the cursor.
|
|
60
|
+
*/
|
|
61
|
+
declare const localCompletionSource = outsideLiterals((context) => {
|
|
62
|
+
const word = context.matchBefore(/[\p{L}\w.]+$/u);
|
|
63
|
+
if (!word && !context.explicit)
|
|
64
|
+
return null;
|
|
65
|
+
const inner = syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
66
|
+
const options = [];
|
|
67
|
+
const seen = new Set();
|
|
68
|
+
for (let pos = inner; pos; pos = pos.parent) {
|
|
69
|
+
if (!ScopeNodes.has(pos.name))
|
|
70
|
+
continue;
|
|
71
|
+
for (const option of scopeNames(pos, context.state.doc)) {
|
|
72
|
+
if (seen.has(option.label))
|
|
73
|
+
continue;
|
|
74
|
+
seen.add(option.label);
|
|
75
|
+
options.push(option);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
from: word ? word.from : context.pos,
|
|
80
|
+
options,
|
|
81
|
+
validFor: identifier
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
declare const rLanguage: LRLanguage;
|
|
86
|
+
/**
|
|
87
|
+
Autocompletion for R's reserved words, the snippets, and the part of base R
|
|
88
|
+
that is reached for often enough to be worth proposing. It offers nothing
|
|
89
|
+
inside strings and comments.
|
|
90
|
+
*/
|
|
91
|
+
declare const rCompletion: CompletionSource;
|
|
92
|
+
/**
|
|
93
|
+
R language support, with completion for the reserved words, snippets, base R
|
|
94
|
+
and the names assigned in the file.
|
|
95
|
+
*/
|
|
96
|
+
declare function r(): LanguageSupport;
|
|
97
|
+
|
|
98
|
+
export { localCompletionSource, parser, r, rCompletion, rLanguage, snippets };
|