@exercism/codemirror-lang-groovy 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/CHANGELOG.md +41 -0
- package/LICENSE +24 -0
- package/README.md +181 -2
- package/dist/index.cjs +764 -0
- package/dist/index.d.cts +38 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +757 -0
- package/package.json +70 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
## 1.0.0
|
|
2
|
+
|
|
3
|
+
This is Exercism's first release of the package, published as
|
|
4
|
+
`@exercism/codemirror-lang-groovy`. It adds completion of keywords, common
|
|
5
|
+
classes, Groovy JDK methods, snippets and the names in scope, and parses a few
|
|
6
|
+
more forms, such as `(a, b) = [b, a]` and `f()(x)`.
|
|
7
|
+
|
|
8
|
+
### New features
|
|
9
|
+
|
|
10
|
+
`groovy()` now has completion. `groovyCompletion` offers keywords, snippets,
|
|
11
|
+
common classes and global functions. After a `.`, `?.` or `*.` it offers only
|
|
12
|
+
the methods called on a value, and after `@` the common annotations.
|
|
13
|
+
|
|
14
|
+
`localCompletionSource` offers the names declared in the file, only where each
|
|
15
|
+
one is in scope. It also completes `$name` and `${...}` inside a string.
|
|
16
|
+
|
|
17
|
+
Snippets for methods, classes, enums, traits, `if`, loops, `switch`, `try`
|
|
18
|
+
and closures are exported as `snippets`.
|
|
19
|
+
|
|
20
|
+
### Bug fixes
|
|
21
|
+
|
|
22
|
+
`(a, b) = [b, a]` assigns to existing variables without `def`.
|
|
23
|
+
|
|
24
|
+
`f()(x)` and `list[0](x)` call the value returned by a call or an index.
|
|
25
|
+
|
|
26
|
+
`?.@` and `*.@` combine direct field access with safe navigation and spread.
|
|
27
|
+
|
|
28
|
+
## 0.1.2 (2026-11-07)
|
|
29
|
+
|
|
30
|
+
### Documentation
|
|
31
|
+
|
|
32
|
+
The README gives the WebJar coordinates, `org.webjars.npm:codemirror-lang-groovy`,
|
|
33
|
+
for Java and Grails applications, and describes how releases are made.
|
|
34
|
+
|
|
35
|
+
## 0.1.1 (2026-11-07)
|
|
36
|
+
|
|
37
|
+
### New features
|
|
38
|
+
|
|
39
|
+
First release: a Lezer grammar for Groovy, derived from `@lezer/java`, with
|
|
40
|
+
CodeMirror 6 language support (highlighting, indentation, folding, comment
|
|
41
|
+
tokens and bracket closing).
|
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2026 by Scott Murphy Heiberg
|
|
4
|
+
|
|
5
|
+
The grammar is derived from @lezer/java:
|
|
6
|
+
Copyright (C) 2020 by Marijn Haverbeke <marijn@haverbeke.berlin> and others
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in
|
|
16
|
+
all copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,182 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @exercism/codemirror-lang-groovy
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This is Exercism's fork of
|
|
4
|
+
[codemirror-lang-groovy](https://github.com/codeconsole/codemirror-lang-groovy),
|
|
5
|
+
written by Scott Murphy Heiberg. Exercism uses it for Groovy in the editor on
|
|
6
|
+
[exercism.org](https://exercism.org). Our changes are on the `exercism` branch,
|
|
7
|
+
and the rest of this README is upstream's, apart from the sections on
|
|
8
|
+
completion, installing and releasing, and the package name.
|
|
9
|
+
|
|
10
|
+
The fork adds:
|
|
11
|
+
|
|
12
|
+
- completion for the names declared in the file (classes, methods, fields,
|
|
13
|
+
parameters, locals, loop and closure variables, script variables and
|
|
14
|
+
imports), offered only where each name is in scope.
|
|
15
|
+
- snippets for methods, classes, enums, traits, `if`, loops, `switch`, `try`
|
|
16
|
+
and closures.
|
|
17
|
+
- completion for keywords, common classes and Groovy JDK methods. After a `.`
|
|
18
|
+
it offers only methods. Inside strings and comments it offers nothing.
|
|
19
|
+
- parsing of `(a, b) = [b, a]`, `f()(x)`, `list[0](x)`, `?.@` and `*.@`.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
Groovy language support for [CodeMirror 6](https://codemirror.net/), built on a
|
|
24
|
+
[Lezer](https://lezer.codemirror.net/) grammar.
|
|
25
|
+
|
|
26
|
+
It replaces the stream-based Groovy mode in `@codemirror/legacy-modes` with a
|
|
27
|
+
real parser. The editor gets a syntax tree, which brings:
|
|
28
|
+
|
|
29
|
+
- highlighting that knows a method call from a variable, a declaration from a
|
|
30
|
+
use, and a map key from a property;
|
|
31
|
+
- syntax-aware indentation and code folding;
|
|
32
|
+
- a tree that other extensions (autocompletion, linting, structural
|
|
33
|
+
navigation) can build on.
|
|
34
|
+
|
|
35
|
+
## Install
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
npm install @exercism/codemirror-lang-groovy
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
import {EditorView, basicSetup} from "codemirror"
|
|
45
|
+
import {groovy} from "@exercism/codemirror-lang-groovy"
|
|
46
|
+
|
|
47
|
+
new EditorView({
|
|
48
|
+
doc: 'println "Hello, Groovy"',
|
|
49
|
+
extensions: [basicSetup, groovy()],
|
|
50
|
+
parent: document.body
|
|
51
|
+
})
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The package exports:
|
|
55
|
+
|
|
56
|
+
- `groovy()`: the `LanguageSupport` to add to an editor;
|
|
57
|
+
- `groovyLanguage`: the `LRLanguage`, for use with other language tooling;
|
|
58
|
+
- `parser`: the Lezer parser on its own, which works without CodeMirror.
|
|
59
|
+
- `groovyCompletion`, `localCompletionSource` and `snippets`: the
|
|
60
|
+
completion that `groovy()` adds (see below).
|
|
61
|
+
|
|
62
|
+
It depends only on `@codemirror/language`, `@codemirror/autocomplete`,
|
|
63
|
+
`@lezer/lr`, `@lezer/highlight` and `@lezer/common`. When loading CodeMirror
|
|
64
|
+
through an import map, map `@exercism/codemirror-lang-groovy` to
|
|
65
|
+
`dist/index.js` alongside those modules.
|
|
66
|
+
|
|
67
|
+
Java and Grails applications can take it from Maven Central as a WebJar,
|
|
68
|
+
`org.webjars.npm:codemirror-lang-groovy`, which serves the bundle at
|
|
69
|
+
`/webjars/codemirror-lang-groovy/<version>/dist/index.js`:
|
|
70
|
+
|
|
71
|
+
```groovy
|
|
72
|
+
runtimeOnly "org.webjars.npm:codemirror-lang-groovy:0.1.1"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Completion
|
|
76
|
+
|
|
77
|
+
`groovy()` registers two completion sources, and both are exported.
|
|
78
|
+
|
|
79
|
+
- `groovyCompletion` offers keywords, snippets, common classes and global
|
|
80
|
+
functions such as `println`. After a `.`, `?.` or `*.` it offers only the
|
|
81
|
+
methods called on a value, such as `collect` and `inject`. After `@` it
|
|
82
|
+
offers common annotations such as `CompileStatic`.
|
|
83
|
+
- `localCompletionSource` offers the names declared in the file. A parameter
|
|
84
|
+
is offered inside its method or closure, a local below the place that
|
|
85
|
+
declares it, a class member anywhere in its class, and a top level
|
|
86
|
+
declaration anywhere in the file. A closure with no parameters offers `it`.
|
|
87
|
+
|
|
88
|
+
Neither source offers anything inside a comment or a name being declared.
|
|
89
|
+
Inside a string, `localCompletionSource` completes `$name` and code in
|
|
90
|
+
`${...}`.
|
|
91
|
+
|
|
92
|
+
## What it parses
|
|
93
|
+
|
|
94
|
+
The grammar starts from `@lezer/java` and adds the parts of Groovy that Java
|
|
95
|
+
lacks:
|
|
96
|
+
|
|
97
|
+
- statements that end at a line break, with Groovy's rules for when the next
|
|
98
|
+
line continues an expression;
|
|
99
|
+
- command calls without parentheses (`println x`, `name nullable: false`)
|
|
100
|
+
and command chains (`id 'groovy' version '4.0' apply false`);
|
|
101
|
+
- closures, including parameters, `it`, `{ -> }` and closures passed after a
|
|
102
|
+
call's arguments;
|
|
103
|
+
- GStrings with `$name.path` and `${...}` interpolation, triple-quoted, slashy
|
|
104
|
+
(`/re/`) and dollar-slashy (`$/.../$`) strings;
|
|
105
|
+
- list and map literals, named arguments and the spread operators;
|
|
106
|
+
- `def`, untyped and default-valued parameters, methods named by strings
|
|
107
|
+
(`def "adds two numbers"()`), traits, records and Groovy 4 switch
|
|
108
|
+
expressions;
|
|
109
|
+
- the operators `?.`, `*.`, `.@`, `.&`, `?:`, `?=`, `**`, `<=>`, `===`,
|
|
110
|
+
`=~`, `==~`, `in`, `!in`, `as`, `!instanceof` and the range operators.
|
|
111
|
+
|
|
112
|
+
Against real code it parses without errors 99.1% of the 8,272 Groovy files in
|
|
113
|
+
`apache/grails-core`, 99.4% of 2,754 files from other Grails projects, and
|
|
114
|
+
562 of 563 Gradle build scripts.
|
|
115
|
+
|
|
116
|
+
## How it handles Groovy's line-sensitive syntax
|
|
117
|
+
|
|
118
|
+
Lezer grammars are context-free, and several parts of Groovy are not. Three
|
|
119
|
+
small tokenizers in `src/tokens.js` cover them, each following the rule
|
|
120
|
+
Groovy's own parser applies (see `GroovyParser.g4` and
|
|
121
|
+
`SemanticPredicates.java` in `apache/groovy`):
|
|
122
|
+
|
|
123
|
+
- **Statement ends.** A zero-width semicolon is inserted at a line break
|
|
124
|
+
unless the next line starts with a token that continues the expression:
|
|
125
|
+
member access (`.`, `?.`), most binary operators, `?`, `:`, assignment, or
|
|
126
|
+
a closure after a call. As in Groovy, a line starting with `+`, `-`, `(` or
|
|
127
|
+
`[` starts a new statement, and a line ending in a comma continues.
|
|
128
|
+
- **Command calls.** `a b` is a command call when the name (or the last
|
|
129
|
+
segment of a dotted name) starts with a lowercase letter and is not
|
|
130
|
+
followed by `name =`; otherwise it is a declaration, as in `String name`.
|
|
131
|
+
- **Blocks and closures.** Where a statement can start, `{` opens a block,
|
|
132
|
+
unless a parameter list and `->` follow it.
|
|
133
|
+
|
|
134
|
+
## Known gaps
|
|
135
|
+
|
|
136
|
+
Rare forms that still produce error nodes:
|
|
137
|
+
|
|
138
|
+
- a command chain that continues after a call with parentheses or a closure,
|
|
139
|
+
as in `foo(a) bar` or `promise.then { } then { }`;
|
|
140
|
+
- `def` combined with a type (`def String name`) and `def final x`;
|
|
141
|
+
- a command call that starts a continuation line (`.insertMany docs, opts`).
|
|
142
|
+
|
|
143
|
+
## Development
|
|
144
|
+
|
|
145
|
+
```sh
|
|
146
|
+
npm install # also builds dist/
|
|
147
|
+
npm run build # regenerate the parser and bundle
|
|
148
|
+
npm test # grammar, highlighting, language and incremental-parsing tests
|
|
149
|
+
npm run corpus -- <dir> [--gradle] [--show 20]
|
|
150
|
+
# parse every .groovy file under <dir> and list failures
|
|
151
|
+
node scripts/parse.js 'println "hi"'
|
|
152
|
+
# print the syntax tree for a snippet
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
`demo/index.html` shows the grammar next to the legacy mode. Build, then
|
|
156
|
+
serve the repository root (for example `python3 -m http.server`) and open
|
|
157
|
+
`/demo/`.
|
|
158
|
+
|
|
159
|
+
`.github/workflows/test.yml` runs the tests on Node 24 for every push to
|
|
160
|
+
`exercism` and every pull request.
|
|
161
|
+
|
|
162
|
+
Test cases live in `test/*.txt` in Lezer's test format.
|
|
163
|
+
`node scripts/fill-tests.js test/<file>.txt` fills in the expected trees from
|
|
164
|
+
the current parser; review every changed tree before committing it.
|
|
165
|
+
|
|
166
|
+
## Releasing
|
|
167
|
+
|
|
168
|
+
1. Update `version` in `package.json` and add a `CHANGELOG.md` entry, then
|
|
169
|
+
commit.
|
|
170
|
+
2. Tag the commit with that version and push the tag:
|
|
171
|
+
`git tag v1.0.0 && git push origin v1.0.0`.
|
|
172
|
+
|
|
173
|
+
Pushing the tag starts `.github/workflows/publish.yml`. The workflow checks that the tag
|
|
174
|
+
matches `package.json`, builds the package and runs the tests. It then publishes the package
|
|
175
|
+
to npm as `@exercism/codemirror-lang-groovy`, using the `exercism` organisation's `NPM_TOKEN`
|
|
176
|
+
secret.
|
|
177
|
+
|
|
178
|
+
## License
|
|
179
|
+
|
|
180
|
+
MIT. The grammar is derived from
|
|
181
|
+
[`@lezer/java`](https://github.com/lezer-parser/java) by Marijn Haverbeke and
|
|
182
|
+
others, also MIT licensed.
|