@exercism/codemirror-lang-sml 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 +21 -0
- package/README.md +81 -2
- package/dist/index.cjs +609 -0
- package/dist/index.d.cts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +601 -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,82 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Standard ML language support for CodeMirror
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
This package gives CodeMirror 6 a Lezer grammar for Standard ML (SML '97), with highlighting, indentation, folding and autocomplete.
|
|
6
|
+
Exercism's in-browser editor uses it for the Standard ML track.
|
|
7
|
+
|
|
8
|
+
⚠️ To ensure that the package can be integrated on the Exercism website, don't change the packages' versions:
|
|
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-sml`
|
|
19
|
+
- Yarn: `yarn add @exercism/codemirror-lang-sml`
|
|
20
|
+
- Bun: `bun add @exercism/codemirror-lang-sml`
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import { EditorView, basicSetup } from "codemirror";
|
|
26
|
+
import { sml } from "@exercism/codemirror-lang-sml";
|
|
27
|
+
|
|
28
|
+
new EditorView({ extensions: [basicSetup, sml()], parent: document.body });
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## What the grammar reads
|
|
32
|
+
|
|
33
|
+
The grammar reads the core language and the module language: values, functions with several clauses, datatypes, exceptions, `local`, `let`, `case`, `fn`, `handle`, records, structures, signatures and functors.
|
|
34
|
+
Comments nest, as they do in SML.
|
|
35
|
+
|
|
36
|
+
SML lets a program declare its own infix operators, and a grammar can't follow those declarations.
|
|
37
|
+
So the grammar reads every symbolic name (`+`, `::`, `@`, `|>`) and the words `div`, `mod`, `o` and `before` as infix operators, all with the same precedence.
|
|
38
|
+
If a program declares a word such as `add` as infix, the grammar will read `a add b` as a function call.
|
|
39
|
+
|
|
40
|
+
## Completion
|
|
41
|
+
|
|
42
|
+
The completion offers:
|
|
43
|
+
|
|
44
|
+
- the keywords, and snippets for `fun`, `val`, `let`, `case`, `if`, `fn`, `datatype`, `structure`, `signature` and `local`.
|
|
45
|
+
- the names that every program can use without a structure, such as `print`, `map`, `SOME` and `Fail`.
|
|
46
|
+
- the members of a Basis Library structure after its name and a dot, as in `List.` or `String.`, and the members of a structure declared in the file.
|
|
47
|
+
- the names declared in the file where they are in scope: functions, values, parameters, the variables bound by patterns, datatypes, constructors, exceptions and structures. After `open List`, the members of `List` are offered without the prefix.
|
|
48
|
+
|
|
49
|
+
Completion switches off inside strings and comments.
|
|
50
|
+
|
|
51
|
+
## Developing
|
|
52
|
+
|
|
53
|
+
Run `bun install` to install the dependencies.
|
|
54
|
+
Then run `bun run dev` to start a [Vite](https://vite.dev/) server (usually at http://localhost:5173/), which shows `index.html` with a sample program in the editor.
|
|
55
|
+
|
|
56
|
+
The source files are:
|
|
57
|
+
|
|
58
|
+
```text
|
|
59
|
+
src
|
|
60
|
+
├── index.ts (the language, highlighting, indentation and folding)
|
|
61
|
+
├── syntax.grammar (the Lezer grammar)
|
|
62
|
+
├── tokens.ts (the tokenizer for nested comments)
|
|
63
|
+
├── complete.ts (the completion sources)
|
|
64
|
+
└── basis.ts (the Basis Library names)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Building
|
|
68
|
+
|
|
69
|
+
Run `bun run prepare` to build the package into `dist`.
|
|
70
|
+
`bun install` also runs this script.
|
|
71
|
+
|
|
72
|
+
## Testing
|
|
73
|
+
|
|
74
|
+
Run `bun run test`.
|
|
75
|
+
It builds the package and then runs the tests in `test/`.
|
|
76
|
+
The grammar tests in `test/cases` use the built parser, because the grammar needs the tokenizer in `src/tokens.ts`.
|
|
77
|
+
|
|
78
|
+
## Publishing
|
|
79
|
+
|
|
80
|
+
To publish a new version, set `version` in `package.json` and commit it.
|
|
81
|
+
Then push a git tag named `v` followed by that version, such as `v1.0.1` for version 1.0.1.
|
|
82
|
+
The publish workflow builds and tests the package, then publishes it to npm.
|