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