@exercism/codemirror-lang-tcl 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 +35 -0
- package/LICENSE +21 -0
- package/README.md +129 -2
- package/dist/index.cjs +848 -0
- package/dist/index.d.cts +118 -0
- package/dist/index.d.ts +118 -0
- package/dist/index.js +841 -0
- package/package.json +55 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { LRParser } from '@lezer/lr';
|
|
2
|
+
import { LanguageSupport, LRLanguage } from '@codemirror/language';
|
|
3
|
+
|
|
4
|
+
declare const parser: LRParser
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
Snippets for the constructs written most often in Tcl.
|
|
8
|
+
*/
|
|
9
|
+
declare const snippets = [
|
|
10
|
+
snippetCompletion("proc ${name} {${args}} {\n\t${}\n}", { label: "proc", detail: "definition", type: "keyword" }),
|
|
11
|
+
snippetCompletion("if {${condition}} {\n\t${}\n}", { label: "if", detail: "block", type: "keyword" }),
|
|
12
|
+
snippetCompletion("if {${condition}} {\n\t${}\n} else {\n\t${}\n}", { label: "if", detail: "/ else block", type: "keyword" }),
|
|
13
|
+
snippetCompletion("if {${condition}} {\n\t${}\n} elseif {${condition}} {\n\t${}\n} else {\n\t${}\n}", { label: "if", detail: "/ elseif / else block", type: "keyword" }),
|
|
14
|
+
snippetCompletion("for {set ${i} 0} {$${i} < ${n}} {incr ${i}} {\n\t${}\n}", { label: "for", detail: "loop", type: "keyword" }),
|
|
15
|
+
snippetCompletion("foreach ${item} ${list} {\n\t${}\n}", { label: "foreach", detail: "loop", type: "keyword" }),
|
|
16
|
+
snippetCompletion("while {${condition}} {\n\t${}\n}", { label: "while", detail: "loop", type: "keyword" }),
|
|
17
|
+
snippetCompletion("switch -- ${value} {\n\t${pattern} {\n\t\t${}\n\t}\n\tdefault {\n\t\t${}\n\t}\n}", { label: "switch", detail: "block", type: "keyword" }),
|
|
18
|
+
snippetCompletion("namespace eval ${name} {\n\t${}\n}", { label: "namespace", detail: "eval block", type: "keyword" }),
|
|
19
|
+
snippetCompletion("dict for {${key} ${value}} ${dict} {\n\t${}\n}", { label: "dict", detail: "for loop", type: "keyword" }),
|
|
20
|
+
snippetCompletion("try {\n\t${}\n} on error {${message}} {\n\t${}\n}", { label: "try", detail: "/ on error", type: "keyword" })
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
The commands `tclsh` starts with. Tk's are not here: a script that has them
|
|
24
|
+
has loaded a package to get them, and a script that has not would be
|
|
25
|
+
offered a command it cannot run.
|
|
26
|
+
*/
|
|
27
|
+
declare const commands = [
|
|
28
|
+
"after", "append", "apply", "array", "binary", "break", "catch", "cd",
|
|
29
|
+
"chan", "clock", "close", "concat", "continue", "coroutine", "dict", "encoding",
|
|
30
|
+
"eof", "error", "eval", "exec", "exit", "expr", "fblocked", "fconfigure",
|
|
31
|
+
"fcopy", "file", "fileevent", "flush", "for", "foreach", "format", "gets",
|
|
32
|
+
"glob", "global", "history", "if", "incr", "info", "interp", "join",
|
|
33
|
+
"lappend", "lassign", "lindex", "linsert", "list", "llength", "lmap",
|
|
34
|
+
"load", "lpop", "lrange", "lremove", "lrepeat", "lreplace", "lreverse",
|
|
35
|
+
"lsearch", "lseq", "lset", "lsort", "namespace", "open", "package", "pid",
|
|
36
|
+
"proc", "puts", "pwd", "read", "regexp", "regsub", "rename", "return",
|
|
37
|
+
"scan", "seek", "set", "socket", "source", "split", "string", "subst",
|
|
38
|
+
"switch", "tailcall", "tell", "throw", "time", "timerate", "trace", "try", "unload",
|
|
39
|
+
"unset", "update", "uplevel", "upvar", "variable", "vwait", "while", "yield",
|
|
40
|
+
"yieldto", "zlib", "oo::class", "oo::define", "oo::object"
|
|
41
|
+
];
|
|
42
|
+
/**
|
|
43
|
+
Completion for Tcl: the built-in commands and their subcommands and
|
|
44
|
+
switches, snippets, the functions of `expr`, and the procs, namespaces and
|
|
45
|
+
variables declared in the file. A variable is offered in the scope that
|
|
46
|
+
declares it, once it has been declared, and after a `$`. Nothing is
|
|
47
|
+
offered in comments, and inside a quoted string only after a `$`.
|
|
48
|
+
*/
|
|
49
|
+
declare const tclCompletion = (context) => {
|
|
50
|
+
const { state, pos } = context;
|
|
51
|
+
const doc = state.doc;
|
|
52
|
+
const tree = syntaxTree(state);
|
|
53
|
+
const here = tree.resolveInner(pos, -1);
|
|
54
|
+
const where = contextOf(here);
|
|
55
|
+
if (where == "comment")
|
|
56
|
+
return null;
|
|
57
|
+
const dollar = context.matchBefore(/\$[\w:]*$/);
|
|
58
|
+
if (dollar) {
|
|
59
|
+
return { from: dollar.from + 1, options: variableOptions(variablesAt(doc, here, dollar.from)), validFor: /^[\w:]*$/ };
|
|
60
|
+
}
|
|
61
|
+
if (where == "string" || where == "declaring")
|
|
62
|
+
return null;
|
|
63
|
+
const word = context.matchBefore(/[\w:\-]*$/);
|
|
64
|
+
if (word.from == word.to && !context.explicit)
|
|
65
|
+
return null;
|
|
66
|
+
const result = (options) => ({ from: word.from, options: dedupe(options), validFor: /^[\w:\-]*$/ });
|
|
67
|
+
if (where == "expr")
|
|
68
|
+
return result(exprOptions);
|
|
69
|
+
const variables = variableOptions(variablesAt(doc, here, word.from));
|
|
70
|
+
if (where == "definition")
|
|
71
|
+
return result(variables);
|
|
72
|
+
// Find the word being typed. With nothing typed yet, it is the word after
|
|
73
|
+
// the last one on the line, or the name of a new command.
|
|
74
|
+
let found;
|
|
75
|
+
if (word.from < word.to) {
|
|
76
|
+
found = wordOf(tree.resolveInner(word.from, 1));
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
const line = doc.lineAt(pos);
|
|
80
|
+
const before = doc.sliceString(line.from, pos).replace(/[ \t]+$/, "");
|
|
81
|
+
if (!before || /[;[{]$/.test(before))
|
|
82
|
+
found = null;
|
|
83
|
+
else {
|
|
84
|
+
const last = wordOf(tree.resolveInner(line.from + before.length, -1));
|
|
85
|
+
found = last && { command: last.command, index: countChildren(last.command) };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const names = fileNames(doc, tree);
|
|
89
|
+
if (!found || found.index == 0)
|
|
90
|
+
return result([...commandOptions, ...names, ...variables]);
|
|
91
|
+
const { command, index } = found;
|
|
92
|
+
const commandName = command.firstChild ? text(doc, command.firstChild) : "";
|
|
93
|
+
const typed = doc.sliceString(word.from, word.to);
|
|
94
|
+
if (command.name == "IfCommand")
|
|
95
|
+
return result([...ifBranches, ...names, ...variables]);
|
|
96
|
+
if (typed.startsWith("-")) {
|
|
97
|
+
const list = switches[commandName];
|
|
98
|
+
return list ? result(list.map(label => ({ label, type: "property" }))) : null;
|
|
99
|
+
}
|
|
100
|
+
if (index == 1 && subcommands[commandName]) {
|
|
101
|
+
return result(subcommands[commandName].map(label => ({ label, type: "method" })));
|
|
102
|
+
}
|
|
103
|
+
const argument = (i) => {
|
|
104
|
+
let ch = command.firstChild;
|
|
105
|
+
for (let n = 0; ch && n < i; n++)
|
|
106
|
+
ch = ch.nextSibling;
|
|
107
|
+
return ch ? text(doc, ch) : "";
|
|
108
|
+
};
|
|
109
|
+
if (commandName == "string" && index == 2 && argument(1) == "is") {
|
|
110
|
+
return result(stringClasses.map(label => ({ label, type: "constant" })));
|
|
111
|
+
}
|
|
112
|
+
return result([...variables, ...names]);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
declare const tclLanguage: LRLanguage;
|
|
116
|
+
declare function tcl(): LanguageSupport;
|
|
117
|
+
|
|
118
|
+
export { commands, parser, snippets, tcl, tclCompletion, tclLanguage };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { LRParser } from '@lezer/lr';
|
|
2
|
+
import { LanguageSupport, LRLanguage } from '@codemirror/language';
|
|
3
|
+
|
|
4
|
+
declare const parser: LRParser
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
Snippets for the constructs written most often in Tcl.
|
|
8
|
+
*/
|
|
9
|
+
declare const snippets = [
|
|
10
|
+
snippetCompletion("proc ${name} {${args}} {\n\t${}\n}", { label: "proc", detail: "definition", type: "keyword" }),
|
|
11
|
+
snippetCompletion("if {${condition}} {\n\t${}\n}", { label: "if", detail: "block", type: "keyword" }),
|
|
12
|
+
snippetCompletion("if {${condition}} {\n\t${}\n} else {\n\t${}\n}", { label: "if", detail: "/ else block", type: "keyword" }),
|
|
13
|
+
snippetCompletion("if {${condition}} {\n\t${}\n} elseif {${condition}} {\n\t${}\n} else {\n\t${}\n}", { label: "if", detail: "/ elseif / else block", type: "keyword" }),
|
|
14
|
+
snippetCompletion("for {set ${i} 0} {$${i} < ${n}} {incr ${i}} {\n\t${}\n}", { label: "for", detail: "loop", type: "keyword" }),
|
|
15
|
+
snippetCompletion("foreach ${item} ${list} {\n\t${}\n}", { label: "foreach", detail: "loop", type: "keyword" }),
|
|
16
|
+
snippetCompletion("while {${condition}} {\n\t${}\n}", { label: "while", detail: "loop", type: "keyword" }),
|
|
17
|
+
snippetCompletion("switch -- ${value} {\n\t${pattern} {\n\t\t${}\n\t}\n\tdefault {\n\t\t${}\n\t}\n}", { label: "switch", detail: "block", type: "keyword" }),
|
|
18
|
+
snippetCompletion("namespace eval ${name} {\n\t${}\n}", { label: "namespace", detail: "eval block", type: "keyword" }),
|
|
19
|
+
snippetCompletion("dict for {${key} ${value}} ${dict} {\n\t${}\n}", { label: "dict", detail: "for loop", type: "keyword" }),
|
|
20
|
+
snippetCompletion("try {\n\t${}\n} on error {${message}} {\n\t${}\n}", { label: "try", detail: "/ on error", type: "keyword" })
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
The commands `tclsh` starts with. Tk's are not here: a script that has them
|
|
24
|
+
has loaded a package to get them, and a script that has not would be
|
|
25
|
+
offered a command it cannot run.
|
|
26
|
+
*/
|
|
27
|
+
declare const commands = [
|
|
28
|
+
"after", "append", "apply", "array", "binary", "break", "catch", "cd",
|
|
29
|
+
"chan", "clock", "close", "concat", "continue", "coroutine", "dict", "encoding",
|
|
30
|
+
"eof", "error", "eval", "exec", "exit", "expr", "fblocked", "fconfigure",
|
|
31
|
+
"fcopy", "file", "fileevent", "flush", "for", "foreach", "format", "gets",
|
|
32
|
+
"glob", "global", "history", "if", "incr", "info", "interp", "join",
|
|
33
|
+
"lappend", "lassign", "lindex", "linsert", "list", "llength", "lmap",
|
|
34
|
+
"load", "lpop", "lrange", "lremove", "lrepeat", "lreplace", "lreverse",
|
|
35
|
+
"lsearch", "lseq", "lset", "lsort", "namespace", "open", "package", "pid",
|
|
36
|
+
"proc", "puts", "pwd", "read", "regexp", "regsub", "rename", "return",
|
|
37
|
+
"scan", "seek", "set", "socket", "source", "split", "string", "subst",
|
|
38
|
+
"switch", "tailcall", "tell", "throw", "time", "timerate", "trace", "try", "unload",
|
|
39
|
+
"unset", "update", "uplevel", "upvar", "variable", "vwait", "while", "yield",
|
|
40
|
+
"yieldto", "zlib", "oo::class", "oo::define", "oo::object"
|
|
41
|
+
];
|
|
42
|
+
/**
|
|
43
|
+
Completion for Tcl: the built-in commands and their subcommands and
|
|
44
|
+
switches, snippets, the functions of `expr`, and the procs, namespaces and
|
|
45
|
+
variables declared in the file. A variable is offered in the scope that
|
|
46
|
+
declares it, once it has been declared, and after a `$`. Nothing is
|
|
47
|
+
offered in comments, and inside a quoted string only after a `$`.
|
|
48
|
+
*/
|
|
49
|
+
declare const tclCompletion = (context) => {
|
|
50
|
+
const { state, pos } = context;
|
|
51
|
+
const doc = state.doc;
|
|
52
|
+
const tree = syntaxTree(state);
|
|
53
|
+
const here = tree.resolveInner(pos, -1);
|
|
54
|
+
const where = contextOf(here);
|
|
55
|
+
if (where == "comment")
|
|
56
|
+
return null;
|
|
57
|
+
const dollar = context.matchBefore(/\$[\w:]*$/);
|
|
58
|
+
if (dollar) {
|
|
59
|
+
return { from: dollar.from + 1, options: variableOptions(variablesAt(doc, here, dollar.from)), validFor: /^[\w:]*$/ };
|
|
60
|
+
}
|
|
61
|
+
if (where == "string" || where == "declaring")
|
|
62
|
+
return null;
|
|
63
|
+
const word = context.matchBefore(/[\w:\-]*$/);
|
|
64
|
+
if (word.from == word.to && !context.explicit)
|
|
65
|
+
return null;
|
|
66
|
+
const result = (options) => ({ from: word.from, options: dedupe(options), validFor: /^[\w:\-]*$/ });
|
|
67
|
+
if (where == "expr")
|
|
68
|
+
return result(exprOptions);
|
|
69
|
+
const variables = variableOptions(variablesAt(doc, here, word.from));
|
|
70
|
+
if (where == "definition")
|
|
71
|
+
return result(variables);
|
|
72
|
+
// Find the word being typed. With nothing typed yet, it is the word after
|
|
73
|
+
// the last one on the line, or the name of a new command.
|
|
74
|
+
let found;
|
|
75
|
+
if (word.from < word.to) {
|
|
76
|
+
found = wordOf(tree.resolveInner(word.from, 1));
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
const line = doc.lineAt(pos);
|
|
80
|
+
const before = doc.sliceString(line.from, pos).replace(/[ \t]+$/, "");
|
|
81
|
+
if (!before || /[;[{]$/.test(before))
|
|
82
|
+
found = null;
|
|
83
|
+
else {
|
|
84
|
+
const last = wordOf(tree.resolveInner(line.from + before.length, -1));
|
|
85
|
+
found = last && { command: last.command, index: countChildren(last.command) };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const names = fileNames(doc, tree);
|
|
89
|
+
if (!found || found.index == 0)
|
|
90
|
+
return result([...commandOptions, ...names, ...variables]);
|
|
91
|
+
const { command, index } = found;
|
|
92
|
+
const commandName = command.firstChild ? text(doc, command.firstChild) : "";
|
|
93
|
+
const typed = doc.sliceString(word.from, word.to);
|
|
94
|
+
if (command.name == "IfCommand")
|
|
95
|
+
return result([...ifBranches, ...names, ...variables]);
|
|
96
|
+
if (typed.startsWith("-")) {
|
|
97
|
+
const list = switches[commandName];
|
|
98
|
+
return list ? result(list.map(label => ({ label, type: "property" }))) : null;
|
|
99
|
+
}
|
|
100
|
+
if (index == 1 && subcommands[commandName]) {
|
|
101
|
+
return result(subcommands[commandName].map(label => ({ label, type: "method" })));
|
|
102
|
+
}
|
|
103
|
+
const argument = (i) => {
|
|
104
|
+
let ch = command.firstChild;
|
|
105
|
+
for (let n = 0; ch && n < i; n++)
|
|
106
|
+
ch = ch.nextSibling;
|
|
107
|
+
return ch ? text(doc, ch) : "";
|
|
108
|
+
};
|
|
109
|
+
if (commandName == "string" && index == 2 && argument(1) == "is") {
|
|
110
|
+
return result(stringClasses.map(label => ({ label, type: "constant" })));
|
|
111
|
+
}
|
|
112
|
+
return result([...variables, ...names]);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
declare const tclLanguage: LRLanguage;
|
|
116
|
+
declare function tcl(): LanguageSupport;
|
|
117
|
+
|
|
118
|
+
export { commands, parser, snippets, tcl, tclCompletion, tclLanguage };
|