@exercism/codemirror-lang-lisp 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 ADDED
@@ -0,0 +1,94 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0
4
+
5
+ This is Exercism's first release of the package, published as
6
+ `@exercism/codemirror-lang-lisp`. It adds completion for Common Lisp, Emacs Lisp
7
+ and LFE, grammar nodes for the names bound by definitions and binding forms, and
8
+ an `lfe` dialect of the grammar.
9
+
10
+ ## 0.3.1 (2026-08-06)
11
+
12
+ The repository link, which npm renders as a link and a browser cannot follow
13
+ with `git+` in front of it.
14
+
15
+ ## 0.3.0 (2026-07-31)
16
+
17
+ ### New features
18
+
19
+ The head of a list is its own node. `Callee` covers the symbol a list applies,
20
+ which is the one thing a Lisp does not say with punctuation: `(display x)` and
21
+ `(x display)` are the same shape and different programs, and until now both
22
+ symbols carried the same tag. 46% of the symbols in the corpus are the head of
23
+ something, 69% of them in a Racket file.
24
+
25
+ Binding forms are recognised by name, so a parameter list is not read as a
26
+ call. Nineteen of them (`lambda`, `let` and its relatives, `do`, `dolist`,
27
+ `destructuring-bind` and so on) take a `Binder` node, the name they bind takes
28
+ a `Definition`, and their parameter or binding list is `Bindings` holding
29
+ `BoundList` pairs. Without this, `(defun f (a b) ...)` read `a` as a function,
30
+ which was 4.39% of every head in the corpus and landed on the shape the
31
+ language writes most.
32
+
33
+ `Binder` is tagged `definitionKeyword`, `Definition` is
34
+ `definition(variableName)` and `Callee` is `function(variableName)`, so a theme
35
+ that says nothing about the distinctions still paints all three the way it
36
+ painted them before.
37
+
38
+ ### Breaking changes
39
+
40
+ The tree shape changed for anything walking it by node name. A symbol at the
41
+ head of a list is now `Callee` rather than `Symbol`, and the binding forms
42
+ above carry the four new nodes.
43
+
44
+ ### Other
45
+
46
+ The corpus is unmoved: 98.35% of 5590 snippets parse clean, which is what it
47
+ parsed before any of this.
48
+
49
+ ## 0.2.1 (2026-07-29)
50
+
51
+ A line in the README saying what this was written for, and a link to the
52
+ platform it was written for. Nothing in the code changed.
53
+
54
+ ## 0.2.0 (2026-07-26)
55
+
56
+ ### Bug fixes
57
+
58
+ The type declaration no longer imports a module it does not ship. 0.1.0's
59
+ `dist/index.d.ts` opened with `import {parser} from "./parser.js"`, and no
60
+ `parser.d.ts` sat beside it, so any consumer without `skipLibCheck` got
61
+ `TS7016: Could not find a declaration file for module './parser.js'`. The
62
+ declaration is self-contained now.
63
+
64
+ ### New features
65
+
66
+ The package is published as CommonJS as well as ESM. `require()` against 0.1.0
67
+ failed with `ERR_PACKAGE_PATH_NOT_EXPORTED`.
68
+
69
+ Doc comments reach the declaration file, so editors show them on hover.
70
+
71
+ ### Breaking changes
72
+
73
+ `@codincod/codemirror-lang-lisp/package.json` is no longer an exported subpath.
74
+ The `@codemirror/lang-*` packages do not export it either.
75
+
76
+ ### Other
77
+
78
+ The layout follows the conventions the `@codemirror/lang-*` and `@lezer/*`
79
+ packages share: `src/lisp.ts` is the entry point, the generated parser sits
80
+ next to the grammar in `src/`, and the build is `@codemirror/buildhelper`.
81
+
82
+ No grammar changes. The parser is byte for byte what 0.1.0 shipped, and the
83
+ corpus figure is still 98.29% of 5618 snippets.
84
+
85
+ ## 0.1.0 (2026-07-26)
86
+
87
+ First release.
88
+
89
+ A Lezer grammar for the Lisp family, covering Common Lisp, Scheme, Racket,
90
+ Emacs Lisp and the smaller dialects that share their reader. 98.29% of the 5618
91
+ Rosetta Code snippets it was developed against parse with no error node; of the
92
+ 96 that do not, 74 have unbalanced brackets and are not parseable by anything.
93
+
94
+ Ships `lisp()`, `lispLanguage`, `lispCompletion` 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,325 @@
1
- # Temporary Holding Version
1
+ # @exercism/codemirror-lang-lisp [![NPM version](https://img.shields.io/npm/v/@exercism/codemirror-lang-lisp.svg)](https://www.npmjs.org/package/@exercism/codemirror-lang-lisp)
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 fork
4
+
5
+ This is Exercism's fork of
6
+ [`@codincod/codemirror-lang-lisp`](https://codeberg.org/reeven/codemirror-lang-lisp)
7
+ by CodinCod, released under the MIT license. Exercism uses it in the Common
8
+ Lisp, Emacs Lisp and Lisp Flavoured Erlang (LFE) editors on
9
+ [exercism.org](https://exercism.org). Our
10
+ changes are on the `main` branch and are published as
11
+ `@exercism/codemirror-lang-lisp`.
12
+
13
+ The grammar serves every Lisp dialect. The fork adds these nodes to it:
14
+
15
+ - `LocalName` for a name bound by a parameter list or a binding form, such as
16
+ `a` in `(defun f (a) ...)` and `x` in `(let ((x 1)) ...)`.
17
+ - `IterationBinder` and `IterationBindings` for `dolist`, `dotimes`,
18
+ `with-open-file` and the other forms where the list binds one name and then
19
+ holds values. In `(dolist (x items) ...)` only `x` is bound.
20
+ - `FunctionBinder`, `FunctionBindings` and `FunctionBinding` for `flet`,
21
+ `labels` and `macrolet`.
22
+ - `Definer` for `defvar`, `defparameter`, `defconstant`, `defstruct`,
23
+ `defclass`, `deftype` and `define-condition`, with the name being defined as a
24
+ `Definition`.
25
+ - `LambdaKeyword` for `&optional`, `&key`, `&rest` and the other markers in a
26
+ parameter list.
27
+
28
+ Each of these nodes also covers the Emacs Lisp forms of the same shape, such as
29
+ `cl-defun`, `defsubst`, `when-let*`, `seq-let`, `cl-dolist`, `cl-labels`,
30
+ `defconst` and `defcustom`. The grammar reads Emacs Lisp characters (`?a`,
31
+ `?\s`, `?\(`, `?\C-a`). Numbers and booleans come from the external
32
+ tokenizer, which reads the whole symbol first, so `1+`, `1-` and `#topic` are
33
+ symbols.
34
+
35
+ The grammar has an `lfe` dialect for Lisp Flavoured Erlang. When it is on,
36
+ `defun`, `defmacro` and `match-lambda` can be written as clauses, as in
37
+ `(defun f ((0) 1) ((n) (* n (f (- n 1)))))`. Each clause is a `Clause` node,
38
+ with its patterns in `Patterns` and the constructors in them, such as `(cons
39
+ h t)`, in `PatternList`. The names in a pattern are `LocalName`s. `flet`,
40
+ `flet*` and `fletrec` define local functions the same way. `defmodule` and
41
+ `defrecord` are definers, and `receive`, `after`, `try`, `lc`, `bc` and `fun`
42
+ are special forms. In the `lfe` dialect, special forms from the other dialects that LFE
43
+ lacks, such as `loop` and `for`, are ordinary names. The external specializer
44
+ `lfeWords` in `src/tokens.ts` reads these words when the dialect is on, so the
45
+ other dialects are unaffected. In every dialect `#b(` and `#m(`
46
+ open a vector, which is how LFE writes binaries and maps.
47
+
48
+ `defgeneric` and `defmethod` are binders, and a method qualifier such as
49
+ `:before` may sit between the name and the parameter list. A form's body
50
+ indents from its own open bracket, so a form that starts partway along a line
51
+ indents correctly.
52
+
53
+ The package has one entry point for each dialect, on top of the shared one:
54
+
55
+ - `lisp()` is the shared Lisp support. Its completion offers the special forms
56
+ and the names declared in the file. Other dialects can build on it.
57
+ - `commonLisp()` adds completion for Common Lisp:
58
+ - Every symbol exported by the `COMMON-LISP` package: special operators,
59
+ macros, functions, variables and constants.
60
+ - Snippets for `defun`, `defmacro`, `defmethod`, `defparameter`, `lambda`,
61
+ `let`, `let*`, `flet`, `labels`, `if`, `when`, `cond`, `case`, `loop`,
62
+ `dolist`, `dotimes`, `defpackage` with `in-package`, `defstruct`,
63
+ `defclass`, `handler-case` and `multiple-value-bind`.
64
+ - The names declared in the file. Functions, macros, global variables,
65
+ structures and classes are offered everywhere. A parameter or local
66
+ variable is offered inside the form that binds it. The package also offers
67
+ the functions written by `defstruct` (`make-point`, `point-x`, ...), the
68
+ accessors named in `defclass` slots, and the variables bound by `loop`.
69
+
70
+ - `emacsLisp()` adds completion for Emacs Lisp:
71
+ - The built-in special forms, macros and functions: the C primitives for
72
+ lists, sequences, strings, numbers, characters, hash tables, symbols,
73
+ buffers and evaluation, and the libraries `subr`, `subr-x`, `seq`, `map`,
74
+ `pcase`, `cl-lib`, `cl-generic`, `custom` and `ert`.
75
+ - Snippets for `defun`, `defmacro`, `cl-defun`, `defvar`, `defconst`,
76
+ `defcustom`, `lambda`, `let`, `let*`, `if-let*`, `when-let*`, `cl-flet`,
77
+ `cl-labels`, `if`, `when`, `unless`, `cond`, `pcase`, `cl-case`, `while`,
78
+ `dolist`, `dotimes`, `cl-loop`, `cl-defstruct`, `condition-case`,
79
+ `with-temp-buffer`, `ert-deftest`, `provide` and `require`.
80
+ - The names declared in the file, as for Common Lisp. It also offers the
81
+ functions written by `cl-defstruct`, functions named by `defalias`, the
82
+ variables bound by `cl-loop` and the error variable of `condition-case`.
83
+
84
+ - `lfe()` turns on the `lfe` grammar dialect and adds completion for LFE:
85
+ - LFE's core forms and macros, the Erlang BIFs that LFE calls without a
86
+ module, Erlang's operators, and the names of the common Erlang modules.
87
+ - The functions of those modules after `lists:`, `maps:`, `io:`, `string:`
88
+ and the others, and after the module name in `(: lists foldl ...)`. Each
89
+ function shows its arities.
90
+ - Snippets for `defmodule`, `defun` (plain, with clauses, and with a
91
+ guard), `defmacro`, `defrecord`, `lambda`, `match-lambda`, `let`, `let*`,
92
+ `flet`, `fletrec`, `if`, `cond`, `case`, `receive`, `try`, `lc` and `fun`.
93
+ - The names declared in the file, as for Common Lisp. The variables in a
94
+ clause's patterns are offered in that clause, and so are the variables
95
+ bound by patterns in `case`, `receive`, the `catch` of `try`, `let` and
96
+ the generators of `lc` and `bc`. It also offers the functions written by
97
+ `defrecord` (`make-person`, `is-person`, `person-name`,
98
+ `set-person-name`, ...).
99
+
100
+ Nothing is offered inside strings, comments, characters or keywords, or while
101
+ a new name is being typed.
102
+
103
+ `src/common-lisp-symbols.ts` lists the standard symbols. SBCL produced it by
104
+ listing the external symbols of the `COMMON-LISP` package (see the comment at
105
+ the top of the file). Emacs 30.1 wrote `src/emacs-lisp-symbols.ts` with
106
+ `scripts/emacs-lisp-symbols.el`, which says how to run it. Erlang/OTP wrote
107
+ `src/lfe-symbols.ts` with `scripts/lfe-symbols.escript`.
108
+
109
+ ### Adding a dialect
110
+
111
+ Each dialect has two files: `src/<dialect>.ts` for its completion and entry
112
+ point, and `src/<dialect>-symbols.ts` for its built-in names. The helpers in
113
+ `src/dialect.ts` do most of the work:
114
+
115
+ - `builtinSource` turns the built-in names and the snippets into a completion
116
+ source.
117
+ - `localsSource` completes the names declared in the file. A dialect can add
118
+ the names defined by its own forms, using `eachForm` and helpers such as
119
+ `structureNames` and `loopNames`.
120
+ - `dialectSupport` wraps the sources in a `LanguageSupport`.
121
+
122
+ If a dialect has binding forms missing from the grammar, add their names
123
+ to `Binder`, `IterationBinder`, `FunctionBinder` or `Definer` in
124
+ `src/lisp.grammar`, and their completion types to `definitionTypes` in
125
+ `src/locals.ts`. When a dialect gives a form a shape that would break the
126
+ others, as LFE does with `defun`, add a Lezer dialect for it: list its words
127
+ in an external specializer such as `lfeWords`, and pass the configured
128
+ language to `dialectSupport`. Then export the entry point from
129
+ `src/index.ts`, and check that every other dialect still parses the example
130
+ solutions of its Exercism track.
131
+
132
+ [ [**CHANGELOG**](https://codeberg.org/reeven/codemirror-lang-lisp/src/branch/master/CHANGELOG.md) ]
133
+
134
+ This package implements Lisp language support for the
135
+ [CodeMirror](https://codemirror.net/) code editor, using a
136
+ [Lezer](https://lezer.codemirror.net/) grammar written for this package.
137
+
138
+ One parser serves the family: Common Lisp, Scheme, Racket, Emacs Lisp, and the
139
+ smaller dialects that share their reader. They differ in what the reader does
140
+ before the lists are built, and agree about everything after.
141
+
142
+ CodeMirror ships Common Lisp and Scheme as CodeMirror 5 stream modes. A stream
143
+ mode colours tokens and stops there. Without a tree there is no structural
144
+ folding, no indentation that knows what a form is, and no node-aware selection.
145
+
146
+ Written in part for [CodinCod](https://codincod.com/), a competitive coding
147
+ platform, where it colours the editor people solve puzzles in.
148
+
149
+ This code is released under an
150
+ [MIT license](https://codeberg.org/reeven/codemirror-lang-lisp/src/branch/master/LICENSE).
151
+
152
+ ## Install
153
+
154
+ ```
155
+ npm install @exercism/codemirror-lang-lisp
156
+ ```
157
+
158
+ ## Usage
159
+
160
+ ```javascript
161
+ import {EditorView, basicSetup} from "codemirror"
162
+ import {commonLisp} from "@exercism/codemirror-lang-lisp"
163
+
164
+ const view = new EditorView({
165
+ parent: document.body,
166
+ doc: `(defun greet (name)\n (format t "hello, ~a~%" name))`,
167
+ extensions: [basicSetup, commonLisp()]
168
+ })
169
+ ```
170
+
171
+ ## Coverage
172
+
173
+ Which reader constructs the grammar carries was decided by counting them across
174
+ 5618 snippets, so a few things that look like omissions are deliberate.
175
+
176
+ Brackets and braces are lists. Racket and R6RS write `[` where the standard
177
+ writes `(`, and no dialect gives it a different meaning; brackets appear in 22%
178
+ of the corpus. `#lang` takes its whole line, because that line names the reader
179
+ instead of being a form the reader produces, and it appears in 17.5%.
180
+
181
+ Also handled: the quote family (`'`, `` ` ``, `,`, `,@`, `#'`, `` #` ``, `#,`,
182
+ `#,@`), both keyword spellings (`:name` and `#:name`), characters, booleans,
183
+ vectors and structs (`#(`, `#s(`, `#3a(`), dotted pairs, `|symbols with
184
+ spaces|`, ratios and the radix prefixes `#x` `#b` `#o` `#d` `#e` `#i`, `#;`
185
+ datum comments, `#+`/`#-` reader conditionals, and comments in both forms with
186
+ `#| |#` nesting properly.
187
+
188
+ Strings may span lines. That sounds like a detail and is not one. Every Common
189
+ Lisp definition may carry a docstring, most of them wrap, and a token that
190
+ stopped at the line end closed the string early, read the prose as symbols, and
191
+ then took the real closing quote for the start of the next string. Every form
192
+ after it in the file shifted by one.
193
+
194
+ Special forms are lifted out of `Symbol` into their own node, so structure can
195
+ be told from application at a glance. The list is a union across dialects. A
196
+ name that is ordinary in the dialect on screen costs one miscoloured symbol;
197
+ leaving it out costs every file that uses it.
198
+
199
+ The head of a list is a `Callee`, which is the thing a Lisp does not say with
200
+ punctuation: `(display x)` and `(x display)` are the same shape and different
201
+ programs. 46% of the symbols in the corpus are the head of something, and 69%
202
+ of them in a Racket file, so a theme that paints a call differently from the
203
+ names it is passed has most of the file to say it with.
204
+
205
+ Binding forms are known by name, because a parameter list is a list of names
206
+ and not a call. `(defun f (a b) ...)` gives `f` a `Definition` node and leaves
207
+ `a` and `b` as ordinary symbols, where a grammar that only knew about heads
208
+ would read `a` as a function. Nineteen forms are recognised (`lambda`, `let`
209
+ and its relatives, `do`, `dolist`, `destructuring-bind` and so on), which is
210
+ the set whose shape is always "an optional name, then a list of names".
211
+
212
+ ## Accuracy
213
+
214
+ Measured against 5590 Rosetta Code snippets. A file counts as clean only when
215
+ the parse leaves no error node anywhere.
216
+
217
+ | | Snippets | Clean |
218
+ | --- | --: | --: |
219
+ | **All** | **5590** | **98.35%** |
220
+ | Racket | 1191 | 99.58% |
221
+ | Common Lisp | 1161 | 98.36% |
222
+ | PicoLisp | 953 | 98.11% |
223
+ | Scheme | 579 | 98.62% |
224
+ | EchoLisp | 310 | 96.45% |
225
+ | Emacs Lisp | 260 | 98.46% |
226
+
227
+ 92 files are not clean. Most of those have unbalanced brackets: they are
228
+ fragments, transcripts of a REPL session, or shell command lines filed as
229
+ source. No parser reads them.
230
+
231
+ No corpus ships here. Rosetta Code is under the GNU Free
232
+ Documentation License 1.2 and cannot be redistributed under this one.
233
+
234
+ ## Known limits
235
+
236
+ PicoLisp reads `]` as a super-parenthesis closing every open bracket at once.
237
+ That cannot be reconciled with Racket's `[` matching `]` without knowing which
238
+ dialect is on screen. Racket is the larger share, so brackets match.
239
+
240
+ Special forms are recognised by name and never by scope, so a variable called
241
+ `for` or `match` is coloured as a keyword.
242
+
243
+ When `defstruct` has options, as in `(defstruct (point (:conc-name p-)) x
244
+ y)`, its name stays inside the options list and reads as a call. Completion
245
+ still finds it.
246
+
247
+ In Emacs Lisp, a bare `?(`, `?)`, `?[`, `?]`, `?"` or `?;` is not read as a
248
+ character, because `?` is an ordinary symbol in other dialects. Emacs Lisp
249
+ style escapes them anyway, as `?\(`.
250
+
251
+ In LFE, only the clauses of `defun`, `defmacro`, `match-lambda` and the
252
+ local functions of `flet` and `fletrec` have pattern nodes. The patterns of
253
+ `case`, `receive` and `let` are ordinary lists to the grammar, and completion
254
+ finds their variables from the tree. A clause's patterns treat the first
255
+ symbol of every list as a constructor, so in a binary pattern such as
256
+ `(binary (a (size 8)))` the `a` reads as a call.
257
+
258
+ The `loop` macro's clauses are ordinary symbols to the grammar. Completion
259
+ finds the variables bound by `for`, `as` and `with` from the text.
260
+
261
+ ## Building and testing
262
+
263
+ ```
264
+ npm install # installs the dependencies and builds the package into dist/
265
+ npm run build # regenerates the parser, then rebuilds the package
266
+ npm test # builds the package, then runs the tests
267
+ ```
268
+
269
+ ## API Reference
270
+
271
+ **`lisp`**`() → LanguageSupport`
272
+
273
+ Lisp language support, with completion for the special forms.
274
+
275
+ **`lispLanguage`**`: LRLanguage`
276
+
277
+ A language provider based on the Lezer Lisp parser in this package, extended
278
+ with highlighting and indentation information.
279
+
280
+ **`lispCompletion`**`: CompletionSource`
281
+
282
+ Autocompletion for the special forms the grammar recognises.
283
+
284
+ **`localCompletionSource`**`: CompletionSource`
285
+
286
+ Autocompletion for the names declared in the file that are in scope at the
287
+ cursor.
288
+
289
+ **`commonLisp`**`() → LanguageSupport`
290
+
291
+ Common Lisp language support: the shared grammar with Common Lisp completion.
292
+
293
+ **`commonLispCompletion`**`: readonly CompletionSource[]`
294
+
295
+ The Common Lisp completion sources: `commonLispBuiltins` for the standard
296
+ symbols and snippets, and `commonLispLocals` for the names declared in the
297
+ file.
298
+
299
+ **`emacsLisp`**`() → LanguageSupport`
300
+
301
+ Emacs Lisp language support: the shared grammar with Emacs Lisp completion.
302
+
303
+ **`emacsLispCompletion`**`: readonly CompletionSource[]`
304
+
305
+ The Emacs Lisp completion sources: `emacsLispBuiltins` for the built-in names
306
+ and snippets, and `emacsLispLocals` for the names declared in the file.
307
+
308
+ **`lfe`**`() → LanguageSupport`
309
+
310
+ Lisp Flavoured Erlang language support: the shared grammar in its `lfe`
311
+ dialect, with LFE completion.
312
+
313
+ **`lfeLanguage`**`: LRLanguage`
314
+
315
+ The Lisp language with the grammar's `lfe` dialect turned on.
316
+
317
+ **`lfeCompletion`**`: readonly CompletionSource[]`
318
+
319
+ The LFE completion sources: `lfeBuiltins` for the forms, BIFs, module names
320
+ and snippets, `lfeModuleFunctions` for the functions after `module:`, and
321
+ `lfeLocals` for the names declared in the file.
322
+
323
+ **`parser`**`: LRParser`
324
+
325
+ The raw Lezer parser, for tooling that wants the tree without an editor.