@exercism/codemirror-lang-vbnet 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,104 @@
1
- # Temporary Holding Version
1
+ # Visual Basic 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-vbnet)
4
+
5
+ This package gives the CodeMirror 6 editor a Lezer grammar for Visual Basic (VB.NET), with highlighting, indentation, folding and autocompletion.
6
+ Exercism uses it in the in-browser editor for the Visual Basic 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-vbnet`
19
+ - Yarn: `yarn add @exercism/codemirror-lang-vbnet`
20
+ - Bun: `bun add @exercism/codemirror-lang-vbnet`
21
+
22
+ ## Usage
23
+
24
+ ```js
25
+ import { EditorView, basicSetup } from "codemirror";
26
+ import { vbnet } from "@exercism/codemirror-lang-vbnet";
27
+
28
+ new EditorView({
29
+ extensions: [basicSetup, vbnet()],
30
+ parent: document.body,
31
+ });
32
+ ```
33
+
34
+ Visual Studio indents Visual Basic by four spaces. To match it, add `indentUnit.of(" ")` from `@codemirror/language` to the editor's extensions.
35
+
36
+ ## What it does
37
+
38
+ - It reads modules, classes, structures, interfaces, enums, namespaces, subs, functions, properties (with or without Get and Set blocks), operators, fields and attributes.
39
+ - It reads every statement block (If, Select Case, For, For Each, While, Do, Try, With, Using, SyncLock), single-line Ifs, lambdas on one line or many, LINQ queries, object and collection initializers, tuples, interpolated strings and generics.
40
+ - It highlights keywords, strings, numbers, comments, declarations, calls, types and operators.
41
+ - It indents the lines inside a block, lines up `End`, `Else`, `Case`, `Catch` and `Next` with the line that opened the block, and folds every block.
42
+ - Its autocompletion offers:
43
+ - keywords, and snippets for Module, Class, Structure, Enum, Interface, Function, Sub, Sub New, Property, If, ElseIf, For, For Each, While, Do, Select Case, Try, Using, a lambda, Imports and Throw.
44
+ - the types written as keywords, such as `Integer` and `String`, common .NET types such as `List`, `Dictionary` and `StringBuilder`, and Visual Basic's own functions, such as `CInt` and `Len`.
45
+ - common .NET members after a dot, such as `WriteLine`, `Select` and `ToString`.
46
+ - the members of the enclosing type after `Me.`, and an enum's members after its name, as in `Colour.Red`.
47
+ - the names declared in the file that are in scope at the cursor: types, the members of the enclosing type, parameters, locals, loop variables and lambda parameters.
48
+
49
+ ## How the grammar reads lines and words
50
+
51
+ A Visual Basic statement ends at the end of its line. If the line clearly carries on, the statement continues on the next line.
52
+ The newline tokenizer in `src/tokens.ts` decides what each line break means:
53
+
54
+ - If the grammar can end a statement at the line break, the line break ends it.
55
+ - Anywhere else, such as after a comma, an operator, a dot or an open bracket, the line break is skipped like a space. This is Visual Basic's implicit line continuation.
56
+ - If the next line starts a query clause such as `Where` or `Select`, and the grammar is in a query, the line break is skipped too.
57
+ - If the next line starts a property's `Get` or `Set`, the line break starts the property's body.
58
+
59
+ A ` _` at the end of a line is always skipped.
60
+
61
+ Visual Basic keywords ignore case, and many of them can also be names, such as `Text`, `Key` or `random.Next`.
62
+ The word tokenizer in the same file reads a word as a keyword where the grammar can use that keyword.
63
+ Elsewhere, an unreserved keyword such as `Text`, and any keyword after a dot, is read as a name.
64
+ The tokenizer also tells the `If(a, b, c)` operator apart from an `If` statement, and reads `(Of` as the start of a list of type arguments.
65
+
66
+ ## Prerequisites
67
+
68
+ - [Bun](https://bun.sh/)
69
+
70
+ ## Setup
71
+
72
+ Run `bun install` to install all dependencies.
73
+
74
+ ## Developing
75
+
76
+ To help with development, run `bun run dev`.
77
+ This starts a [Vite](https://vite.dev/) dev server (usually at http://localhost:5173/) that renders `index.html` with some sample Visual Basic code.
78
+
79
+ The grammar is in `src/syntax.grammar`, the tokenizers are in `src/tokens.ts`, and the completion is in `src/complete.ts`.
80
+ If `src/tokens.ts` starts to use another term by name, add it to `src/syntax.grammar.terms.d.ts`.
81
+
82
+ ## Building
83
+
84
+ Run `bun run prepare` to build the package into `dist`.
85
+ `bun install` also runs this script.
86
+
87
+ ## Testing
88
+
89
+ Run `bun run test`. It builds the package and then runs the tests in `test/`.
90
+
91
+ - `test/cases/*.txt` hold the grammar tests, in [Lezer's test format](https://lezer.codemirror.net/docs/guide/#running-the-grammar).
92
+ - `test/completion.test.ts` checks what the completion offers at a given position.
93
+ - `test/editor.test.ts` checks highlighting, indentation and folding.
94
+
95
+ ## Resources
96
+
97
+ - [CodeMirror](https://codemirror.net/docs/)
98
+ - [Lezer](https://lezer.codemirror.net/docs/guide/)
99
+
100
+ ## Publishing
101
+
102
+ To publish a new version, set `version` in `package.json` and commit it.
103
+ Then push a git tag named `v` followed by that version, such as `v1.0.1` for version 1.0.1.
104
+ The publish workflow builds and tests the package, then publishes it to npm.