@exercism/codemirror-lang-red 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/CHANGELOG.md +34 -0
- package/LICENSE +21 -0
- package/README.md +203 -2
- package/dist/index.cjs +1662 -0
- package/dist/index.d.cts +88 -0
- package/dist/index.d.ts +88 -0
- package/dist/index.js +1654 -0
- package/package.json +56 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { LanguageSupport, LRLanguage } from '@codemirror/language';
|
|
2
|
+
import { LRParser } from '@lezer/lr';
|
|
3
|
+
|
|
4
|
+
declare const parser: LRParser
|
|
5
|
+
|
|
6
|
+
declare const snippets = [
|
|
7
|
+
snip("func [${args}] [\n\t${}\n]", { label: "func", detail: "definition", type: "keyword" }),
|
|
8
|
+
snip("function [${args}] [\n\t${}\n]", { label: "function", detail: "definition", type: "keyword" }),
|
|
9
|
+
snip("does [\n\t${}\n]", { label: "does", detail: "definition", type: "keyword" }),
|
|
10
|
+
snip("has [${locals}] [\n\t${}\n]", { label: "has", detail: "definition", type: "keyword" }),
|
|
11
|
+
snip("make object! [\n\t${}\n]", { label: "object", detail: "make object!", type: "keyword" }),
|
|
12
|
+
snip("if ${condition} [\n\t${}\n]", { label: "if", detail: "block", type: "keyword" }),
|
|
13
|
+
snip("unless ${condition} [\n\t${}\n]", { label: "unless", detail: "block", type: "keyword" }),
|
|
14
|
+
snip("either ${condition} [\n\t${}\n] [\n\t\n]", { label: "either", detail: "/ else block", type: "keyword" }),
|
|
15
|
+
snip("case [\n\t${condition} [${}]\n\ttrue [\n]", { label: "case", detail: "block", type: "keyword" }),
|
|
16
|
+
snip("switch ${value} [\n\t${case} [${}]\n]", { label: "switch", detail: "block", type: "keyword" }),
|
|
17
|
+
snip("foreach ${item} ${series} [\n\t${}\n]", { label: "foreach", detail: "loop", type: "keyword" }),
|
|
18
|
+
snip("repeat ${i} ${count} [\n\t${}\n]", { label: "repeat", detail: "loop", type: "keyword" }),
|
|
19
|
+
snip("loop ${count} [\n\t${}\n]", { label: "loop", detail: "loop", type: "keyword" }),
|
|
20
|
+
snip("while [${condition}] [\n\t${}\n]", { label: "while", detail: "loop", type: "keyword" }),
|
|
21
|
+
snip("until [\n\t${}\n\t${condition}\n]", { label: "until", detail: "loop", type: "keyword" }),
|
|
22
|
+
snip("collect [\n\t${}keep \n]", { label: "collect", detail: "block", type: "keyword" }),
|
|
23
|
+
snip("parse ${input} [\n\t${rules}\n]", { label: "parse", detail: "rules", type: "keyword" })
|
|
24
|
+
];
|
|
25
|
+
/**
|
|
26
|
+
Completion for Red and Rebol: names in scope, then, for Red, the words
|
|
27
|
+
Red starts with, the snippets and the dialect words of `parse` and
|
|
28
|
+
`collect`.
|
|
29
|
+
*/
|
|
30
|
+
declare function completionSource(withRed) {
|
|
31
|
+
return (context) => {
|
|
32
|
+
const node = syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
33
|
+
let from = context.pos;
|
|
34
|
+
let plain = true;
|
|
35
|
+
if (wordTokens.has(node.name)) {
|
|
36
|
+
const typed = context.state.sliceDoc(node.from, context.pos);
|
|
37
|
+
if (node.name == "Path" || typed.includes("/"))
|
|
38
|
+
return refinementCompletion(context, node);
|
|
39
|
+
if (node.name == "GetWord" || node.name == "LitWord") {
|
|
40
|
+
from = node.from + 1;
|
|
41
|
+
plain = false;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
from = node.from;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else if (!containers.has(node.name) || !context.explicit) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
const options = namesInScope(context.state, node);
|
|
51
|
+
if (withRed) {
|
|
52
|
+
options.push(...redOptions);
|
|
53
|
+
if (plain) {
|
|
54
|
+
options.push(...snippets);
|
|
55
|
+
if (inParseRules(context.state, node))
|
|
56
|
+
options.push(...parseOptions);
|
|
57
|
+
if (inCollect(context.state, node))
|
|
58
|
+
options.push(keepOption);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return { from, options, validFor: wordChars };
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
Rebol, in the sense of every interpreter that reads this syntax:
|
|
67
|
+
Rebol 2, Rebol 3 and the forks that continue it. `redLanguage` is the
|
|
68
|
+
other dialect.
|
|
69
|
+
*/
|
|
70
|
+
declare const rebolLanguage: LRLanguage;
|
|
71
|
+
/**
|
|
72
|
+
Red, which is a second language with the same lexer and a preprocessor
|
|
73
|
+
of its own. Red/System, the dialect a `.reds` file is written in, is the
|
|
74
|
+
same syntax again with other words in it, so it reads here too.
|
|
75
|
+
*/
|
|
76
|
+
declare const redLanguage: LRLanguage;
|
|
77
|
+
/**
|
|
78
|
+
Rebol support, with the names set in the file offered as completions.
|
|
79
|
+
*/
|
|
80
|
+
declare function rebol(): LanguageSupport;
|
|
81
|
+
/**
|
|
82
|
+
Red support. Completion offers the names in scope, the functions and
|
|
83
|
+
datatypes Red starts with, the refinements after a `/`, snippets, and
|
|
84
|
+
the words of `parse` and `collect` inside their blocks.
|
|
85
|
+
*/
|
|
86
|
+
declare function red(): LanguageSupport;
|
|
87
|
+
|
|
88
|
+
export { completionSource, parser, rebol, rebolLanguage, red, redLanguage, snippets };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { LanguageSupport, LRLanguage } from '@codemirror/language';
|
|
2
|
+
import { LRParser } from '@lezer/lr';
|
|
3
|
+
|
|
4
|
+
declare const parser: LRParser
|
|
5
|
+
|
|
6
|
+
declare const snippets = [
|
|
7
|
+
snip("func [${args}] [\n\t${}\n]", { label: "func", detail: "definition", type: "keyword" }),
|
|
8
|
+
snip("function [${args}] [\n\t${}\n]", { label: "function", detail: "definition", type: "keyword" }),
|
|
9
|
+
snip("does [\n\t${}\n]", { label: "does", detail: "definition", type: "keyword" }),
|
|
10
|
+
snip("has [${locals}] [\n\t${}\n]", { label: "has", detail: "definition", type: "keyword" }),
|
|
11
|
+
snip("make object! [\n\t${}\n]", { label: "object", detail: "make object!", type: "keyword" }),
|
|
12
|
+
snip("if ${condition} [\n\t${}\n]", { label: "if", detail: "block", type: "keyword" }),
|
|
13
|
+
snip("unless ${condition} [\n\t${}\n]", { label: "unless", detail: "block", type: "keyword" }),
|
|
14
|
+
snip("either ${condition} [\n\t${}\n] [\n\t\n]", { label: "either", detail: "/ else block", type: "keyword" }),
|
|
15
|
+
snip("case [\n\t${condition} [${}]\n\ttrue [\n]", { label: "case", detail: "block", type: "keyword" }),
|
|
16
|
+
snip("switch ${value} [\n\t${case} [${}]\n]", { label: "switch", detail: "block", type: "keyword" }),
|
|
17
|
+
snip("foreach ${item} ${series} [\n\t${}\n]", { label: "foreach", detail: "loop", type: "keyword" }),
|
|
18
|
+
snip("repeat ${i} ${count} [\n\t${}\n]", { label: "repeat", detail: "loop", type: "keyword" }),
|
|
19
|
+
snip("loop ${count} [\n\t${}\n]", { label: "loop", detail: "loop", type: "keyword" }),
|
|
20
|
+
snip("while [${condition}] [\n\t${}\n]", { label: "while", detail: "loop", type: "keyword" }),
|
|
21
|
+
snip("until [\n\t${}\n\t${condition}\n]", { label: "until", detail: "loop", type: "keyword" }),
|
|
22
|
+
snip("collect [\n\t${}keep \n]", { label: "collect", detail: "block", type: "keyword" }),
|
|
23
|
+
snip("parse ${input} [\n\t${rules}\n]", { label: "parse", detail: "rules", type: "keyword" })
|
|
24
|
+
];
|
|
25
|
+
/**
|
|
26
|
+
Completion for Red and Rebol: names in scope, then, for Red, the words
|
|
27
|
+
Red starts with, the snippets and the dialect words of `parse` and
|
|
28
|
+
`collect`.
|
|
29
|
+
*/
|
|
30
|
+
declare function completionSource(withRed) {
|
|
31
|
+
return (context) => {
|
|
32
|
+
const node = syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
33
|
+
let from = context.pos;
|
|
34
|
+
let plain = true;
|
|
35
|
+
if (wordTokens.has(node.name)) {
|
|
36
|
+
const typed = context.state.sliceDoc(node.from, context.pos);
|
|
37
|
+
if (node.name == "Path" || typed.includes("/"))
|
|
38
|
+
return refinementCompletion(context, node);
|
|
39
|
+
if (node.name == "GetWord" || node.name == "LitWord") {
|
|
40
|
+
from = node.from + 1;
|
|
41
|
+
plain = false;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
from = node.from;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else if (!containers.has(node.name) || !context.explicit) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
const options = namesInScope(context.state, node);
|
|
51
|
+
if (withRed) {
|
|
52
|
+
options.push(...redOptions);
|
|
53
|
+
if (plain) {
|
|
54
|
+
options.push(...snippets);
|
|
55
|
+
if (inParseRules(context.state, node))
|
|
56
|
+
options.push(...parseOptions);
|
|
57
|
+
if (inCollect(context.state, node))
|
|
58
|
+
options.push(keepOption);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return { from, options, validFor: wordChars };
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
Rebol, in the sense of every interpreter that reads this syntax:
|
|
67
|
+
Rebol 2, Rebol 3 and the forks that continue it. `redLanguage` is the
|
|
68
|
+
other dialect.
|
|
69
|
+
*/
|
|
70
|
+
declare const rebolLanguage: LRLanguage;
|
|
71
|
+
/**
|
|
72
|
+
Red, which is a second language with the same lexer and a preprocessor
|
|
73
|
+
of its own. Red/System, the dialect a `.reds` file is written in, is the
|
|
74
|
+
same syntax again with other words in it, so it reads here too.
|
|
75
|
+
*/
|
|
76
|
+
declare const redLanguage: LRLanguage;
|
|
77
|
+
/**
|
|
78
|
+
Rebol support, with the names set in the file offered as completions.
|
|
79
|
+
*/
|
|
80
|
+
declare function rebol(): LanguageSupport;
|
|
81
|
+
/**
|
|
82
|
+
Red support. Completion offers the names in scope, the functions and
|
|
83
|
+
datatypes Red starts with, the refinements after a `/`, snippets, and
|
|
84
|
+
the words of `parse` and `collect` inside their blocks.
|
|
85
|
+
*/
|
|
86
|
+
declare function red(): LanguageSupport;
|
|
87
|
+
|
|
88
|
+
export { completionSource, parser, rebol, rebolLanguage, red, redLanguage, snippets };
|