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