@exercism/codemirror-lang-8th 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 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,84 @@
1
- # Temporary Holding Version
1
+ # 8th language support for CodeMirror
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
+ ![NPM Version](https://img.shields.io/npm/v/@exercism/codemirror-lang-8th)
4
+
5
+ This package gives CodeMirror 6 a Lezer grammar for [8th](https://8th-dev.com/), a Forth-like language, with highlighting, indentation, folding and completion.
6
+ Exercism's editor uses it for the 8th track.
7
+
8
+ ```js
9
+ import { eighth } from "@exercism/codemirror-lang-8th";
10
+
11
+ new EditorView({ extensions: [basicSetup, eighth()] });
12
+ ```
13
+
14
+ The code uses the name `eighth`, because a JavaScript name can't start with a digit.
15
+
16
+ ## Install
17
+
18
+ - npm: `npm install @exercism/codemirror-lang-8th`
19
+ - Yarn: `yarn add @exercism/codemirror-lang-8th`
20
+ - Bun: `bun add @exercism/codemirror-lang-8th`
21
+
22
+ ## What it reads
23
+
24
+ 8th splits its source at whitespace, and so does this grammar.
25
+ An external tokenizer in `src/tokens.ts` reads every token and decides what it is.
26
+ Inside an array or a map it also splits at `,`, `:` and the closing bracket, the way 8th's JSON reader does.
27
+
28
+ The tree has nodes for:
29
+
30
+ - word definitions (`: name \ a -- b ... ;`), with the name in `DefName` and the stack effect in `StackEffect`. The grammar also reads `SED:` stack effects.
31
+ - `var`, `var,`, `constant` and `defer:`, with the name in `VariableName`.
32
+ - `if ... else ... then`, `!if` and `;then` in `Conditional`, and `repeat ... again`, `while`, `while!`, `until` and `until!` in `Loop`.
33
+ - quotations (`( ... )`), arrays (`[ ... ]`) and maps (`{ ... }`), including bare keys such as `{ Mercury: 0.24 }`.
34
+ - words with a namespace (`a:map`), which split into `Namespace` and `Word`, and ticked words (`' s:cmp`).
35
+ - strings, numbers (including `0xff`, `$ff` and `1k`), characters (`'a`), regexes (`/[^[:alpha:] ]+/`), `true`, `false` and `null`.
36
+ - `\` and `--` line comments and `(* ... *)` block comments.
37
+ - `needs`, `ns:` and `with: ... ;with`.
38
+
39
+ The `G:` forms of the structure words, such as `G:if` and `G:(`, work like the plain ones.
40
+ `;:` ends one definition and starts the next.
41
+
42
+ ## Completion
43
+
44
+ - After a namespace such as `a:`, `s:`, `n:` or `m:`, completion offers the words in that namespace, with their stack effects.
45
+ Each word that needs a library lists it in the completion, for example `needs types/set`.
46
+ - Elsewhere it offers the words outside any namespace, the namespaces themselves, and snippets for a word definition, `if ... then`, `if ... else ... then`, `!if`, `;then`, `repeat` loops, `loop`, `times`, `var`, `constant`, `needs` and `with:`.
47
+ It also has snippets for `a:each`, `a:map`, `a:filter`, `a:reduce`, `m:each`, `m:map` and `s:each`.
48
+ - It offers the words, variables and constants defined earlier in the file.
49
+ 8th reads a file once from the top, so a word defined lower down isn't offered.
50
+ A word can call itself, so its own name is offered inside its body.
51
+ - It offers nothing inside strings, regexes, comments and stack effects, or while a new name is being typed.
52
+
53
+ `src/words.ts` lists 8th's words.
54
+ `scripts/extract-words.py` builds it from 8th's [words list](https://8th-dev.com/words.html), and keeps only each word's name, its stack effect and the library it needs.
55
+
56
+ ## Developing
57
+
58
+ Run `bun install` to install the dependencies.
59
+
60
+ - `bun run dev` starts a [Vite](https://vite.dev/) server that shows `index.html` with the grammar.
61
+ - `bun run prepare` builds the package into `dist/`.
62
+ - `bun run test` builds the package and runs the tests.
63
+ The grammar needs the external tokenizer, so the tests use the built parser.
64
+
65
+ The tests are in `test/`:
66
+
67
+ - `test/cases/*.txt` hold the grammar tests, in Lezer's test format.
68
+ - `test/completion.test.ts` checks what completion offers at a given position.
69
+ - `test/editor.test.ts` checks highlighting, indentation and folding.
70
+
71
+ To keep the package working on the Exercism website, don't change the versions of `@codemirror/language`, `@lezer/highlight` and `@lezer/lr`.
72
+
73
+ ## Publishing
74
+
75
+ To publish a new version, set `version` in `package.json` and commit it.
76
+ Then push a tag made of `v` followed by that version, for example `v1.0.0`.
77
+ The tag starts the Publish workflow, which builds and tests the package and publishes it to npm.
78
+ If the tag differs from `version`, the workflow stops before it publishes.
79
+
80
+ ## Resources
81
+
82
+ - [8th](https://8th-dev.com/), and its [manual](https://8th-dev.com/manual.pdf)
83
+ - [CodeMirror](https://codemirror.net/docs/)
84
+ - [Lezer](https://lezer.codemirror.net/docs/guide/)