@exercism/codemirror-lang-reasonml 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (C) 2024 by Erik Schierboom <erik_schierboom@hotmail.com> and others
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
13
+ all 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
21
+ THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,101 @@
1
- # Temporary Holding Version
1
+ # ReasonML language support for CodeMirror
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
+ ![NPM Version](https://img.shields.io/npm/v/@exercism/codemirror-lang-reasonml)
4
+
5
+ This package gives the CodeMirror 6 editor a Lezer grammar for ReasonML 3, with highlighting, indentation, folding and autocompletion.
6
+ Exercism uses it in the in-browser editor for the ReasonML track.
7
+
8
+ ⚠️ To keep the package working on the Exercism website, don't change the versions of these packages:
9
+
10
+ ```json
11
+ "@codemirror/language": "^6.10.1",
12
+ "@lezer/highlight": "^1.2.0",
13
+ "@lezer/lr": "^1.4.0"
14
+ ```
15
+
16
+ ## Install
17
+
18
+ - NPM: `npm install @exercism/codemirror-lang-reasonml`
19
+ - Yarn: `yarn add @exercism/codemirror-lang-reasonml`
20
+ - Bun: `bun add @exercism/codemirror-lang-reasonml`
21
+
22
+ ## Usage
23
+
24
+ ```js
25
+ import { EditorView, basicSetup } from "codemirror";
26
+ import { reasonml } from "@exercism/codemirror-lang-reasonml";
27
+
28
+ new EditorView({
29
+ extensions: [basicSetup, reasonml()],
30
+ parent: document.body,
31
+ });
32
+ ```
33
+
34
+ ## What it does
35
+
36
+ - It reads `.re` and `.rei` files: let bindings, types, modules, functors, module types, externals, attributes such as `[@bs.val]` and extensions such as `[%re "/a/"]`.
37
+ - It highlights keywords, strings, numbers, comments, definitions, function calls, types, constructors, record fields, labels and operators.
38
+ - It indents inside braces, brackets and parentheses, and folds blocks, modules, records, lists, arrays and `switch` expressions.
39
+ - Its autocompletion offers:
40
+ - keywords, and snippets for `let`, a function, `let rec`, `switch`, `if` and `else`, record and variant types, `module`, `module type`, `fun`, an arrow function, `for`, `while`, `try` and `exception`.
41
+ - the built-in values, types and constructors, such as `string_of_int`, `option` and `Some`.
42
+ - a module's members after its name and a dot, such as `List.map`, `Js.String.split` or `Belt.Option.getWithDefault`. This covers the OCaml 4.06 standard library shipped with BuckleScript, and every `Js` and `Belt` module. Each member shows its type, such as `(list('a), int) => 'a` for `List.nth`. `Option`, `Result`, `Int` and `Float` complete as Belt's modules, which solutions use after `open Belt`.
43
+ - the members of a module declared in the file.
44
+ - the names declared in the file that are in scope at the cursor: values, functions, types, constructors, record fields, exceptions and modules declared above it, and the parameters and pattern variables of the functions, `switch` cases and loops around it.
45
+
46
+ ## How the grammar reads semicolons
47
+
48
+ Reason separates items with semicolons, but people often leave them out between top-level items.
49
+ When the next token can't continue the current item, the fallback tokenizer in `src/tokens.ts` ends the item there.
50
+ So `let a = 1` on one line and `let b = 2` on the next parse as two items, while `f(x)` followed by `(y)` on the next line still reads as one call.
51
+
52
+ The cases of a `fun` have no braces around them, so each case body is a single expression.
53
+ A `switch` case body can hold several items separated by semicolons, but a type declaration inside a case body needs braces.
54
+
55
+ ## Updating the module lists
56
+
57
+ `src/modules.ts` is generated from the interface files in bs-platform 9, which is the compiler used by the ReasonML track. The script reads the OCaml `.mli` and `.ml` files and writes each type in Reason syntax. To regenerate it:
58
+
59
+ ```shell
60
+ npm pack bs-platform@9
61
+ tar xzf bs-platform-9.0.2.tgz
62
+ node scripts/generate-modules.mjs package
63
+ ```
64
+
65
+ The script prints how many members each module has.
66
+
67
+ ## Prerequisites
68
+
69
+ - [Bun](https://bun.sh/)
70
+
71
+ ## Setup
72
+
73
+ Run `bun install` to install all dependencies.
74
+
75
+ ## Developing
76
+
77
+ To help with development, run `bun run dev`.
78
+ This starts a [Vite](https://vite.dev/) dev server (usually at http://localhost:5173/) that renders `index.html` with some sample ReasonML code.
79
+
80
+ The grammar is in `src/syntax.grammar`, the external tokenizers are in `src/tokens.ts`, and the completion is in `src/complete.ts` and `src/modules.ts`.
81
+
82
+ ## Building
83
+
84
+ Run `bun run prepare` to build the package into `dist/`.
85
+ It runs Rollup under Bun's runtime, because one of the Rollup plugins doesn't load in recent versions of Node.
86
+
87
+ ## Testing
88
+
89
+ Run `bun run test`. It builds the package and then runs the tests in `test/`.
90
+
91
+ - `test/cases/*.txt` hold the grammar tests, in [Lezer's test format](https://lezer.codemirror.net/docs/guide/#running-the-grammar).
92
+ - `test/completion.test.ts` checks what the completion offers at a given position.
93
+
94
+ The tests use the built package, because the grammar needs the external tokenizers in `src/tokens.ts`.
95
+
96
+ ## Publishing
97
+
98
+ To publish a new version, set `version` in `package.json` and commit it.
99
+ Then push a tag made of `v` followed by that version, for example `v1.0.0`.
100
+ The tag starts the Publish workflow, which builds and tests the package and publishes it to npm.
101
+ If the tag differs from `version`, the workflow stops before it publishes.