@exercism/codemirror-lang-tcl 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 ADDED
@@ -0,0 +1,39 @@
1
+ ## 1.0.1
2
+
3
+ The README is restructured. This release is the first published from GitHub Actions, with npm provenance.
4
+
5
+ ## 1.0.0
6
+
7
+ This is Exercism's first release of the package, published as
8
+ `@exercism/codemirror-lang-tcl`. It adds completion of the built-in commands and
9
+ their subcommands, `expr` functions, snippets, and the procs, namespaces and
10
+ variables declared in the file.
11
+
12
+ ## 0.1.2 (2026-08-12)
13
+
14
+ A comment that ends on a backslash threw `Token end out of bounds` out of the
15
+ parse. A backslash in a comment escapes the character after it, and the scanner
16
+ counted two characters whether or not the second one was there, so a file ending
17
+ on the backslash gave a token ending past its own input and Lezer refused it.
18
+
19
+ That is the ordinary state of a comment while somebody is still typing it, and
20
+ CodeMirror parses from an idle callback where nothing catches a throw, so
21
+ highlighting stopped until the page was reloaded. Every prefix of a Tcl source
22
+ now parses, and a test holds it there.
23
+
24
+ A backslash before a carriage return counted three characters the same way,
25
+ which is right for the CRLF it was written for and wrong for a lone CR.
26
+
27
+ ## 0.1.1 (2026-08-06)
28
+
29
+ The repository link, which npm renders as a link and a browser cannot follow
30
+ with `git+` in front of it.
31
+
32
+ ## 0.1.0 (2026-08-06)
33
+
34
+ First release. A Lezer grammar for Tcl, written from scratch against the twelve
35
+ rules of `Tcl(n)`, with highlighting, indentation, folding and completion for
36
+ the commands `tclsh` starts with.
37
+
38
+ 99.00% of the 1359 Tcl snippets CodinCod keeps parse with no error node, and
39
+ 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,126 @@
1
- # Temporary Holding Version
1
+ # @exercism/codemirror-lang-tcl
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ This package implements [Tcl](https://www.tcl-lang.org/) language support for
4
+ the [CodeMirror](https://codemirror.net/) code editor: a
5
+ [Lezer](https://lezer.codemirror.net/) grammar, highlighting, indentation,
6
+ folding and completion for the commands `tclsh` starts with.
7
+
8
+ The grammar is written from scratch, against the twelve rules of `Tcl(n)`.
9
+ There was a Lezer grammar for Tcl on npm before this one, and measured against
10
+ the 1359 Tcl snippets [CodinCod](https://codincod.com/) keeps, it left seventy
11
+ error nodes in the average file. A tree that is mostly error nodes colours
12
+ worse than the CodeMirror 5 stream mode it was meant to replace, which is why
13
+ that mode was still in use.
14
+
15
+ This one reads 99.00% of those snippets with no error node, and 96.41% of the
16
+ Tcl core, Tk, tcllib and tklib: 2283 files, 33 MiB.
17
+
18
+ Exercism uses this package in the Tcl editor on [exercism.org](https://exercism.org).
19
+
20
+ This code is released under an [MIT license](LICENSE).
21
+
22
+ ## Install
23
+
24
+ ```bash
25
+ npm install @exercism/codemirror-lang-tcl
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ ```javascript
31
+ import {EditorView, basicSetup} from "codemirror"
32
+ import {tcl} from "@exercism/codemirror-lang-tcl"
33
+
34
+ const view = new EditorView({
35
+ parent: document.body,
36
+ doc: `proc fact {n} {
37
+ if {$n <= 1} {
38
+ return 1
39
+ }
40
+ return [expr {$n * [fact [expr {$n - 1}]]}]
41
+ }
42
+
43
+ puts [fact 10]
44
+ `,
45
+ extensions: [basicSetup, tcl()]
46
+ })
47
+ ```
48
+
49
+ ## Completion
50
+
51
+ Completion offers:
52
+
53
+ - The commands that are available when `tclsh` starts, and snippets for `proc`, `if` (with
54
+ `else` and `elseif`), `for`, `foreach`, `while`, `switch`, `namespace eval`,
55
+ `dict for` and `try`.
56
+ - The subcommands of `string`, `dict`, `array`, `info`, `file`, `namespace`,
57
+ `clock`, `chan` and `binary`, the classes of `string is`, and the switches
58
+ of `lsort`, `lsearch`, `regexp`, `regsub`, `switch` and a few others once a
59
+ `-` is typed.
60
+ - The functions of `expr` inside an expression.
61
+ - The procs and namespaces in the file, everywhere. A proc inside
62
+ `namespace eval` is offered by its own name and by its qualified name.
63
+ - The variables in scope, once they have been declared. Inside a proc body, completion
64
+ offers its parameters, its own variables, and the names declared with `global`
65
+ or `upvar`. Completion picks up variables from `set`, `foreach`, `lassign`, `incr`,
66
+ `append`, `lappend`, `variable`, `dict for` and a few others.
67
+
68
+ Completion switches off in comments. Inside a quoted string, variables are offered
69
+ after a `$`, and code inside `[...]` is completed like any other code.
70
+
71
+ To read the declared names from the tree, the grammar gives `set` and
72
+ `namespace eval` nodes of their own: `SetCommand` with a `VariableDefinition`,
73
+ and `NamespaceCommand` with a `NamespaceName`.
74
+
75
+ ## What a braced word holds
76
+
77
+ Tcl has no expression syntax and no statement syntax. A script is commands, a
78
+ command is words, and what a word means is the business of the command it is
79
+ handed to. `{$x + 1}` is an expression to `expr`, a script to `eval`, a
80
+ two-element list to `lappend` and eight characters to `string length`, and the
81
+ braces are the same braces. No parser can be told which without being told
82
+ what every command does.
83
+
84
+ Four commands are written out in the grammar, because reading their braced
85
+ words as anything else colours them wrong: `proc` takes a list of parameters,
86
+ and `if`, `while` and `for` take a condition, which is where the operator
87
+ table on the `expr` manual page applies.
88
+
89
+ Every other braced word is read as a script. That is what one is whenever it
90
+ is long enough to be worth colouring, and a procedure body left as an opaque
91
+ run of characters is the one outcome worse than colouring a list of names as
92
+ though the first were a command.
93
+
94
+ ## What the tokenizer decides
95
+
96
+ Four things a context-free grammar cannot say are settled in `src/tokens.ts`,
97
+ each of them by asking the parser what it has room for:
98
+
99
+ * **A word is a run of pieces that touch.** `a$b[c]d` is one argument and
100
+ `a $b [c] d` is four, so a piece may only join the one before it when
101
+ nothing stands between them.
102
+ * **A brace and a quote are only special where a word begins.** `a{b}` is the
103
+ four characters it looks like.
104
+ * **A command name is only a command name in the first word of a command.**
105
+ `if` opens a conditional and `lappend l if` appends two letters.
106
+ * **`#` opens a comment only where a command may start**, and stops at the
107
+ brace that closes the word it is written in. Tcl counts braces before it
108
+ knows what a comment is, so `{a ;# b}` is a whole word.
109
+
110
+ Two further things are read the way Tcl's own two passes read them. A quote
111
+ that never closes before the enclosing braced word ends is a quote and not the
112
+ start of a string, and so is a `[` with no `]` to answer it: a line of
113
+ somebody's test data would otherwise take the rest of the file with it.
114
+
115
+ ## Building and testing
116
+
117
+ ```bash
118
+ npm install # installs the dependencies and builds dist/
119
+ npm run build # regenerates the parser and rebuilds dist/
120
+ npm test # builds, then runs the tests
121
+ ```
122
+
123
+ ## Contributing
124
+
125
+ Please read about how to [contribute to Exercism](https://exercism.org/docs/building).
126
+ Be sure to read the Exercism [Code of Conduct](https://exercism.org/docs/using/legal/code-of-conduct).