@exercism/codemirror-lang-powershell 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 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,85 @@
1
- # Temporary Holding Version
1
+ # PowerShell 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-powershell)
4
+
5
+ This package gives the CodeMirror 6 editor a Lezer grammar for PowerShell, with highlighting, indentation, folding and completion.
6
+ It is written for the online editor of Exercism's PowerShell 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-powershell`
19
+ - Yarn: `yarn add @exercism/codemirror-lang-powershell`
20
+ - Bun: `bun add @exercism/codemirror-lang-powershell`
21
+
22
+ ## Usage
23
+
24
+ ```js
25
+ import { EditorView, basicSetup } from "codemirror";
26
+ import { powershell } from "@exercism/codemirror-lang-powershell";
27
+
28
+ new EditorView({
29
+ extensions: [basicSetup, powershell()],
30
+ parent: document.body,
31
+ });
32
+ ```
33
+
34
+ `powershell()` includes the completion.
35
+ The package also exports `powershellLanguage`, the `completion` source on its own, and the lists the completion uses (`keywords`, `cmdlets`, `automaticVariables`, `types`, `operators` and `snippets`).
36
+
37
+ ## What the completion offers
38
+
39
+ - Keywords, common cmdlets such as `Write-Output` and `ForEach-Object`, and snippets for a function with a `param` block, `if`/`elseif`/`else`, `foreach`, `for`, `while`, `do`/`until`, `switch`, `try`/`catch`, `class` and `enum`.
40
+ - Automatic variables such as `$_`, `$PSItem` and `$args`.
41
+ - The functions, variables and parameters declared in the file. A variable assigned inside a function or script block is offered inside that function or block and nowhere else.
42
+ - Types and attributes inside `[`, including the classes and enums declared in the file.
43
+ - After `$this.`, the members of the class. After `[Name]::`, the static members of a class or the members of an enum.
44
+ - Operators such as `-eq` and `-like` after a dash in an expression.
45
+
46
+ It offers nothing inside comments or single-quoted strings.
47
+ Inside a double-quoted string it offers variables after `$`.
48
+
49
+ ## How the grammar reads PowerShell
50
+
51
+ PowerShell reads a line in one of two modes.
52
+ A line that starts with a value (`$x`, `1`, `"a"`, `(...)`, `[int]`) is an expression, and `-eq` is an operator.
53
+ A line that starts with a bare word (`Get-Item`) is a command, and `-Path` is a parameter.
54
+ The grammar follows the same rule.
55
+
56
+ A newline ends a statement wherever the statement can end.
57
+ A line that ends with `|`, `=`, `,` or an operator carries on to the next line, and so does a line that starts with `|`, `else`, `elseif`, `catch` or `finally`.
58
+ `src/tokens.ts` makes these decisions.
59
+
60
+ Keywords and operators are case-insensitive, so `Function`, `IF` and `-EQ` all work.
61
+
62
+ ## Known gaps
63
+
64
+ - The grammar reads a line that starts with an operator, such as `-and`, as a new statement. It doesn't join that line to the one before.
65
+ - A here-string is highlighted as one string, without its `$variables`.
66
+ - The grammar doesn't read a bare word that starts with something other than a letter, such as `.\script.ps1` or `*.txt`, as a command argument.
67
+
68
+ ## Development
69
+
70
+ You need [Bun](https://bun.sh/).
71
+
72
+ - `bun install` installs the dependencies.
73
+ - `bun run test` builds the parser from `src/syntax.grammar` and runs the tests.
74
+ - `bun run prepare` builds the package into `dist/`.
75
+ - `bun run dev` starts a playground at http://localhost:5173/ (run `bun run build:grammar` first).
76
+
77
+ The grammar tests are in `test/cases`, one file per topic.
78
+ Each test gives some PowerShell and the tree it should parse to.
79
+
80
+ ## Publishing
81
+
82
+ To publish a new version, set `version` in `package.json` and commit it.
83
+ Then push a tag made of `v` followed by that version, for example `v1.0.0`.
84
+ The tag starts the Publish workflow, which builds and tests the package and publishes it to npm.
85
+ If the tag differs from `version`, the workflow stops before it publishes.