@exercism/codemirror-lang-yamlscript 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,136 @@
1
- # Temporary Holding Version
1
+ # YAMLScript 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-yamlscript)
4
+
5
+ This repo contains the CodeMirror 6 language support for [YAMLScript](https://yamlscript.org/) (YS), the language taught on [Exercism's YAMLScript track](https://exercism.org/tracks/yamlscript).
6
+ It has a Lezer grammar, highlighting, indentation, folding and autocomplete.
7
+
8
+ ## How the grammar works
9
+
10
+ A YAMLScript file is a YAML document in which the keys and values are code, as in `defn score(x y):` or `if x > 0: 'positive'`.
11
+ So the grammar has two layers:
12
+
13
+ - The external tokenizers in `src/tokens.ts` handle the YAML layer.
14
+ They track indentation, decide which lines are mapping keys (a line with `: ` outside quotes and brackets), and read block scalars and data-mode text.
15
+ - `src/syntax.grammar` describes the YAMLScript code inside keys and values: calls, `.` and `:` chains, infix operators, operator-first lists such as `(+ a b)`, literals and collections.
16
+
17
+ After `::` (or `=::`), a value is data, and plain text such as `north` is a string.
18
+ Another `::` inside data switches back to code.
19
+
20
+ The rules follow Exercism's tree-sitter grammar for YAMLScript, which is used by the representer.
21
+
22
+ ## Autocomplete
23
+
24
+ The completion offers:
25
+
26
+ - the functions in YAMLScript's `ys::std` library, and the `clojure.core` names that can be called from YAMLScript.
27
+ - snippets for `defn`, `defn-`, `fn`, `if`, `when`, `cond`, `each`, `for`, `loop` and `=:`, and the `!YS-v0` header at the start of a file.
28
+ - the functions and bindings defined in the file, where they are in scope.
29
+ Top-level `defn` names and bindings are offered everywhere.
30
+ A function's parameters, the bindings in a block, and the names bound by `loop`, `for`, `each`, `let` and `fn` are offered inside them.
31
+
32
+ Completion switches off inside strings, comments, regular expressions and data-mode text, and while a new function name or parameter is being typed.
33
+
34
+ ## What it doesn't parse yet
35
+
36
+ - YAML flow mappings with `: ` inside braces, such as `{a: 1}`.
37
+ - YAML anchors, aliases and document markers (`---`, `...`).
38
+ - Tags such as `!code` and `!data` parse as tags, and leave the mode as it is. Only `::` switches between code and data.
39
+ - String interpolation (`"$name"`) is part of the string, so names inside strings aren't completed or highlighted.
40
+
41
+ ⚠️ To ensure that the package can be integrated on the Exercism website, don't change the packages' versions:
42
+
43
+ ```json
44
+ "@codemirror/language": "^6.10.1",
45
+ "@lezer/highlight": "^1.2.0",
46
+ "@lezer/lr": "^1.4.0"
47
+ ```
48
+
49
+ ## Install
50
+
51
+ - NPM: `npm install @exercism/codemirror-lang-yamlscript`
52
+ - Yarn: `yarn add @exercism/codemirror-lang-yamlscript`
53
+ - Bun: `bun add @exercism/codemirror-lang-yamlscript`
54
+
55
+ ## Usage
56
+
57
+ ```js
58
+ import { EditorView, basicSetup } from "codemirror";
59
+ import { yamlscript } from "@exercism/codemirror-lang-yamlscript";
60
+
61
+ new EditorView({
62
+ doc: "!YS-v0\n\ndefn square(x): x * x\n",
63
+ extensions: [basicSetup, yamlscript()],
64
+ parent: document.querySelector("#editor"),
65
+ });
66
+ ```
67
+
68
+ ## Prerequisites
69
+
70
+ - [Bun](https://bun.sh/)
71
+
72
+ ## Resources
73
+
74
+ - [CodeMirror](https://codemirror.net/docs/)
75
+ - [Lezer](https://lezer.codemirror.net/docs/guide/)
76
+ - [Writing a Grammar](https://lezer.codemirror.net/docs/guide/#writing-a-grammar)
77
+ - [Examples](https://lezer.codemirror.net/examples/)
78
+ - [Existing grammar files](https://github.com/search?q=org%3Alezer-parser+path%3A%2F.grammar%24%2F&type=code)
79
+
80
+ ## Structure
81
+
82
+ The repo's source files are written in [TypeScript](https://www.typescriptlang.org/).
83
+
84
+ The repo is structured as follows:
85
+
86
+ ```text
87
+ .
88
+ ├── src
89
+ │ ├── index.ts (the main plugin)
90
+ │ ├── complete.ts (the completion sources)
91
+ │ ├── builtins.ts (the ys::std and clojure.core names)
92
+ │ ├── tokens.ts (the tokenizers for the YAML layer)
93
+ │ ├── syntax.grammar (the Lezer grammar)
94
+ │ ├── syntax.grammar.d.ts (the grammar typings)
95
+ │ └── syntax.grammar.terms.d.ts (the typings for the grammar's terms)
96
+ ├── test
97
+ │ ├── cases (test cases)
98
+ │ │ └ *.txt (test case)
99
+ │ ├── grammar.test.ts (the grammar tests)
100
+ │ ├── editor.test.ts (the highlighting, indentation and folding tests)
101
+ │ └── completion.test.ts (the completion tests)
102
+ ├── index.html (dev server file)
103
+ ├── rollup.config.js (bundling config)
104
+ ├── tsconfig.json (TypeScript config)
105
+ └── vite.config.js (vite dev server config)
106
+ ```
107
+
108
+ ## Setup
109
+
110
+ Run `bun install` to install all dependencies.
111
+
112
+ ## Developing
113
+
114
+ To help with development, run `bun run dev`.
115
+ This starts a [Vite](https://vite.dev/) dev server (usually at http://localhost:5173/) that renders the `index.html` file.
116
+ The `#editor` element holds some sample source code of your choosing, which the grammar in `src/syntax.grammar` highlights.
117
+ Any changes to the grammar will auto-refresh the dev server's rendered contents.
118
+
119
+ ## Building
120
+
121
+ Run `bun run prepare` to build the package into `dist`.
122
+ `bun install` also runs this script.
123
+
124
+ ## Testing
125
+
126
+ The `test/cases` directory contains the grammar's test files.
127
+ The grammar uses the tokenizers in `src/tokens.ts`, so the tests use the built parser in `dist/`.
128
+ Run `bun run test` to build the package and run the tests.
129
+
130
+ Note: test (case) files should be relatively small and focus on a single aspect of a grammar.
131
+
132
+ ## Publishing
133
+
134
+ To publish a new version, set `version` in `package.json` and commit it.
135
+ Then push a git tag named `v` followed by that version, such as `v1.0.1` for version 1.0.1.
136
+ The publish workflow builds and tests the package, then publishes it to npm.