@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/CHANGELOG.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
## 1.0.0
|
|
2
|
+
|
|
3
|
+
This is Exercism's first release of the package, published as
|
|
4
|
+
`@exercism/codemirror-lang-tcl`. It adds completion of the built-in commands and
|
|
5
|
+
their subcommands, `expr` functions, snippets, and the procs, namespaces and
|
|
6
|
+
variables declared in the file.
|
|
7
|
+
|
|
8
|
+
## 0.1.2 (2026-08-12)
|
|
9
|
+
|
|
10
|
+
A comment that ends on a backslash threw `Token end out of bounds` out of the
|
|
11
|
+
parse. A backslash in a comment escapes the character after it, and the scanner
|
|
12
|
+
counted two characters whether or not the second one was there, so a file ending
|
|
13
|
+
on the backslash gave a token ending past its own input and Lezer refused it.
|
|
14
|
+
|
|
15
|
+
That is the ordinary state of a comment while somebody is still typing it, and
|
|
16
|
+
CodeMirror parses from an idle callback where nothing catches a throw, so
|
|
17
|
+
highlighting stopped until the page was reloaded. Every prefix of a Tcl source
|
|
18
|
+
now parses, and a test holds it there.
|
|
19
|
+
|
|
20
|
+
A backslash before a carriage return counted three characters the same way,
|
|
21
|
+
which is right for the CRLF it was written for and wrong for a lone CR.
|
|
22
|
+
|
|
23
|
+
## 0.1.1 (2026-08-06)
|
|
24
|
+
|
|
25
|
+
The repository link, which npm renders as a link and a browser cannot follow
|
|
26
|
+
with `git+` in front of it.
|
|
27
|
+
|
|
28
|
+
## 0.1.0 (2026-08-06)
|
|
29
|
+
|
|
30
|
+
First release. A Lezer grammar for Tcl, written from scratch against the twelve
|
|
31
|
+
rules of `Tcl(n)`, with highlighting, indentation, folding and completion for
|
|
32
|
+
the commands `tclsh` starts with.
|
|
33
|
+
|
|
34
|
+
99.00% of the 1359 Tcl snippets CodinCod keeps parse with no error node, and
|
|
35
|
+
96.41% of the Tcl core, Tk, tcllib and tklib.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 CodinCod
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,130 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @exercism/codemirror-lang-tcl
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
## This fork
|
|
4
|
+
|
|
5
|
+
This is Exercism's fork of
|
|
6
|
+
[`@codincod/codemirror-lang-tcl`](https://codeberg.org/reeven/codemirror-lang-tcl)
|
|
7
|
+
by CodinCod, released under the MIT license. Exercism uses it in the Tcl
|
|
8
|
+
editor on [exercism.org](https://exercism.org). Our changes are on the
|
|
9
|
+
`main` branch, and are published as `@exercism/codemirror-lang-tcl`.
|
|
10
|
+
|
|
11
|
+
The fork adds completion to the package:
|
|
12
|
+
|
|
13
|
+
- The commands that are available when `tclsh` starts, and snippets for `proc`, `if` (with
|
|
14
|
+
`else` and `elseif`), `for`, `foreach`, `while`, `switch`, `namespace eval`,
|
|
15
|
+
`dict for` and `try`.
|
|
16
|
+
- The subcommands of `string`, `dict`, `array`, `info`, `file`, `namespace`,
|
|
17
|
+
`clock`, `chan` and `binary`, the classes of `string is`, and the switches
|
|
18
|
+
of `lsort`, `lsearch`, `regexp`, `regsub`, `switch` and a few others once a
|
|
19
|
+
`-` is typed.
|
|
20
|
+
- The functions of `expr` inside an expression.
|
|
21
|
+
- The procs and namespaces in the file, everywhere. A proc inside
|
|
22
|
+
`namespace eval` is offered by its own name and by its qualified name.
|
|
23
|
+
- The variables in scope, once they have been declared. Inside a proc body, completion
|
|
24
|
+
offers its parameters, its own variables, and the names declared with `global`
|
|
25
|
+
or `upvar`. Completion picks up variables from `set`, `foreach`, `lassign`, `incr`,
|
|
26
|
+
`append`, `lappend`, `variable`, `dict for` and a few others.
|
|
27
|
+
|
|
28
|
+
Completion switches off in comments. Inside a quoted string, variables are offered
|
|
29
|
+
after a `$`, and code inside `[...]` is completed like any other code.
|
|
30
|
+
|
|
31
|
+
To read the declared names from the tree, the grammar gives `set` and
|
|
32
|
+
`namespace eval` nodes of their own: `SetCommand` with a `VariableDefinition`,
|
|
33
|
+
and `NamespaceCommand` with a `NamespaceName`.
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
This package implements [Tcl](https://www.tcl-lang.org/) language support for
|
|
37
|
+
the [CodeMirror](https://codemirror.net/) code editor: a
|
|
38
|
+
[Lezer](https://lezer.codemirror.net/) grammar, highlighting, indentation,
|
|
39
|
+
folding and completion for the commands `tclsh` starts with.
|
|
40
|
+
|
|
41
|
+
The grammar is written from scratch, against the twelve rules of `Tcl(n)`.
|
|
42
|
+
There was a Lezer grammar for Tcl on npm before this one, and measured against
|
|
43
|
+
the 1359 Tcl snippets [CodinCod](https://codincod.com/) keeps, it left seventy
|
|
44
|
+
error nodes in the average file. A tree that is mostly error nodes colours
|
|
45
|
+
worse than the CodeMirror 5 stream mode it was meant to replace, which is why
|
|
46
|
+
that mode was still in use.
|
|
47
|
+
|
|
48
|
+
This one reads 99.00% of those snippets with no error node, and 96.41% of the
|
|
49
|
+
Tcl core, Tk, tcllib and tklib: 2283 files, 33 MiB.
|
|
50
|
+
|
|
51
|
+
Written in part for CodinCod, a competitive coding platform, where it colours
|
|
52
|
+
the editor people solve puzzles in.
|
|
53
|
+
|
|
54
|
+
This code is released under an
|
|
55
|
+
[MIT license](https://codeberg.org/reeven/codemirror-lang-tcl/src/branch/master/LICENSE).
|
|
56
|
+
|
|
57
|
+
## Install
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npm install @exercism/codemirror-lang-tcl
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Usage
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
import {EditorView, basicSetup} from "codemirror"
|
|
67
|
+
import {tcl} from "@exercism/codemirror-lang-tcl"
|
|
68
|
+
|
|
69
|
+
const view = new EditorView({
|
|
70
|
+
parent: document.body,
|
|
71
|
+
doc: `proc fact {n} {
|
|
72
|
+
if {$n <= 1} {
|
|
73
|
+
return 1
|
|
74
|
+
}
|
|
75
|
+
return [expr {$n * [fact [expr {$n - 1}]]}]
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
puts [fact 10]
|
|
79
|
+
`,
|
|
80
|
+
extensions: [basicSetup, tcl()]
|
|
81
|
+
})
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## What a braced word holds
|
|
85
|
+
|
|
86
|
+
Tcl has no expression syntax and no statement syntax. A script is commands, a
|
|
87
|
+
command is words, and what a word means is the business of the command it is
|
|
88
|
+
handed to. `{$x + 1}` is an expression to `expr`, a script to `eval`, a
|
|
89
|
+
two-element list to `lappend` and eight characters to `string length`, and the
|
|
90
|
+
braces are the same braces. No parser can be told which without being told
|
|
91
|
+
what every command does.
|
|
92
|
+
|
|
93
|
+
Four commands are written out in the grammar, because reading their braced
|
|
94
|
+
words as anything else colours them wrong: `proc` takes a list of parameters,
|
|
95
|
+
and `if`, `while` and `for` take a condition, which is where the operator
|
|
96
|
+
table on the `expr` manual page applies.
|
|
97
|
+
|
|
98
|
+
Every other braced word is read as a script. That is what one is whenever it
|
|
99
|
+
is long enough to be worth colouring, and a procedure body left as an opaque
|
|
100
|
+
run of characters is the one outcome worse than colouring a list of names as
|
|
101
|
+
though the first were a command.
|
|
102
|
+
|
|
103
|
+
## What the tokenizer decides
|
|
104
|
+
|
|
105
|
+
Four things a context-free grammar cannot say are settled in `src/tokens.ts`,
|
|
106
|
+
each of them by asking the parser what it has room for:
|
|
107
|
+
|
|
108
|
+
* **A word is a run of pieces that touch.** `a$b[c]d` is one argument and
|
|
109
|
+
`a $b [c] d` is four, so a piece may only join the one before it when
|
|
110
|
+
nothing stands between them.
|
|
111
|
+
* **A brace and a quote are only special where a word begins.** `a{b}` is the
|
|
112
|
+
four characters it looks like.
|
|
113
|
+
* **A command name is only a command name in the first word of a command.**
|
|
114
|
+
`if` opens a conditional and `lappend l if` appends two letters.
|
|
115
|
+
* **`#` opens a comment only where a command may start**, and stops at the
|
|
116
|
+
brace that closes the word it is written in. Tcl counts braces before it
|
|
117
|
+
knows what a comment is, so `{a ;# b}` is a whole word.
|
|
118
|
+
|
|
119
|
+
Two further things are read the way Tcl's own two passes read them. A quote
|
|
120
|
+
that never closes before the enclosing braced word ends is a quote and not the
|
|
121
|
+
start of a string, and so is a `[` with no `]` to answer it: a line of
|
|
122
|
+
somebody's test data would otherwise take the rest of the file with it.
|
|
123
|
+
|
|
124
|
+
## Building and testing
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
npm install # installs the dependencies and builds dist/
|
|
128
|
+
npm run build # regenerates the parser and rebuilds dist/
|
|
129
|
+
npm test # builds, then runs the tests
|
|
130
|
+
```
|