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