codemirror-lang-raku 0.1.0 → 0.3.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 CHANGED
@@ -1,3 +1,89 @@
1
+ ## 0.3.0 (2026-10-07)
2
+
3
+ ### Breaking changes
4
+
5
+ - A pair of a quote's own delimiters inside it, as the `[b]` of
6
+ `qq[a [b] c]`, is a `NestedDelimiters` node in the `StringLiteral`.
7
+ It was text without a node.
8
+
9
+ ### Bug fixes
10
+
11
+ - After an edit in a long quote that interpolates and has bracket
12
+ delimiters (`qq[…]`), the text after a nested `[` could be read as if
13
+ the quote had ended, and every further edit parsed the quote again
14
+ from its start.
15
+ - In such a quote, a `[…]` or `(…)` right after a nested pair of
16
+ delimiters is text, not a subscript or a call: `qq[a [b](c)]`.
17
+ - After an edit, the text of a heredoc could be read as code when a long
18
+ quote that interpolates and spans several lines followed the opener
19
+ of the heredoc on its line.
20
+
21
+ ## 0.2.0 (2026-10-07)
22
+
23
+ ### New features
24
+
25
+ - Regexes are highlighted inside: the literals `/…/`, `rx/…/`, `m/…/` and
26
+ the pattern of `s/…/…/`, and the body of a `token`, `rule` or `regex`
27
+ declaration. A `Regex` node has children for character classes (`CharacterClass`),
28
+ `<…>` assertions (`Assertion`), quoted literals, escapes, quantifiers
29
+ and anchors, variables, comments, and the blocks of code in it, which
30
+ are read as code.
31
+ - `multi foo(…) { }`, `proto foo(…) {*}` and `only foo(…) { }`, without the
32
+ word `sub`, are `RoutineDeclaration` nodes with a `RoutineName`. The
33
+ node has no declarator keyword, and `multi` is the node before it.
34
+ - Pod blocks have child nodes for their directives (`PodDirective`),
35
+ headings (`PodHeading`) and formatting codes (`PodStrong`,
36
+ `PodEmphasis`, `PodCode`, `PodLink`, `PodFormat`), which are highlighted.
37
+ - Variables, blocks and escapes are interpolated in the text of a
38
+ `qq:to` heredoc. Its `Heredoc` node has the children of a string that
39
+ interpolates.
40
+ - Variables, blocks and escapes are interpolated in `<<…>>` and `«…»`
41
+ word lists. Such a list can hold code over several lines, and can be
42
+ a subscript: `%h«$key»`, `:a<<b $c>>`.
43
+ - Completion offers the names that the document declares: the variables
44
+ and attributes in scope, routines, classes, enums, subsets and
45
+ constants, and after a `.` the methods.
46
+ - Completion also offers placeholder variables (`$^a`) in their block,
47
+ and variables without a sigil (`my \x`).
48
+ - A line that starts with a trait, as in `is export {` under
49
+ `sub f($a)`, is indented as the continuation of its statement.
50
+ - Toggling a block comment picks brackets that fit the selection:
51
+ `` #`[ … ] `` when the selection holds an unbalanced parenthesis, and so
52
+ on. A comment is removed whichever bracket it was written with.
53
+ - A line that continues a statement is indented one unit further: after
54
+ a line that ends in an operator or a comma, and when it starts with a
55
+ method call or an infix operator.
56
+ - The adverbs of a quote that switch kinds of interpolation on and off
57
+ are taken into account: `q:c{…}` interpolates blocks, `qq:!s[…]` does
58
+ not interpolate `$` variables. This covers `:c`, `:s`, `:a`, `:h`, `:f`,
59
+ `:b`, `:qq`, `:q` and their long names.
60
+ - An operator referred to as a routine, as in `&infix:<+>`, is a single
61
+ `VariableName`. Operator names can also be written as `circumfix:<[ ]>`
62
+ and `infix:['+']`.
63
+ - `q`, `qq`, `Q` and their variants take a bracket after blanks: `q {…}`,
64
+ `qw <a b>`.
65
+ - An adverb with an argument that is `False` or `0` is switched off:
66
+ `qq:c(False)[…]`.
67
+
68
+ ### Bug fixes
69
+
70
+ - A regex with bracket delimiters no longer ends at the `]` of a
71
+ character class in it: `rx[ <[a..z]> ]`.
72
+ - `multi foo`, `proto foo` and `only foo` declare a sub also when the
73
+ signature or the body starts on the next line.
74
+ - A long comment right after a type name (`my Foo # …`) no longer makes
75
+ every edit before it reparse the document up to that comment.
76
+ - After the built-in terms `pi`, `π`, `tau`, `τ`, `now`, `time` and `rand`, a
77
+ `/` or `<` is an operator whatever the spacing: `pi /2`.
78
+ - A keyword that is a routine and is called with parentheses, as in
79
+ `take(1)` or `not($x)`, is a plain name and not a keyword.
80
+ - The body of a regex declaration that is not closed ends before the next
81
+ `token`, `rule` or `regex` declaration, so that the declarations after
82
+ it are still found.
83
+ - A heredoc opener that is only mentioned in a string or in a comment no
84
+ longer starts a heredoc. Heredocs are now found from the quote tokens
85
+ of the line, not from its text.
86
+
1
87
  ## 0.1.0 (2026-10-06)
