@exercism/codemirror-lang-erlang 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,34 @@
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-erlang`. It adds completion of the file's functions,
11
+ macros, records and variables, standard library functions after a module name,
12
+ and snippets, and parses an attribute with spaces after its hyphen, such as
13
+ `- spec f() -> ok.`.
14
+
15
+ ## 0.1.0
16
+
17
+ First release.
18
+
19
+ A Lezer grammar for Erlang up to OTP 29, written from scratch: no CodeMirror 6
20
+ grammar for the language existed, on npm or anywhere else.
21
+
22
+ 98.11% of 8923 files from OTP, RabbitMQ, EMQX, ejabberd, Cowboy, rebar3, Ranch,
23
+ riak_core, erlang_ls, hackney, PropEr, epgsql, mochiweb, lager, meck, elli,
24
+ gproc, gen_smtp, jsx and poolboy parse with no error node.
25
+
26
+ What it reads that a CodeMirror 5 stream mode did not: a tree. Patterns and
27
+ expressions share one rule, the way Erlang's own grammar reads a `case`, so bit
28
+ syntax and comprehensions fall out of the operators rather than needing rules
29
+ of their own. Types are a second grammar, reached from `-spec`, `-type` and the
30
+ `::` that annotates a record field.
31
+
32
+ The dialects nobody writes modules in are here too: a form may be a bare
33
+ expression, and a pasted shell session is read as its prompts, what was typed
34
+ at them and the terms printed back.
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,85 @@
1
- # Temporary Holding Version
1
+ # @exercism/codemirror-lang-erlang
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
+ Erlang language support for [CodeMirror 6](https://codemirror.net/), built on a
4
+ [Lezer](https://lezer.codemirror.net/) grammar written from scratch. No Lezer
5
+ grammar for Erlang existed before this one. Exercism uses it in the Erlang
6
+ editor on [exercism.org](https://exercism.org).
7
+
8
+ ```bash
9
+ npm install @exercism/codemirror-lang-erlang
10
+ ```
11
+
12
+ ```js
13
+ import {EditorView, basicSetup} from "codemirror"
14
+ import {erlang} from "@exercism/codemirror-lang-erlang"
15
+
16
+ new EditorView({
17
+ doc: "-module(hello).\n-export([world/0]).\n\nworld() -> io:format(\"hello~n\").\n",
18
+ extensions: [basicSetup, erlang()],
19
+ parent: document.body
20
+ })
21
+ ```
22
+
23
+ `erlang()` returns the language with completion. `erlangLanguage` is the
24
+ language without completion, and `parser` is the Lezer parser that it uses.
25
+
26
+ ## Completion
27
+
28
+ Completion offers keywords, guards and the parts of OTP that people use most. It
29
+ also offers:
30
+
31
+ - The names declared in the file. That covers the file's functions with their
32
+ arities (as `add/2` inside `-export([...])` and after `fun`), macros after
33
+ `?`, records after `#`, a record's fields after `#point.` and inside its
34
+ braces, and the variables of the clause around the cursor. Completion offers
35
+ a variable bound inside a `fun` or a comprehension within that `fun` or
36
+ comprehension.
37
+ - The functions of `lists`, `maps`, `string`, `io`, `io_lib`, `math`,
38
+ `proplists` and `erlang` after the module name and a colon.
39
+ - Attribute names after a hyphen at the start of a line.
40
+ - Snippets for function clauses, `case`, `if`, `receive`, `fun`, `try`,
41
+ `begin` and the `-module` and `-export` header.
42
+
43
+ Completion is switched off inside strings and comments.
44
+
45
+ ## What it reads
46
+
47
+ OTP 29's Erlang, which is every version before it plus the parts that arrived
48
+ late: `maybe` blocks, sigils (`~"binary"`, `~B/verbatim/`), triple-quoted
49
+ strings, `-doc` and `-moduledoc`, the strict generators `<:-` and `<:=`, zip
50
+ generators, map comprehensions, `-nominal` types, and the record declarations
51
+ OTP 29 writes as `-record #point{x, y}.`
52
+
53
+ Two dialects come with it, because most published Erlang is written in one of
54
+ them rather than in a module. A form may be a bare expression, which is what
55
+ the shell is handed, and a pasted shell session is read as what was typed at
56
+ each prompt and the term printed under it.
57
+
58
+ The grammar reads an attribute with spaces after its hyphen, such as
59
+ `- spec f() -> ok.`, which the compiler accepts.
60
+
61
+ Measured against 8923 files of OTP, RabbitMQ, EMQX, ejabberd, Cowboy, rebar3
62
+ and thirteen other projects: 98.11% parse with no error node.
63
+
64
+ ## What it does not read
65
+
66
+ A `-define` whose body is not an expression. `-define(F(T, R), T:R -> ok)` is
67
+ a fragment of a clause and the preprocessor pastes it into place; nothing that
68
+ parses Erlang before the preprocessor runs can read it as anything.
69
+
70
+ ## Building and testing
71
+
72
+ ```bash
73
+ npm install # installs the dependencies and builds dist/
74
+ npm run build # regenerates the parser and rebuilds dist/
75
+ npm test # builds, then runs the tests
76
+ ```
77
+
78
+ ## Licence
79
+
80
+ This code is released under an [MIT license](LICENSE).
81
+
82
+ ## Contributing
83
+
84
+ Please read about how to [contribute to Exercism](https://exercism.org/docs/building).
85
+ Be sure to read the Exercism [Code of Conduct](https://exercism.org/docs/using/legal/code-of-conduct).