@exercism/codemirror-lang-purescript 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/LICENSE +22 -0
- package/README.md +107 -2
- package/dist/index.cjs +1010 -0
- package/dist/index.d.cts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +1002 -0
- package/package.json +51 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2024 by Erik Schierboom <erik_schierboom@hotmail.com> and others
|
|
4
|
+
Copyright (c) 2026 CodinCod (the Haskell grammar that this grammar is adapted from)
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
|
14
|
+
all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,108 @@
|
|
|
1
|
-
#
|
|
1
|
+
# PureScript language support for CodeMirror
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
This package gives the [CodeMirror 6](https://codemirror.net/) editor a [Lezer](https://lezer.codemirror.net/) grammar for PureScript, with highlighting, folding, indentation and autocompletion.
|
|
6
|
+
Exercism uses it in the in-browser editor for the PureScript 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-purescript`
|
|
19
|
+
- Yarn: `yarn add @exercism/codemirror-lang-purescript`
|
|
20
|
+
- Bun: `bun add @exercism/codemirror-lang-purescript`
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import { EditorView, basicSetup } from "codemirror";
|
|
26
|
+
import { purescript } from "@exercism/codemirror-lang-purescript";
|
|
27
|
+
|
|
28
|
+
new EditorView({
|
|
29
|
+
doc: "main = log \"Hello\"",
|
|
30
|
+
extensions: [basicSetup, purescript()],
|
|
31
|
+
parent: document.body,
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## What it supports
|
|
36
|
+
|
|
37
|
+
The grammar reads modules, imports and exports, functions with signatures and guards, `where`, `let`, `do`, `ado`, `case` (including several values at once), `if`, lambdas, operator sections and backtick operators.
|
|
38
|
+
It also reads data types, newtypes, type synonyms, kind signatures, classes, instances and instance chains, derived instances, foreign imports and fixity declarations.
|
|
39
|
+
For records, it reads literals, puns, patterns, updates, field access such as `p.name` and accessor sections such as `_.name`.
|
|
40
|
+
In types, it reads rows, open records, `forall`, constraints and the Unicode spellings of `::`, `->`, `<-`, `=>` and `forall`.
|
|
41
|
+
|
|
42
|
+
PureScript uses indentation to open and close blocks. The tokenizer in `src/tokens.ts` follows the indentation and tells the grammar where each block opens, where each item starts and where each block ends.
|
|
43
|
+
|
|
44
|
+
Completion offers:
|
|
45
|
+
|
|
46
|
+
- the keywords
|
|
47
|
+
- snippets for functions, guards, `case`, `if`, `let`, `where`, `do`, lambdas, folds, data types, newtypes, records, classes, instances, imports and the module header
|
|
48
|
+
- the names exported by Prelude, and the common functions, types and constructors from modules such as `Data.Array`, `Data.Maybe`, `Data.String`, `Data.Tuple`, `Data.Map` and `Effect.Console`
|
|
49
|
+
- the names declared in the file that are in scope at the cursor, such as functions, types, constructors, parameters, pattern variables, and bindings from `let`, `where`, `do` and `ado`
|
|
50
|
+
- record field names from the file after a dot
|
|
51
|
+
|
|
52
|
+
It offers nothing inside strings and comments.
|
|
53
|
+
|
|
54
|
+
## Credits
|
|
55
|
+
|
|
56
|
+
The grammar and the layout tokenizer are adapted from [codemirror-lang-haskell](https://codeberg.org/reeven/codemirror-lang-haskell) by CodinCod, which is released under the MIT licence.
|
|
57
|
+
|
|
58
|
+
## Prerequisites
|
|
59
|
+
|
|
60
|
+
- [Bun](https://bun.sh/)
|
|
61
|
+
|
|
62
|
+
## Structure
|
|
63
|
+
|
|
64
|
+
```text
|
|
65
|
+
.
|
|
66
|
+
├── src
|
|
67
|
+
│ ├── index.ts (the language support: highlighting, folding and indentation)
|
|
68
|
+
│ ├── complete.ts (the completion sources and snippets)
|
|
69
|
+
│ ├── syntax.grammar (the Lezer grammar)
|
|
70
|
+
│ ├── tokens.ts (the layout, comment, record and name tokenizers)
|
|
71
|
+
│ └── syntax.grammar*.d.ts (the grammar typings)
|
|
72
|
+
├── test
|
|
73
|
+
│ ├── cases (grammar test cases)
|
|
74
|
+
│ ├── grammar.test.ts (runs the grammar test cases)
|
|
75
|
+
│ ├── complete.test.ts (completion tests)
|
|
76
|
+
│ └── editor.test.ts (folding, indentation and highlighting tests)
|
|
77
|
+
├── index.html (dev server file)
|
|
78
|
+
├── rollup.config.js (bundling config)
|
|
79
|
+
├── tsconfig.json (TypeScript config)
|
|
80
|
+
└── vite.config.js (Vite dev server config)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Setup
|
|
84
|
+
|
|
85
|
+
Run `bun install` to install all dependencies.
|
|
86
|
+
|
|
87
|
+
## Developing
|
|
88
|
+
|
|
89
|
+
Run `bun run dev` to start a [Vite](https://vite.dev/) dev server, usually at http://localhost:5173/.
|
|
90
|
+
It shows `index.html`, which loads some sample PureScript into an editor that uses this package.
|
|
91
|
+
The page reloads when the grammar changes.
|
|
92
|
+
|
|
93
|
+
## Building
|
|
94
|
+
|
|
95
|
+
Run `bun run prepare` to build the package into `dist/`.
|
|
96
|
+
It runs Rollup under Bun's runtime, because one of the Rollup plugins doesn't load in recent versions of Node.
|
|
97
|
+
|
|
98
|
+
## Testing
|
|
99
|
+
|
|
100
|
+
Run `bun run test`. It builds the package and then runs the tests, because the grammar tests use the built parser.
|
|
101
|
+
Each file in `test/cases` holds grammar test cases. Keep each case small and about one feature.
|
|
102
|
+
|
|
103
|
+
## Publishing
|
|
104
|
+
|
|
105
|
+
To publish a new version, set `version` in `package.json` and commit it.
|
|
106
|
+
Then push a tag made of `v` followed by that version, for example `v1.0.0`.
|
|
107
|
+
The tag starts the Publish workflow, which builds and tests the package and publishes it to npm.
|
|
108
|
+
If the tag differs from `version`, the workflow stops before it publishes.
|