@exercism/codemirror-lang-futhark 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 +21 -0
- package/README.md +127 -2
- package/dist/index.cjs +615 -0
- package/dist/index.d.cts +23 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +605 -0
- package/package.json +51 -4
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,128 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Futhark language support for CodeMirror
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
This package gives the CodeMirror 6 editor a Lezer grammar for Futhark, with highlighting, indentation, folding and autocompletion.
|
|
6
|
+
Exercism uses it in the in-browser editor for the Futhark track.
|
|
7
|
+
|
|
8
|
+
⚠️ Keep the versions of these dependencies as they are, so that the package works on the Exercism website:
|
|
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-futhark`
|
|
19
|
+
- Yarn: `yarn add @exercism/codemirror-lang-futhark`
|
|
20
|
+
- Bun: `bun add @exercism/codemirror-lang-futhark`
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import { EditorView, basicSetup } from "codemirror";
|
|
26
|
+
import { futhark } from "@exercism/codemirror-lang-futhark";
|
|
27
|
+
|
|
28
|
+
new EditorView({
|
|
29
|
+
extensions: [basicSetup, futhark()],
|
|
30
|
+
parent: document.body,
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## What it does
|
|
35
|
+
|
|
36
|
+
- It highlights keywords, strings, characters, numbers, comments, attributes, definitions, function calls, types, constructors, record fields and operators.
|
|
37
|
+
- It indents a new line under `=`, `->`, `then`, `else`, `do`, `in`, an open bracket or a trailing operator.
|
|
38
|
+
It lines `in` up with its `let`, `then` and `else` with their `if`, and `case` with its `match`.
|
|
39
|
+
- It folds declarations, `let`, `if`, `loop` and `match` expressions, lambdas, modules, records, tuples and arrays.
|
|
40
|
+
- Its autocompletion offers:
|
|
41
|
+
- keywords, and snippets for `def`, `entry`, `let ... in`, `loop` with `for i < n`, `for x in xs` and `while`, `if ... then ... else`, `match`, a lambda, `type` and `module`.
|
|
42
|
+
- the prelude's functions, such as `map`, `reduce`, `scan`, `filter`, `iota`, `zip` and `length`, and the primitive types.
|
|
43
|
+
- a numeric module's functions after its name and a dot, such as `i32.sum` or `f64.sqrt`.
|
|
44
|
+
- the names declared in the file that are in scope at the cursor. These are the definitions above it, the parameters of the function it is in, and the names bound by `let`, `loop`, `case` and lambdas around it.
|
|
45
|
+
- record field names after a dot, as in `queen.row`, and constructors after a `#`.
|
|
46
|
+
|
|
47
|
+
## How the grammar reads Futhark
|
|
48
|
+
|
|
49
|
+
Futhark has no layout rule, so the grammar reads a file as a run of declarations.
|
|
50
|
+
An `if`, `let`, `loop`, `match` or lambda extends as far as it can.
|
|
51
|
+
|
|
52
|
+
Two things need the tokenizer in `src/tokens.ts`.
|
|
53
|
+
|
|
54
|
+
- A `[` straight after a name or a closing bracket indexes an array, as in `xs[i]`.
|
|
55
|
+
A `[` after a space starts an array literal, so `f [1, 2]` passes an array to `f`.
|
|
56
|
+
- An operator is any run of operator characters, such as `+`, `|>` or a user's own `+++`.
|
|
57
|
+
It takes its precedence from its first characters, as Futhark's parser does.
|
|
58
|
+
|
|
59
|
+
## Prerequisites
|
|
60
|
+
|
|
61
|
+
- [Bun](https://bun.sh/)
|
|
62
|
+
|
|
63
|
+
## Resources
|
|
64
|
+
|
|
65
|
+
- [CodeMirror](https://codemirror.net/docs/)
|
|
66
|
+
- [Lezer](https://lezer.codemirror.net/docs/guide/)
|
|
67
|
+
- [Writing a Grammar](https://lezer.codemirror.net/docs/guide/#writing-a-grammar)
|
|
68
|
+
- [Examples](https://lezer.codemirror.net/examples/)
|
|
69
|
+
- [Existing grammar files](https://github.com/search?q=org%3Alezer-parser+path%3A%2F.grammar%24%2F&type=code)
|
|
70
|
+
|
|
71
|
+
## Structure
|
|
72
|
+
|
|
73
|
+
The repo's source files are written in [TypeScript](https://www.typescriptlang.org/).
|
|
74
|
+
|
|
75
|
+
The repo is structured as follows:
|
|
76
|
+
|
|
77
|
+
```text
|
|
78
|
+
.
|
|
79
|
+
├── src
|
|
80
|
+
│ ├── index.ts (the language, highlighting, indentation and folding)
|
|
81
|
+
│ ├── complete.ts (the autocompletion)
|
|
82
|
+
│ ├── prelude.ts (the names Futhark's prelude puts in scope)
|
|
83
|
+
│ ├── tokens.ts (the tokenizer for index brackets and operators)
|
|
84
|
+
│ ├── syntax.grammar (the Lezer grammar)
|
|
85
|
+
│ ├── syntax.grammar.d.ts (the grammar typings)
|
|
86
|
+
│ └── syntax.grammar.terms.d.ts (the typings for the tokenizer's terms)
|
|
87
|
+
├── test
|
|
88
|
+
│ ├── cases (grammar test cases)
|
|
89
|
+
│ │ └ *.txt (test case)
|
|
90
|
+
│ ├── grammar.test.ts (grammar tests)
|
|
91
|
+
│ ├── completion.test.ts (completion tests)
|
|
92
|
+
│ └── editor.test.ts (highlighting, indentation and folding tests)
|
|
93
|
+
├── index.html (dev server file)
|
|
94
|
+
├── rollup.config.js (bundling config)
|
|
95
|
+
├── tsconfig.json (typescript config)
|
|
96
|
+
└── vite.config.js (vite dev server config)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Setup
|
|
100
|
+
|
|
101
|
+
Run `bun install` to install all dependencies.
|
|
102
|
+
|
|
103
|
+
## Developing
|
|
104
|
+
|
|
105
|
+
To help with development, run `bun run dev`.
|
|
106
|
+
This starts a [Vite](https://vite.dev/) dev server (usually at http://localhost:5173/) that renders `index.html`.
|
|
107
|
+
The `#editor` element holds some sample source code, which you can change, and the grammar in `src/syntax.grammar` highlights it.
|
|
108
|
+
Any change to the grammar refreshes the page.
|
|
109
|
+
|
|
110
|
+
## Building
|
|
111
|
+
|
|
112
|
+
Run `bun run prepare` to build the package into `dist/`.
|
|
113
|
+
It runs Rollup under Bun's runtime, because one of the Rollup plugins doesn't load in recent versions of Node.
|
|
114
|
+
|
|
115
|
+
## Testing
|
|
116
|
+
|
|
117
|
+
The `test/cases` directory holds the grammar tests, and `test/completion.test.ts` and `test/editor.test.ts` test the completion, highlighting, indentation and folding.
|
|
118
|
+
The grammar uses the tokenizer in `src/tokens.ts`, so the tests use the built package.
|
|
119
|
+
Run `bun run test` to build it and run the tests.
|
|
120
|
+
|
|
121
|
+
Keep each test case file small and focused on one aspect of the grammar.
|
|
122
|
+
|
|
123
|
+
## Publishing
|
|
124
|
+
|
|
125
|
+
To publish a new version, set `version` in `package.json` and commit it.
|
|
126
|
+
Then push a tag made of `v` followed by that version, for example `v1.0.0`.
|
|
127
|
+
The tag starts the Publish workflow, which builds and tests the package and publishes it to npm.
|
|
128
|
+
If the tag differs from `version`, the workflow stops before it publishes.
|