@exercism/codemirror-lang-rescript 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,13 @@
1
+ ## 1.0.0
2
+
3
+ This is Exercism's first release of the package, published as
4
+ `@exercism/codemirror-lang-rescript`. It adds CodeMirror support through
5
+ `rescript()`, with highlighting, indentation, folding and completion, and parses
6
+ `%` as the remainder operator, value signatures at the top level and the spread
7
+ in a list pattern.
8
+
9
+ ## 0.1.0 (2025-10-24)
10
+
11
+ ### New Features
12
+
13
+ First documented release.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (C) 2018 by Marijn Haverbeke <marijn@haverbeke.berlin> 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,131 @@
1
- # Temporary Holding Version
1
+ # rescript-lezer
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 a ReScript grammar for the
4
+ [lezer](https://lezer.codemirror.net/) parser system.
5
+
6
+ ## Exercism's fork
7
+
8
+ This branch is Exercism's fork of [tsnobip/rescript-lezer](https://github.com/tsnobip/rescript-lezer), by tsnobip.
9
+ It is published as `@exercism/codemirror-lang-rescript` and powers ReScript in the editor on [exercism.org](https://exercism.org).
10
+ Upstream's `main` stays as it is, and our work is on the `exercism` branch.
11
+
12
+ Install it with:
13
+
14
+ ```bash
15
+ npm install @exercism/codemirror-lang-rescript
16
+ ```
17
+
18
+ The package keeps upstream's `parser` export and adds CodeMirror 6 support:
19
+
20
+ ```js
21
+ import {rescript} from "@exercism/codemirror-lang-rescript"
22
+
23
+ new EditorView({extensions: [basicSetup, rescript()], parent: document.body})
24
+ ```
25
+
26
+ `rescript()` gives highlighting, indentation, folding and completion. Completion offers:
27
+
28
+ - keywords, global functions such as `ignore`, the standard library's module names, and constructors such as `Some` and `Ok`.
29
+ - snippets for `let`, functions, `switch`, `if` and `if`/`else`, record and variant types, `module`, `for`, `while` and `try`.
30
+ - the functions in each standard library module after its name and a dot, as in `Array.`, `String.`, `List.`, `Option.`, `Int.` and `Belt.Map.Int.`. Each one shows its type. After `open Belt`, `Array.` offers Belt.Array's functions too.
31
+ - the names defined in the file (bindings, parameters, pattern variables, types, constructors and modules), where they are in scope. After a module defined in the file and a dot, it offers that module's names.
32
+ - built-in and file-defined types inside a type annotation.
33
+
34
+ `src/builtins.js` lists the standard library's functions. `scripts/generate-builtins.mjs` writes it from the interface files in the `@rescript/runtime` package. To update it, install that package without saving it, then run:
35
+
36
+ ```bash
37
+ npm install --no-save @rescript/runtime@12
38
+ npm run build
39
+ npm run builtins -- node_modules/@rescript/runtime/lib/ocaml
40
+ ```
41
+
42
+ The fork also changes the grammar so that it parses all of the ReScript track's example solutions:
43
+
44
+ - `%` between two expressions is the remainder operator, as in ReScript 12.
45
+ - Value signatures such as `let keep: array<int> => array<int>` can appear at the top level. Exercism's editor uses one language for both `.res` and `.resi` files.
46
+ - In `list{first, ...rest}`, `rest` is a binding.
47
+
48
+ To parse a single expression instead of a full program, set the `top` option to `"SingleExpression"`.
49
+
50
+ ## Building and testing
51
+
52
+ Run `npm install`, which also builds the package into `dist/`. Run `npm run build` to rebuild it and `npm test` to run the tests.
53
+
54
+ ## Grammar Audit
55
+
56
+ Use the audit script to find remaining grammar bugs against the official ReScript parser.
57
+
58
+ The compiler and corpus are pinned in the `vendored/rescript` Git submodule.
59
+ Initialize it once, then build the parser comparator with ReScript's OCaml/dune
60
+ dependencies installed (see its `CONTRIBUTING.md`):
61
+
62
+ ```bash
63
+ git submodule update --init vendored/rescript
64
+ cd vendored/rescript
65
+ dune build compiler/bsc/rescript_compiler_main.exe
66
+ cd ../..
67
+ ```
68
+
69
+ ### Quick run
70
+
71
+ ```bash
72
+ npm install --no-save @rescript/runtime@12
73
+ npm run build
74
+ npm run audit:grammar
75
+ ```
76
+
77
+ ### Corpus regression check
78
+
79
+ ```bash
80
+ npm run test:corpus
81
+ ```
82
+
83
+ This checks the syntax fixtures, runtime packages, and scripts in the pinned
84
+ checkout. It also compares fresh and incremental trees across 1,000 reproducible edits.
85
+ It fails on compiler-valid parse errors, incremental mismatches, or crashes.
86
+ Compiler-rejected fixtures remain visible in the full differential audit.
87
+
88
+ Upstream's GitHub Actions run this corpus check on pushes and pull requests.
89
+ On the `exercism` branch, `.github/workflows/test.yml` runs only `npm test`.
90
+
91
+ ### Strict agreement
92
+
93
+ ```bash
94
+ npm run audit:grammar:strict
95
+ ```
96
+
97
+ ### Custom run
98
+
99
+ ```bash
100
+ node scripts/audit-grammar.mjs \
101
+ --mode all \
102
+ --max-files 10000 \
103
+ --fuzz-cases 500 \
104
+ --incremental-cases 300 \
105
+ --include-idempotency \
106
+ --report /tmp/rescript-lezer-audit.json
107
+ ```
108
+
109
+ ### What it checks
110
+
111
+ - Differential parse agreement vs ReScript (`-only-parse`) on upstream corpus files
112
+ - Mutation fuzzing with mismatch detection
113
+ - Incremental parse consistency (incremental tree vs fresh parse)
114
+
115
+ `--corpus` adds directories to the default corpus. Reports include error positions
116
+ and the full source and edit for reproducing fuzz and incremental failures. Use a fixed
117
+ `--seed` to reproduce edits, and `--rescript-root` or `RESCRIPT_ROOT` to compare
118
+ against another compiler checkout.
119
+
120
+ ## Publishing
121
+
122
+ To release from the `exercism` branch, set `version` in `package.json` and push a tag of the same version:
123
+
124
+ ```bash
125
+ npm version patch # or minor / major
126
+ git push origin HEAD --follow-tags
127
+ ```
128
+
129
+ `npm version` updates the package and lockfile, commits the change, and creates the version tag. The tag starts `.github/workflows/publish.yml`. The workflow checks that the tag matches `package.json`, builds and tests the package, and publishes it to npm as `@exercism/codemirror-lang-rescript`, using the `exercism` organisation's `NPM_TOKEN` secret.
130
+
131
+ The code is licensed under an MIT license.