@exercism/codemirror-lang-pyret 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 +98 -2
- package/dist/index.cjs +1056 -0
- package/dist/index.d.cts +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +1048 -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,99 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Pyret language support for CodeMirror
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
This package gives CodeMirror 6 a Lezer grammar for Pyret, with highlighting, indentation, folding and autocomplete.
|
|
6
|
+
Exercism's in-browser editor uses it for the Pyret 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-pyret`
|
|
19
|
+
- Yarn: `yarn add @exercism/codemirror-lang-pyret`
|
|
20
|
+
- Bun: `bun add @exercism/codemirror-lang-pyret`
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import { EditorView, basicSetup } from "codemirror";
|
|
26
|
+
import { pyret } from "@exercism/codemirror-lang-pyret";
|
|
27
|
+
|
|
28
|
+
new EditorView({ extensions: [basicSetup, pyret()], parent: document.body });
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## What the grammar reads
|
|
32
|
+
|
|
33
|
+
The grammar was written from Pyret's own grammar (`pyret-grammar.bnf` in [brownplt/pyret-lang](https://github.com/brownplt/pyret-lang)) and its tokenizer.
|
|
34
|
+
It reads `use`, `import`, `include` and `provide`, functions with `doc:` and `where:`, `data` with variants, `with:` and `sharing:`, `cases`, `if`, `ask`, `when`, `for`, `block:`, `let`, lambdas (`lam` and `{(x): ...}`), methods, objects, tuples, `[list: ...]` constructors, annotations, contracts such as `f :: Number -> Number`, and `check:` and `examples:` blocks with `is`, `raises`, `satisfies` and the other test operators.
|
|
35
|
+
Comments nest, as they do in Pyret.
|
|
36
|
+
|
|
37
|
+
In Pyret, the meaning of `-`, `(` and `<` depends on what comes straight before them. This grammar follows the same rules:
|
|
38
|
+
|
|
39
|
+
- A dash between two name characters is part of the name, so `string-length` and `n-1` are names. `n - 1` is a subtraction.
|
|
40
|
+
- `(` straight after a name or a closing bracket opens an argument list, as in `f(x)`. After a space, `(` opens a new expression, so `f (x)` is two expressions.
|
|
41
|
+
- `<` straight after a name opens type arguments, as in `List<Number>`. With a space before it, as in `a < b`, it compares.
|
|
42
|
+
|
|
43
|
+
Pyret requires brackets when an expression mixes different binary operators, so the grammar gives them all the same precedence.
|
|
44
|
+
The grammar doesn't parse the table operators (`select`, `sieve`, `order`, `extend`, `transform` and `extract`) or `reactor` yet. It does parse `table:` and `row:`.
|
|
45
|
+
|
|
46
|
+
## Completion
|
|
47
|
+
|
|
48
|
+
The completion offers:
|
|
49
|
+
|
|
50
|
+
- the keywords, and snippets for `fun` (with and without `where:`), `lam`, `data`, `cases`, `check`, `for map`, `for each`, `for fold`, `for filter`, `if`, `ask` and `when`.
|
|
51
|
+
- the names provided by `use context essentials2020` and `use context starter2024`, such as `string-length`, `num-modulo`, `map` and `link`, and the built-in types.
|
|
52
|
+
- the members of a module after its name and a dot, as in `lists.` and `sets.`, or `L.` after `import lists as L`. `string-dict` works the same way once it is imported.
|
|
53
|
+
- the methods of lists, sets, options and string dictionaries after any other value and a dot, as in `xs.`, and the fields and methods of the data types declared in the file.
|
|
54
|
+
- the names declared in the file where they are in scope: functions, values, parameters, the names bound by `for`, `cases` and `let`, data types with their variants and `is-` functions, and imported modules.
|
|
55
|
+
|
|
56
|
+
Completion is switched off inside strings and comments.
|
|
57
|
+
It doesn't include the image functions from `starter2024` yet.
|
|
58
|
+
|
|
59
|
+
The built-in names in `src/builtins.ts` are generated from Pyret's library sources.
|
|
60
|
+
To update them, build the package and run `node scripts/generate-builtins.mjs <path to a pyret-lang checkout>`.
|
|
61
|
+
|
|
62
|
+
## Developing
|
|
63
|
+
|
|
64
|
+
Run `bun install` to install the dependencies.
|
|
65
|
+
Then run `bun run dev` to start a [Vite](https://vite.dev/) server, usually at http://localhost:5173/. It serves `index.html`, which has a sample program in the editor.
|
|
66
|
+
|
|
67
|
+
The source files are:
|
|
68
|
+
|
|
69
|
+
```text
|
|
70
|
+
src
|
|
71
|
+
├── index.ts (the language, highlighting, indentation and folding)
|
|
72
|
+
├── syntax.grammar (the Lezer grammar)
|
|
73
|
+
├── tokens.ts (the tokenizers for nested comments, `(`, `<` and `[`)
|
|
74
|
+
├── complete.ts (the completion sources)
|
|
75
|
+
└── builtins.ts (the built-in names, generated by scripts/generate-builtins.mjs)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Building
|
|
79
|
+
|
|
80
|
+
Run `bun run prepare` to build the package into `dist/`.
|
|
81
|
+
It runs Rollup under Bun's runtime, because one of the Rollup plugins doesn't load in recent versions of Node.
|
|
82
|
+
|
|
83
|
+
## Testing
|
|
84
|
+
|
|
85
|
+
Run `bun run test`.
|
|
86
|
+
It builds the package and then runs the tests in `test/`.
|
|
87
|
+
The grammar tests in `test/cases` run against the built parser. The grammar imports the tokenizers in `src/tokens.ts`, and only the build compiles that file.
|
|
88
|
+
|
|
89
|
+
## Publishing
|
|
90
|
+
|
|
91
|
+
To publish a new version, set `version` in `package.json` and commit it.
|
|
92
|
+
Then push a tag made of `v` followed by that version, for example `v1.0.0`.
|
|
93
|
+
The tag starts the Publish workflow, which builds and tests the package and publishes it to npm.
|
|
94
|
+
If the tag differs from `version`, the workflow stops before it publishes.
|
|
95
|
+
|
|
96
|
+
## Licence
|
|
97
|
+
|
|
98
|
+
This package is MIT licensed.
|
|
99
|
+
The grammar follows Pyret's grammar, and the built-in names come from Pyret's library. Both are taken from [brownplt/pyret-lang](https://github.com/brownplt/pyret-lang), which uses the Apache License 2.0.
|