@exercism/codemirror-lang-lua 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,81 @@
1
+ ## 1.0.1
2
+
3
+ The README is restructured. This release is the first published from GitHub Actions, with npm provenance.
4
+
5
+ # Changelog
6
+
7
+ ## 1.0.0
8
+
9
+ This is Exercism's first release of the package, published as
10
+ `@exercism/codemirror-lang-lua`. It adds completion of the names declared in the
11
+ file, snippets, standard library members and table fields, and folds blocks from
12
+ the line where they open.
13
+
14
+ ### New features
15
+
16
+ Completion offers the names declared in the file, each only where it is in
17
+ scope, and the fields declared on a table after `name.`, `name:` and `self.`.
18
+ The standard library's members are offered after their table, and the string
19
+ methods after `:`.
20
+
21
+ Snippets for functions, `if`, the three common `for` loops, `while`,
22
+ `repeat` and a metatable class.
23
+
24
+ Keyword completion is turned off inside strings and comments.
25
+
26
+ ### Bug fixes
27
+
28
+ Blocks fold from the line where they open. Before, a fold started at the
29
+ first statement of the body, on the next line, so the fold gutter never
30
+ offered it.
31
+
32
+ ## 0.2.2 (2026-08-06)
33
+
34
+ The repository link, which npm renders as a link and a browser cannot follow
35
+ with `git+` in front of it.
36
+
37
+ ## 0.2.1 (2026-07-29)
38
+
39
+ A line in the README saying what this was written for, and a link to the
40
+ platform it was written for. Nothing in the code changed.
41
+
42
+ ## 0.2.0 (2026-07-26)
43
+
44
+ ### Bug fixes
45
+
46
+ The type declaration no longer imports a module it does not ship. 0.1.0's
47
+ `dist/index.d.ts` opened with `import {parser} from "./parser.js"`, and no
48
+ `parser.d.ts` sat beside it, so any consumer without `skipLibCheck` got
49
+ `TS7016: Could not find a declaration file for module './parser.js'`. The
50
+ declaration is self-contained now.
51
+
52
+ ### New features
53
+
54
+ The package is published as CommonJS as well as ESM. `require()` against 0.1.0
55
+ failed with `ERR_PACKAGE_PATH_NOT_EXPORTED`.
56
+
57
+ Doc comments reach the declaration file, so editors show them on hover.
58
+
59
+ ### Breaking changes
60
+
61
+ `@codincod/codemirror-lang-lua/package.json` is no longer an exported subpath.
62
+ The `@codemirror/lang-*` packages do not export it either.
63
+
64
+ ### Other
65
+
66
+ The layout follows the conventions the `@codemirror/lang-*` and `@lezer/*`
67
+ packages share: `src/lua.ts` is the entry point, the generated parser sits next
68
+ to the grammar in `src/`, and the build is `@codemirror/buildhelper`.
69
+
70
+ No grammar changes. The parser is byte for byte what 0.1.0 shipped, and the
71
+ corpus figure is still 97.57% of 1070 snippets.
72
+
73
+ ## 0.1.0 (2026-07-26)
74
+
75
+ First release.
76
+
77
+ A Lezer grammar for Lua 5.4. 97.57% of the 1070 Rosetta Code snippets it was
78
+ developed against parse with no error node, and all 26 that do not were read:
79
+ 14 are not Lua, 5 do not compile, 4 are fragments, and 3 were damaged upstream.
80
+
81
+ Ships `lua()`, `luaLanguage`, `luaCompletion` and the raw `parser`.
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,144 @@
1
- # Temporary Holding Version
1
+ # @exercism/codemirror-lang-lua
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
+ [ [**CHANGELOG**](CHANGELOG.md) ]
4
+
5
+ This package implements Lua language support for the
6
+ [CodeMirror](https://codemirror.net/) code editor, using a
7
+ [Lezer](https://lezer.codemirror.net/) grammar written for this package.
8
+ Exercism uses it in the Lua editor on [exercism.org](https://exercism.org).
9
+
10
+ CodeMirror ships Lua as a CodeMirror 5 stream mode. A stream mode colours
11
+ tokens and stops there. Without a tree there is no structural folding, no
12
+ indentation that knows what a block is, and no node-aware selection.
13
+
14
+ This code is released under an [MIT license](LICENSE).
15
+
16
+ ## Install
17
+
18
+ ```bash
19
+ npm install @exercism/codemirror-lang-lua
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ```javascript
25
+ import {EditorView, basicSetup} from "codemirror"
26
+ import {lua} from "@exercism/codemirror-lang-lua"
27
+
28
+ const view = new EditorView({
29
+ parent: document.body,
30
+ doc: `print("Hello World!")`,
31
+ extensions: [basicSetup, lua()]
32
+ })
33
+ ```
34
+
35
+ ## Completion
36
+
37
+ `lua()` includes completion for keywords, snippets, the names declared in the
38
+ file, the members of the standard library tables, and the fields declared on a
39
+ table. The API reference below describes each completion source.
40
+
41
+ ## Coverage
42
+
43
+ Lua 5.4, which accepts everything 5.1 through 5.3 do, so older code parses too.
44
+ That includes integer division `//` and the bitwise operators with their own
45
+ precedence levels, `goto` and `::labels::`, the `<const>` and `<close>`
46
+ attributes, `\z` line continuations, calls written without parentheses as
47
+ `f"string"` and `f{table}`, and hex floats like `0xA23p-4`.
48
+
49
+ Long brackets carry a level. `[[...]]` through `[=====[...]=====]` are read for
50
+ both strings and comments, including the half-typed case where the closer is
51
+ not there yet.
52
+
53
+ Two departures from the reference manual, both because this parses code in an
54
+ editor instead of compiling it.
55
+
56
+ Identifiers may hold characters above U+007F. Lua's own lexer asks the C
57
+ library whether a byte is a letter, so whether `local α = 1` compiles depends
58
+ on the locale the interpreter was built against, and code in the wild uses it.
59
+ Painting working code as broken is the worse failure.
60
+
61
+ A newline never ends a statement, so `f\n(x)` is one call, which is what Lua
62
+ does. Lua 5.1 called this ambiguous syntax and 5.2 dropped the complaint.
63
+
64
+ Luau's extensions, meaning type annotations, compound assignment and
65
+ `continue`, are not supported.
66
+
67
+ ## Accuracy
68
+
69
+ Measured against 1072 Lua programs, the Lua half of the
70
+ [Rosetta Code](https://rosettacode.org/) corpus behind
71
+ [CodinCod](https://codincod.com/)'s language-guessing game. A file counts as
72
+ clean only when the parse leaves no error node anywhere.
73
+
74
+ ```
75
+ files 1072
76
+ clean parses 1048 (97.76%)
77
+ error nodes 370
78
+ ```
79
+
80
+ All 24 files that are not clean were read, and none is a gap in the grammar.
81
+
82
+ | | |
83
+ | --: | --- |
84
+ | 14 | are not Lua: C source, HTML output, shell command lines, REPL transcripts and program output, filed under Lua on the wiki |
85
+ | 5 | are Lua that does not compile: a missing `do`, a missing `then`, an unclosed `print(` |
86
+ | 4 | are fragments instead of chunks, like a bare `3.14159` or an anonymous function header |
87
+ | 3 | were damaged before the parser saw them, by a corpus pipeline that masks the language's own name and decodes HTML entities inside string literals |
88
+
89
+ The measurement paid for itself on its first run by finding a bug in that
90
+ pipeline instead of in the grammar. The comment stripper read `--[==[` as an
91
+ ordinary `--` line comment, so a levelled long comment left its body and its
92
+ closer behind as code, and one snippet had been reduced to nothing but
93
+ `]====]`. These numbers are from the corpus rebuilt after that was fixed.
94
+
95
+ No corpus ships here. Rosetta Code is under the GNU Free Documentation License
96
+ 1.2 and cannot be redistributed under this one.
97
+
98
+ ## Building and testing
99
+
100
+ ```bash
101
+ npm install # installs the dependencies and builds dist/
102
+ npm run build # regenerates the parser and rebuilds dist/
103
+ npm test # builds, then runs the tests
104
+ ```
105
+
106
+ ## API Reference
107
+
108
+ **`lua`**`() → LanguageSupport`
109
+
110
+ Lua language support, with completion for keywords, snippets, the standard
111
+ library and the names declared in the file.
112
+
113
+ **`luaLanguage`**`: LRLanguage`
114
+
115
+ A language provider based on the Lezer Lua parser in this package, extended
116
+ with highlighting, folding and indentation information. Blocks fold from the
117
+ line where they open.
118
+
119
+ **`luaCompletion`**`: CompletionSource`
120
+
121
+ Autocompletion for Lua's keywords, snippets, globals and standard library
122
+ tables. It offers nothing inside strings and comments.
123
+
124
+ **`localCompletionSource`**`: CompletionSource`
125
+
126
+ Completes the names declared in the file. A local is offered from the end of
127
+ its declaration to the end of its block, a parameter inside its function and a
128
+ loop variable inside its loop. Globals and global functions are offered
129
+ everywhere. After `name.` or `name:` it offers the fields declared on that
130
+ table, or the standard library's members, and after `self.` inside a method it
131
+ offers the fields of the method's table.
132
+
133
+ **`snippets`**`: readonly Completion[]`
134
+
135
+ Snippets for functions, conditionals, loops and a metatable class.
136
+
137
+ **`parser`**`: LRParser`
138
+
139
+ The raw Lezer parser, for tooling that wants the tree without an editor.
140
+
141
+ ## Contributing
142
+
143
+ Please read about how to [contribute to Exercism](https://exercism.org/docs/building).
144
+ Be sure to read the Exercism [Code of Conduct](https://exercism.org/docs/using/legal/code-of-conduct).