2
88
 
3
89
  ### New features
package/README.md CHANGED
@@ -60,13 +60,16 @@ const rakuDescription = LanguageDescription.of({
60
60
 
61
61
  <dl>
62
62
  <dt><code><strong>raku</strong>() → LanguageSupport</code></dt>
63
- <dd><p>Raku language support, with completion.</p></dd>
63
+ <dd><p>Raku language support, with completion, and with block comment
64
+ tokens that fit the selection (<code>#`[ … ]</code> around text that holds an
65
+ unbalanced parenthesis).</p></dd>
64
66
  <dt><code><strong>rakuLanguage</strong>: LRLanguage</code></dt>
65
67
  <dd><p>A language provider based on the Lezer Raku parser, extended with
66
68
  highlighting and indentation information.</p></dd>
67
69
  <dt><code><strong>rakuCompletion</strong>: Extension</code></dt>
68
- <dd><p>Completion of Raku keywords and of the commonly used built-in types,
69
- routines, methods and special variables. <code>raku()</code> includes it. To
70
+ <dd><p>Completion of Raku keywords, of the commonly used built-in types,
71
+ routines, methods and special variables, and of the variables, routines,
72
+ types and methods that the document declares. <code>raku()</code> includes it. To
70
73
  leave it out, use <code>rakuLanguage</code> in place of <code>raku()</code>.</p></dd>
71
74
  <dt><code><strong>parser</strong>: LRParser</code></dt>
72
75
  <dd><p>The Lezer parser for Raku, without the editor-specific node props.
@@ -83,73 +86,131 @@ on incomplete code.
83
86
  | Node | Covers |
84
87
  |---|---|
85
88
  | `PackageDeclaration` | `class`, `role`, `grammar`, `module`, `package`, with a `PackageName` child, up to the body `Block` or the `;` of a `unit` declaration |
86
- | `RoutineDeclaration` | `sub`, `method`, `submethod`, with a `RoutineName` child (absent for anonymous routines), up to the body `Block` |
89
+ | `RoutineDeclaration` | `sub`, `method`, `submethod`, with a `RoutineName` child (absent for anonymous routines), up to the body `Block`. Also the `foo(…) { }` of `multi foo(…) { }`, which declares a sub without the word `sub`: that node starts with its `RoutineName` |
87
90
  | `RegexDeclaration` | `token`, `rule`, `regex`, with a `RegexName` child, up to the body `Block`, which holds one `Regex` |
88
91
  | `EnumDeclaration`, `SubsetDeclaration`, `ConstantDeclaration` | The declarator and its `EnumName`, `SubsetName` or `ConstantName` |
89
92
  | `Block`, `Parens`, `Brackets` | `{ }`, `( )`, `[ ]` |
90
93
  | `VariableName`, `AttributeName`, `SpecialVariable` | `$x` / `$^a`, `$!x` / `$.x`, `$*x` / `$?x` |
91
- | `StringLiteral` | A quote of any kind. One that interpolates has `Escape`, `Interpolation`, variable, `Brackets`, `Parens` and `MethodCall` children |
92
- | `Heredoc` | The text of a heredoc, from the line after its `q:to/END/` opener through its terminator. The opener is a `StringLiteral` |
93
- | `Regex` | `/…/`, `rx//`, `m//`, `s///`, `tr///`, or the body of a regex declaration |
94
- | `LineComment`, `DocComment`, `BlockComment`, `Pod` | `#`, `#|` / `#=`, `` #`( ) ``, `=begin` … `=end` and the other Pod blocks |
94
+ | `StringLiteral` | A quote of any kind. One that interpolates has `Escape`, `Interpolation`, variable, `Brackets`, `Parens` and `MethodCall` children, and a `NestedDelimiters` for each pair of its own delimiters in it (the `[b]` of `qq[a [b] c]`) |
95
+ | `Heredoc` | The text of a heredoc, from the line after its `q:to/END/` opener through its terminator. The opener is a `StringLiteral`. The text of a `qq:to` heredoc has the same children as a string that interpolates. The texts of the heredocs that one line opens are a single node |
96
+ | `Regex` | `/…/`, `rx//`, `m//`, `s///`, `tr///`, or the body of a regex declaration. Its children are `CharacterClass` (`<[a..z]>`), `Assertion` (`<name>`, `<?before …>`), `StringLiteral`, `Escape` (`\d`), `Operator` (quantifiers, `\|`, anchors), `VariableName` (`$x`, `$<name>`), `LineComment`, and a `Block` for each `{ }` of code |
97
+ | `LineComment`, `DocComment`, `BlockComment` | `#`, `#|` / `#=`, `` #`( ) `` |
98
+ | `Pod` | `=begin` … `=end` and the other Pod blocks. Its children are `PodDirective` (`=begin`, `=head1`, `=end pod`), `PodHeading` (the text after `=head1`), and the formatting codes `PodStrong` (`B<…>`), `PodEmphasis` (`I<…>`), `PodCode` (`C<…>`), `PodLink` (`L<…>`) and `PodFormat` (the others) |
95
99
 
96
100
  Each declarator keyword is a child node named after the keyword (`class`,
97
- `sub`, `token`, …). The words `unit`, `multi`, `proto`, `my` and `our` are
98
- not part of the declaration node. They are the nodes right before it.
101
+ `sub`, `token`, …). The words `unit`, `multi`, `proto`, `only`, `my` and
102
+ `our` are not part of the declaration node. They are the nodes right
103
+ before it, also in `multi foo(…) { }`, where the declaration node has no
104
+ declarator keyword.
99
105
 
100
106
  ## Known limitations
101
107
 
102
108
  Not supported yet:
103
109
 
104
- - Nothing is highlighted inside a regex. A regex literal, and the body of
105
- a `token` / `rule` / `regex` declaration, is a single `Regex` token,
106
- including any code blocks in it.
107
- - Nothing is highlighted inside a heredoc, a `<<…>>` / `«…»` word list or
108
- a Pod block: no interpolation, no Pod formatting codes.
109
- - Only `"…"` and the `qq` forms interpolate. Adverbs that switch
110
- interpolation on or off (`q:c`, `q:s`, `qq:!c`) are not taken into
111
- account.
112
- - `multi`, `proto` and `only` declarations without `sub` or `method` are
113
- not declaration nodes.
114
- - User-defined operators are recognized where they are declared
115
- (`sub infix:<+++>`), not as `&infix:<+++>`.
116
- - Indentation follows brackets only. A statement continued on the next
117
- line is not indented further.
118
- - Completion offers a fixed list of names. It does not offer the
119
- variables, routines and classes of the document, and after a `.` it
120
- offers the same methods whatever the type of the invocant. In a
121
- string, only the code in `{ }` and in a subscript is completed, not
122
- the method name of `"$x.name()"`.
123
- - Toggling a block comment wraps the selection in `` #`( `` … `)`. When
124
- the parentheses in the selection are not balanced, the comment ends
125
- early or runs on past the selection.
110
+ - Nothing is highlighted in the replacement of `s/…/…/`, nor in
111
+ `tr/…/…/`.
112
+ - In a regex, a `<…>` is one
113
+ token, with the code or the nested `<…>` in it, and has to be closed on
114
+ its line unless it is a character class. Groups (`[ ]`, `( )`) and
115
+ adverbs (`:i`, `:my`) are plain text, so the text after `:my` is read
116
+ as regex.
117
+ - A heredoc is interpolated when everything interpolates in it, as in
118
+ `qq:to`. One that interpolates in part (`q:c:to`, `qq:!s:to`) is not
119
+ highlighted inside. When a line opens several heredocs, they are
120
+ interpolated only if all of them are. A `{` that is not closed in the
121
+ text takes the rest of the heredoc, with its terminator, for code.
122
+ - In Pod, a formatting code is one token: the codes inside it
123
+ (`B<I<…>>`) are not told apart. Formatting codes are left alone in a
124
+ block that is code (`=begin code`, `=code`, `=for code`), but not in a
125
+ code block inside another block, nor in an indented code paragraph.
126
+ Tables and the configuration after a directive (`:numbered`) are plain
127
+ text.
128
+ - A `<<…>>` or `«…»` word list that holds `{ }`, `( )` or `;` can span up
129
+ to 10 lines. A longer one is not taken to be a word list. Nothing is
130
+ interpolated in a list that holds an unbalanced `{` or its own
131
+ delimiter: it is a single token.
132
+ - A Pod block is read where a statement or a term can stand, not
133
+ everywhere that whitespace can: one between `class` and the name of
134
+ the class is not read as Pod.
135
+ - A quote adverb is switched off by the argument `False` or `0`, as in
136
+ `qq:c(False)[…]`. With any other argument, such as a variable, it
137
+ counts as switched on.
138
+ - The brackets of a block comment are picked for the `toggleBlockComment`
139
+ command. Text that unbalances every bracket that is tried gets
140
+ `` #`( `` … `)`, which then does not cover exactly that text.
141
+ - A user-defined operator is recognized where it is declared
142
+ (`sub infix:<+++>`) and as a routine (`&infix:<+++>`), not where it is
143
+ used as an operator.
144
+ - Completion does not know types. After a `.` it offers the built-in
145
+ methods and every method that the document declares, whatever the
146
+ invocant is. Names from other files are not offered.
147
+ - Completion takes a variable to be declared by `my`, `our`, `state` or
148
+ `has`, in a signature, after the `->` of a pointy block, or by being a
149
+ placeholder variable (`$^a`, `$:a`). A sigilless variable is offered
150
+ when it is declared with a backslash (`my \x`, `sub f(\x)`, `-> \x`),
151
+ not as a term (`my constant x`, `sub term:<x>`).
152
+ - In a string, only the code in `{ }` and in a subscript is completed,
153
+ not the method name of `"$x.name()"`.
126
154
 
127
155
  Heuristics that can be wrong:
128
156
 
157
+ - A line is indented as the continuation of a statement when the line
158
+ before it ends in an operator or a comma, or when it starts with a
159
+ method call, with an operator that has a space after it, or with a
160
+ trait (`is`, `does`, `returns`, `handles`, `where`, `will`, as in
161
+ `is export {`). A statement that continues in another way is not
162
+ indented further. A line that starts with one of these words for
163
+ another reason, such as a call of the `is` of `Test`, is indented when
164
+ the line before it does not end in a `;` or a `}`. Inside `( )` and
165
+ `[ ]`, indentation follows the brackets only.
129
166
  - A capitalized word is taken to be a type name.
130
167
  - Whether `/` starts a regex and `<` starts a word list is decided from
131
168
  the token before it. After a bare name, spacing decides: `say /x/` and
132
- `say <a b>` are a regex and a word list, `pi / 2` and `n < 3` are not.
133
- After a closing brace, a line break decides.
169
+ `say <a b>` are a regex and a word list, `foo / 2` and `n < 3` are not.
170
+ The built-in terms `pi`, `π`, `tau`, `τ`, `now`, `time` and `rand` are
171
+ followed by an operator whatever the spacing (`pi /2`), also when a
172
+ routine of your own has one of these names. After a closing brace, a
173
+ line break decides.
134
174
  - A `<…>` right after a term is a subscript only when it holds plain words
135
- on one line: `%h<key>`, but not `$a<$b`.
175
+ on one line: `%h<key>`, but not `$a<$b`. A `<<…>>` or `«…»` that touches
176
+ the term before it is a subscript when it is at most 24 characters
177
+ long and starts and ends in a word, a variable or a quote: `%h«$key»`,
178
+ but not the hyper operators of `@a<<+>>@b` and `@a«R-»@b`. A hyper
179
+ operator that is a word and touches both of its operands, as in
180
+ `@a<<min>>@b`, is misread as a subscript.
181
+ - A `<<` or `«` where a term is expected starts a word list when a `>>`
182
+ or `»` follows, within 10 lines if there is a `{ }`, `( )` or `;` in
183
+ between. One that is being typed takes the code up to there for its
184
+ content.
185
+ - In a `<<…>>` word list, a `>>` in a subscript or a call that is
186
+ interpolated ends the list: `<<@a[1 >> 2]>>`. A heredoc that is opened
187
+ in a block in a word list or in a regex literal is not read as one.
136
188
  - `q`, `qq`, `Q`, `m`, `rx`, `s`, `tr` and their variants start a quote
137
- when a delimiter follows directly, so a sigilless `s/2` is misread, and
138
- `q {…}` with a space is not a quote.
189
+ when a delimiter follows directly, so a sigilless `s/2` is misread.
190
+ `q`, `qq` and `Q` also take a bracket after blanks (`q {…}`), so a
191
+ routine or a sigilless variable of your own named `q`, before a block
192
+ or a subscript, is misread. The
193
+ regex words do not: `m {…}` and `s {…}` are calls.
139
194
  - `%name` and `&name` are variables, except between two terms with no
140
195
  space on either side: `$a%b`.
196
+ - After `multi`, `proto` or `only`, a name is taken to declare a sub when
197
+ a `(` or a `{` follows it, on the same line or the next:
198
+ `multi foo($x) { }`. One that follows a comment or more than 20
199
+ characters of whitespace is not seen, and a call such as `only foo(1)`, of a
200
+ routine of your own that is named `only`, is read as a declaration.
141
201
  - A word spelled like a keyword is a keyword wherever it appears, except
142
- as a method name, as a declared name, or before `=>`: `take(1)` is
143
- highlighted as a keyword.
144
- - A heredoc is found by looking for `:to` or `:heredoc` with a quote word
145
- in the text of the line before it. One mentioned in a string, or in a
146
- comment at the end of a line of code, counts when its terminator
147
- follows.
148
- - What happens to an unclosed construct depends on its kind. The opener
149
- of a quote that does not interpolate (`'…'`, `q`), of a regex or of a
150
- heredoc is read as ordinary code. A `"…"` or `qq` quote, a Pod block,
151
- an embedded comment or the body of a regex declaration runs to the end
152
- of the document.
202
+ as a method name, as a declared name, before `=>`, and for the
203
+ keywords that are routines (`take`, `return`, `next`, `not`, …) right
204
+ before a `(`: `take(1)`. A sigilless variable or a routine of your own
205
+ that is named like a keyword is highlighted as one.
206
+ - A quote that does not interpolate (`'…'`, `q{…}`), a regex and a
207
+ heredoc have to be closed. Otherwise their opener is read as ordinary
208
+ code.
209
+ - A quote that interpolates (`"…`, `qq[…`), a Pod block or an embedded
210
+ comment that is not closed runs to the end of the document.
211
+ - The body of a regex declaration that is not closed runs up to the next
212
+ line that starts a `token`, `rule` or `regex` declaration, or to the
213
+ end of the document.
153
214
 
154
215
  ## Development
155
216
 
@@ -161,6 +222,18 @@ npm run dev # serves demo/, an editor next to the syntax tree of its content
161
222
 
162
223
  The demo loads the sources, so a change to the grammar shows up on reload.
163
224
 
225
+ To release a version:
226
+
227
+ 1. Run `npm version 1.2.3 --no-git-tag-version`, and turn the
228
+ `## Unreleased` heading of `CHANGELOG.md` into `## 1.2.3 (2026-01-31)`.
229
+ Commit and push.
230
+ 2. Run `npm publish` from that commit. It first runs the tests and checks
231
+ that `CHANGELOG.md` has that section and that nothing is uncommitted.
232
+ 3. Tag that commit `v1.2.3` and push the tag. A workflow then checks that
233
+ the tag matches `package.json` and that npm has the version, published
234
+ from that commit, and creates the GitHub release from the section of
235
+ `CHANGELOG.md`.
236
+
164
237
  ## License
165
238
 
166
239
  [MIT](LICENSE)