@exercism/codemirror-lang-clojure 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 +30 -0
- package/LICENSE +13 -0
- package/README.md +55 -2
- package/dist/index.cjs +1018 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.es.js +1010 -0
- package/package.json +66 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
This is Exercism's first release of the package, published as
|
|
6
|
+
`@exercism/codemirror-lang-clojure`. It adds CodeMirror support with
|
|
7
|
+
highlighting, indentation, folding and completion, and grammar nodes for the
|
|
8
|
+
names bound by forms such as `defn`, `let` and `fn`.
|
|
9
|
+
|
|
10
|
+
## 1.0.0-rc.2 (2022-07-06)
|
|
11
|
+
* Add namespace forms
|
|
12
|
+
|
|
13
|
+
## 1.0.0-rc.1 (2022-07-05)
|
|
14
|
+
* Reintroduce constructor call Syntax
|
|
15
|
+
* Refine allowed Reader Tags
|
|
16
|
+
* Make skip-next-form play well with prefixed expressions
|
|
17
|
+
|
|
18
|
+
## 1.0.0-rc.0 (2022-06-30)
|
|
19
|
+
* Upgrade to Lezer parser to v1.0.0
|
|
20
|
+
* Remove constructor call syntax
|
|
21
|
+
* Improve char detection (#17)
|
|
22
|
+
|
|
23
|
+
## 0.1.10 (2020-12-07)
|
|
24
|
+
* Upgrade Lezer to v0.13
|
|
25
|
+
* Extend grammar to include more #-prefixed expressions (#5)
|
|
26
|
+
* Deflike expressions with metadata
|
|
27
|
+
* Operator for first element in a list
|
|
28
|
+
|
|
29
|
+
## 0.1.0 (2020-10-20)
|
|
30
|
+
* First release
|
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2022 Nextjournal GmbH.
|
|
2
|
+
|
|
3
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose
|
|
4
|
+
with or without fee is hereby granted, provided that the above copyright notice
|
|
5
|
+
and this permission notice appear in all copies.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
9
|
+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
11
|
+
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
12
|
+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
|
13
|
+
THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,56 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @exercism/codemirror-lang-clojure
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This package gives the [CodeMirror 6](https://codemirror.net/) editor support for Clojure, with a [Lezer](https://lezer.codemirror.net/) grammar, highlighting, indentation, folding and autocompletion. Exercism uses it in the editor on [exercism.org](https://exercism.org).
|
|
4
|
+
|
|
5
|
+
It is a fork of [nextjournal/lezer-clojure](https://github.com/nextjournal/lezer-clojure) by Martin Kavalar and Andrea Amantini at Nextjournal. The grammar comes from that repo, and the highlighting and indentation come from [nextjournal/lang-clojure](https://github.com/nextjournal/lang-clojure) by Andrea Amantini. Both are licensed under the ISC licence, and so is this fork.
|
|
6
|
+
|
|
7
|
+
The `main` branch follows upstream. Exercism's work is on the `exercism` branch.
|
|
8
|
+
|
|
9
|
+
## What the fork adds
|
|
10
|
+
|
|
11
|
+
The grammar has nodes for the names bound by a form, so the editor can highlight them and offer them as completions:
|
|
12
|
+
|
|
13
|
+
- `defn`, `defn-`, `defmacro` and `definline` have their parameters marked, including each arity of a multi-arity function.
|
|
14
|
+
- `let`, `loop`, `for`, `doseq`, `when-let`, `if-let` and the other binding macros have their bindings marked, including `:let` inside `for` and `doseq`.
|
|
15
|
+
- `fn` has its name and parameters marked, `letfn` its functions, `catch` its exception, and `defrecord` and `deftype` their fields.
|
|
16
|
+
- Destructuring works in all of these, for example `[{:keys [a b] :as m} & more]`.
|
|
17
|
+
- Special forms and the core macros (`if`, `when`, `cond`, `->` and so on) are highlighted as keywords when they start a list. Other symbols that start a list are highlighted as function calls.
|
|
18
|
+
|
|
19
|
+
Every new form also parses as an ordinary list. If a form does not have the shape expected by the grammar (for example while it is still being typed), it parses as a plain list.
|
|
20
|
+
|
|
21
|
+
The completion offers:
|
|
22
|
+
|
|
23
|
+
- special forms, and the public functions, macros and vars of `clojure.core`.
|
|
24
|
+
- snippets for `defn`, `fn`, `let`, `if`, `when`, `cond`, `case`, `loop`, `doseq`, `for`, `ns`, `defrecord`, `defprotocol`, `defmulti`, `defmethod`, `try` and the threading macros. If the word follows an open paren, the snippet goes inside it. Otherwise the snippet brings its own parens.
|
|
25
|
+
- the names defined with `def`, `defn` and the like anywhere in the file, and the `->Name` and `map->Name` constructors of each record.
|
|
26
|
+
- local names (bindings and parameters) inside the form that binds them, once they are bound.
|
|
27
|
+
- `clojure.string` and `clojure.set` functions, both with the full namespace (`clojure.string/join`) and with the alias given in the `ns` form (`str/join`).
|
|
28
|
+
|
|
29
|
+
It offers nothing inside strings, comments, keywords or numbers, or while a new name is being typed.
|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
npm install @exercism/codemirror-lang-clojure
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
import {EditorView, basicSetup} from "codemirror"
|
|
41
|
+
import {clojure} from "@exercism/codemirror-lang-clojure"
|
|
42
|
+
|
|
43
|
+
new EditorView({
|
|
44
|
+
doc: "(defn hello [name]\n (str \"Hello, \" name))",
|
|
45
|
+
extensions: [basicSetup, clojure()],
|
|
46
|
+
parent: document.body
|
|
47
|
+
})
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The package also exports `parser` (the Lezer parser), `clojureLanguage`, the two completion sources (`localCompletionSource` and `builtinCompletionSource`) and the lists of `builtins`.
|
|
51
|
+
|
|
52
|
+
## Developing
|
|
53
|
+
|
|
54
|
+
Run `npm install`, then `npm run build` to build the parser and the package, and `npm test` to run the tests. The grammar tests are in `test/*.txt`, and the completion and language tests are in `test/test-completion.js` and `test/test-language.js`.
|
|
55
|
+
|
|
56
|
+
The lists in `src/builtins.js` come from the public vars of Clojure 1.12.7.
|