@exercism/codemirror-lang-raku 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/CHANGELOG.md +327 -0
- package/LICENSE +23 -0
- package/README.md +371 -2
- package/dist/index.cjs +3297 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +3292 -0
- package/package.json +68 -4
package/README.md
CHANGED
|
@@ -1,3 +1,372 @@
|
|
|
1
|
-
#
|
|
1
|
+
# codemirror-lang-raku
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Exercism's fork
|
|
4
|
+
|
|
5
|
+
This is Exercism's fork of [kan/codemirror-lang-raku](https://github.com/kan/codemirror-lang-raku), by Kan Fushihara.
|
|
6
|
+
Exercism uses it in the Raku editor on [exercism.org](https://exercism.org).
|
|
7
|
+
It is published on npm as `@exercism/codemirror-lang-raku`.
|
|
8
|
+
Our changes are on the `exercism` branch, and the `main` branch follows upstream.
|
|
9
|
+
Below this section, the README is upstream's.
|
|
10
|
+
|
|
11
|
+
The fork adds snippets for the common constructs (`sub`, `class`, `if`, `for`, `given` and others) to the completion.
|
|
12
|
+
|
|
13
|
+
### Install
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install @exercism/codemirror-lang-raku
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Building and testing
|
|
20
|
+
|
|
21
|
+
Run `npm install`, then `npm test`, which builds the package and runs the tests in `test/`.
|
|
22
|
+
|
|
23
|
+
### Releasing
|
|
24
|
+
|
|
25
|
+
To release from the `exercism` branch, set the version in `package.json` and push a tag of the same version (`v1.0.0`, say).
|
|
26
|
+
The tag starts `.github/workflows/publish.yml`.
|
|
27
|
+
The workflow checks that the tag matches `package.json`, builds and tests the package, and publishes it to npm as `@exercism/codemirror-lang-raku`.
|
|
28
|
+
|
|
29
|
+
### Contributing
|
|
30
|
+
|
|
31
|
+
Contributions to this fork follow the Exercism [Code of Conduct](https://exercism.org/docs/using/legal/code-of-conduct).
|
|
32
|
+
Please read about how to [contribute to Exercism](https://exercism.org/docs/building).
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
[](https://www.npmjs.com/package/codemirror-lang-raku)
|
|
37
|
+
[](https://github.com/kan/codemirror-lang-raku/actions/workflows/test.yml)
|
|
38
|
+
[](LICENSE)
|
|
39
|
+
|
|
40
|
+
[Raku](https://raku.org/) (formerly Perl 6) language support for the
|
|
41
|
+
[CodeMirror 6](https://codemirror.net/) code editor: syntax highlighting,
|
|
42
|
+
indentation, code folding, bracket matching and completion, built on a
|
|
43
|
+
[Lezer](https://lezer.codemirror.net/) grammar.
|
|
44
|
+
|
|
45
|
+
It covers comments and Pod, quotes of all kinds (`'…'`, `"…"`, `「…」`,
|
|
46
|
+
curly quotes, `q` / `qq` / `Q` with any delimiter, heredocs,
|
|
47
|
+
`<word lists>`) with interpolation, regexes and grammars, numbers,
|
|
48
|
+
variables with sigils and twigils, keywords, operators, including the
|
|
49
|
+
ones written in Unicode, blocks and declarations.
|
|
50
|
+
|
|
51
|
+
Try it in the [demo](https://kan.github.io/codemirror-lang-raku/), which
|
|
52
|
+
shows the syntax tree next to the editor.
|
|
53
|
+
|
|
54
|
+
> **Status: 0.x.** The node names of the syntax tree can still change
|
|
55
|
+
> between minor versions. See [Known limitations](#known-limitations) for
|
|
56
|
+
> what is missing.
|
|
57
|
+
|
|
58
|
+
## Installation
|
|
59
|
+
|
|
60
|
+
```sh
|
|
61
|
+
npm install @exercism/codemirror-lang-raku
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Usage
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
import {EditorView, basicSetup} from "codemirror"
|
|
68
|
+
import {raku} from "@exercism/codemirror-lang-raku"
|
|
69
|
+
|
|
70
|
+
new EditorView({
|
|
71
|
+
doc: 'say "Hello, Raku!";',
|
|
72
|
+
extensions: [basicSetup, raku()],
|
|
73
|
+
parent: document.body
|
|
74
|
+
})
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Highlighting uses only the standard tags of `@lezer/highlight`, so any
|
|
78
|
+
CodeMirror theme or highlight style applies.
|
|
79
|
+
|
|
80
|
+
To load the language on demand, the way `@codemirror/language-data` does:
|
|
81
|
+
|
|
82
|
+
```javascript
|
|
83
|
+
import {LanguageDescription} from "@codemirror/language"
|
|
84
|
+
|
|
85
|
+
const rakuDescription = LanguageDescription.of({
|
|
86
|
+
name: "Raku",
|
|
87
|
+
alias: ["perl6"],
|
|
88
|
+
extensions: ["raku", "rakumod", "rakutest", "rakudoc", "p6", "pl6", "pm6", "pod6"],
|
|
89
|
+
load: () => import("@exercism/codemirror-lang-raku").then(m => m.raku())
|
|
90
|
+
})
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## API Reference
|
|
94
|
+
|
|
95
|
+
<dl>
|
|
96
|
+
<dt><code><strong>raku</strong>() → LanguageSupport</code></dt>
|
|
97
|
+
<dd><p>Raku language support, with completion, and with block comment
|
|
98
|
+
tokens that fit the selection (<code>#`[ … ]</code> around text that holds an
|
|
99
|
+
unbalanced parenthesis).</p></dd>
|
|
100
|
+
<dt><code><strong>rakuLanguage</strong>: LRLanguage</code></dt>
|
|
101
|
+
<dd><p>A language provider based on the Lezer Raku parser, extended with
|
|
102
|
+
highlighting and indentation information.</p></dd>
|
|
103
|
+
<dt><code><strong>rakuCompletion</strong>: Extension</code></dt>
|
|
104
|
+
<dd><p>Completion of Raku keywords, of the commonly used built-in types,
|
|
105
|
+
routines, methods and special variables, and of the variables, routines,
|
|
106
|
+
types and methods that the document declares. <code>raku()</code> includes it. To
|
|
107
|
+
leave it out, use <code>rakuLanguage</code> in place of <code>raku()</code>.</p></dd>
|
|
108
|
+
<dt><code><strong>parser</strong>: LRParser</code></dt>
|
|
109
|
+
<dd><p>The Lezer parser for Raku, without the editor-specific node props.
|
|
110
|
+
Use <code>rakuLanguage.parser</code> for the configured one.</p></dd>
|
|
111
|
+
</dl>
|
|
112
|
+
|
|
113
|
+
## Syntax tree
|
|
114
|
+
|
|
115
|
+
The grammar does not parse statements and expressions. It tokenizes the
|
|
116
|
+
input, nests brackets, and recognizes declarations, which is enough for
|
|
117
|
+
highlighting, folding and building an outline, and keeps the tree usable
|
|
118
|
+
on incomplete code.
|
|
119
|
+
|
|
120
|
+
| Node | Covers |
|
|
121
|
+
|---|---|
|
|
122
|
+
| `PackageDeclaration` | `class`, `role`, `grammar`, `module`, `package`, with a `PackageName` child, up to the body `Block` or the `;` of a `unit` declaration |
|
|
123
|
+
| `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` |
|
|
124
|
+
| `RegexDeclaration` | `token`, `rule`, `regex`, with a `RegexName` child, up to the body `Block`, which holds one `Regex`. The name includes a `:sym<…>`, with the blanks before it if there are any (`word :sym<long>`), and the brackets in it (`infix:sym<{ }>`) |
|
|
125
|
+
| `EnumDeclaration`, `SubsetDeclaration`, `ConstantDeclaration` | The declarator and its `EnumName`, `SubsetName` or `ConstantName`. The name of a constant includes its sigil if it has one (`constant $LIMIT`). A constant without a sigil that is declared with a backslash (`constant \x`) has no `ConstantName` |
|
|
126
|
+
| `Block`, `Parens`, `Brackets` | `{ }`, `( )`, `[ ]` |
|
|
127
|
+
| `VariableName`, `AttributeName`, `SpecialVariable` | `$x` / `$^a`, `$!x` / `$.x`, `$*x` / `$?x`. An operator that is referred to as a routine is one `VariableName`: `&infix:<+>`, `&[+]` |
|
|
128
|
+
| `Identifier`, `TypeName` | A bare name (`say`, `my-sub`), and a capitalized one (`Int`, `Foo::Bar`, the type capture `::T`, `::?CLASS`), with its smiley if it has one (`Int:D`) |
|
|
129
|
+
| `MethodCall` | The `.` and the `MethodName` of `.name`, `.?name` and the like. The arguments are the `Parens` after it |
|
|
130
|
+
| `PairKey` | `:key`, `:!key`. The value is the node after it |
|
|
131
|
+
| `Number`, `Version` | `42`, `1.5e3`, `0x1F`, `:16<FF>`, `½`, `Ⅻ`, `∞`, and `v6.d` |
|
|
132
|
+
| `True`, `False`, `Nil` | These three words |
|
|
133
|
+
| `Operator` | An operator made of symbols, a word operator where an operator is expected (`x`, `min`, `before`, `Z+`, `Zmin`), a set operator in parentheses (`(elem)`) |
|
|
134
|
+
| `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]`) |
|
|
135
|
+
| `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 |
|
|
136
|
+
| `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`, `BlockComment`, and a `Block` for each `{ }` of code |
|
|
137
|
+
| `LineComment`, `DocComment`, `BlockComment` | `#`, `#\|` / `#=`, `` #`( ) ``. A declarator comment with brackets, `#\|( … )`, is one `DocComment` up to its closing bracket |
|
|
138
|
+
| `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) |
|
|
139
|
+
|
|
140
|
+
Each keyword is a node named after the keyword (`if`, `for`, `my`,
|
|
141
|
+
`is`, `eq`, …), and so is each phaser (`BEGIN`, `LEAVE`, …). A
|
|
142
|
+
declarator keyword is a child of its declaration node (`class`, `sub`,
|
|
143
|
+
`token`, …). The words `unit`, `multi`, `proto`, `only`, `my` and
|
|
144
|
+
`our` are not part of the declaration node. They are the nodes right
|
|
145
|
+
before it, also in `multi foo(…) { }`, where the declaration node has no
|
|
146
|
+
declarator keyword.
|
|
147
|
+
|
|
148
|
+
Statements and expressions have no nodes: `if $x { }` is the nodes `if`,
|
|
149
|
+
`VariableName` and `Block` next to each other.
|
|
150
|
+
|
|
151
|
+
## Known limitations
|
|
152
|
+
|
|
153
|
+
Not supported yet:
|
|
154
|
+
|
|
155
|
+
- Nothing is highlighted in the replacement of `s/…/…/`, nor in
|
|
156
|
+
`tr/…/…/`. The second pair of brackets of `tr[…][…]` is read as code.
|
|
157
|
+
A replacement that is a block of code with the delimiter in it, as in
|
|
158
|
+
`s/x/{ "a/b" }/`, ends at that delimiter.
|
|
159
|
+
- In a regex, a `<…>` is one
|
|
160
|
+
token, with the code or the nested `<…>` in it, and has to be closed on
|
|
161
|
+
its line unless it is a character class. Groups (`[ ]`, `( )`) and
|
|
162
|
+
adverbs (`:i`, `:my`) are plain text, so the text after `:my` is read
|
|
163
|
+
as regex, and so is the code in `$( … )`. Such code does not end the
|
|
164
|
+
regex when it holds the delimiter (`/ :my $m = $/; /`), if it is on
|
|
165
|
+
one line.
|
|
166
|
+
- A heredoc is interpolated when everything interpolates in it, as in
|
|
167
|
+
`qq:to`. One that interpolates in part (`q:c:to`, `qq:!s:to`) is not
|
|
168
|
+
highlighted inside. When a line opens several heredocs, they are
|
|
169
|
+
interpolated only if all of them are. A `{` that is not closed in the
|
|
170
|
+
text takes the rest of the heredoc, with its terminator, for code.
|
|
171
|
+
- After an edit that makes a heredoc's opener no longer open it, such as
|
|
172
|
+
commenting out its line, the text of the heredoc can stay a heredoc
|
|
173
|
+
instead of turning back into code. An edit in the text, or in the code
|
|
174
|
+
shortly after it, makes it code again, as a parse from scratch reads
|
|
175
|
+
it. This takes a fix in `@lezer/common`
|
|
176
|
+
([lezer/lezer#79](https://code.haverbeke.berlin/lezer/lezer/issues/79)).
|
|
177
|
+
- In Pod, a formatting code is one token: the codes inside it
|
|
178
|
+
(`B<I<…>>`) are not told apart. Formatting codes are left alone in a
|
|
179
|
+
block that is code (`=begin code`, `=code`, `=for code`), but not in a
|
|
180
|
+
code block inside another block, nor in an indented code paragraph.
|
|
181
|
+
Tables and the configuration after a directive (`:numbered`) are plain
|
|
182
|
+
text. A block in a block of the same name (`=begin pod` in
|
|
183
|
+
`=begin pod`) does not nest: the first `=end pod` closes the outer one.
|
|
184
|
+
- A `<<…>>` or `«…»` word list that holds `{ }`, `( )` or `;` can span up
|
|
185
|
+
to 10 lines. A longer one is not taken to be a word list. Nothing is
|
|
186
|
+
interpolated in a list that holds an unbalanced `{` or its own
|
|
187
|
+
delimiter: it is a single token.
|
|
188
|
+
- A Pod block between a declarator and its name, as between `class` and
|
|
189
|
+
the name of the class, hides the name: the declaration then has no
|
|
190
|
+
`PackageName`. A comment there does not.
|
|
191
|
+
- In a quote that has braces for delimiters, a `{ }` is taken to be a
|
|
192
|
+
nested pair of the delimiters, not a block of code: the `{$b + 1}` of
|
|
193
|
+
`qq{a {$b + 1} c}` is text, in which `$b` is interpolated. With other
|
|
194
|
+
delimiters, as in `qq[a {$b + 1} c]`, it is a block.
|
|
195
|
+
- A quote adverb is switched off by the argument `False` or `0`, as in
|
|
196
|
+
`qq:c(False)[…]`. With any other argument, such as a variable, it
|
|
197
|
+
counts as switched on.
|
|
198
|
+
- The brackets of a block comment are picked for the `toggleBlockComment`
|
|
199
|
+
command. Text that unbalances every bracket that is tried gets
|
|
200
|
+
`` #`( `` … `)`, which then does not cover exactly that text.
|
|
201
|
+
- A user-defined operator is recognized where it is declared
|
|
202
|
+
(`sub infix:<+++>`) and as a routine (`&infix:<+++>`). Where it is
|
|
203
|
+
used, it is an operator when it is made of operator characters or of
|
|
204
|
+
symbols outside of ASCII (`1 ⚡ 2`). One that is a word is a plain
|
|
205
|
+
name, also between hyper marks (`@a »plus« @b`). A term or a circumfix of one's own is not known: one that is
|
|
206
|
+
a symbol is highlighted as an operator, or is an error when the symbol
|
|
207
|
+
is no operator character (`℃`), and one that is a letter and a number,
|
|
208
|
+
such as `ℵ₀`, is a name and a number.
|
|
209
|
+
- A number that is one character is a `Number` when it is one of the
|
|
210
|
+
fractions, the Roman numerals, the subscripts, the circled numbers and
|
|
211
|
+
the ideographic numbers (`½`, `Ⅻ`, `₀`, `①`, `〇`). Others, as in the
|
|
212
|
+
scripts that have letters (`፩`, `௰`), are names, and so are the digits
|
|
213
|
+
of such scripts (`٤٢`). The full-width digits (`42`) are errors.
|
|
214
|
+
- After a name and a space, `+<`, `~<` and `!<` with no space after them
|
|
215
|
+
are taken for a prefix and a word list, as in a call (`say +<a b>`),
|
|
216
|
+
also when the name is a sigilless variable (`first +<a b>`). With a
|
|
217
|
+
space after them, they are the infix (`first +< 64`). After a
|
|
218
|
+
variable, they are always the infix, as in Raku.
|
|
219
|
+
- After a name and a space, double angles start a word list, also when
|
|
220
|
+
the name is a sigilless variable and they start a hyper infix
|
|
221
|
+
(`x «+« 1`). After a variable or a whatever star, they are the hyper
|
|
222
|
+
(`$x «+« 1`, `* «+« 1`).
|
|
223
|
+
- Double angles right after a prefix are taken for a hyper prefix
|
|
224
|
+
(`-<<@a`), so a word list there needs a space: `say + «a b»`, not
|
|
225
|
+
`say +«a b»`. After an infix with no space, they start a word list
|
|
226
|
+
only when the infix is one character or ends in `=` (`@a=«a b»`,
|
|
227
|
+
`$a==<<a b>>`), not after `~~`. A word list right after a hyper
|
|
228
|
+
operator (`@a»+«<a b>`) is read as part of the operator.
|
|
229
|
+
- In a hyper assignment with brackets, `=<<` and `=«` close the hyper
|
|
230
|
+
(`@a >>[&f]=<< @b`) only when the brackets are on one line and hold
|
|
231
|
+
about 20 characters at most, and no word follows the angles. With a
|
|
232
|
+
name right after them (`@a >>[&f]=<<foo`), or a longer infix in the
|
|
233
|
+
brackets, they start a word list, as after a hyper subscript
|
|
234
|
+
(`@a>>[0]=<<a b>>`). Brackets that start with a digit, `$` or `@` are
|
|
235
|
+
taken for a hyper subscript.
|
|
236
|
+
- The `native` declarator, which NativeCall uses internally, does not
|
|
237
|
+
make a declaration node.
|
|
238
|
+
- Completion does not know types. After a `.` it offers the built-in
|
|
239
|
+
methods and every method that the document declares, whatever the
|
|
240
|
+
invocant is. Names from other files are not offered.
|
|
241
|
+
- Completion takes a variable to be declared by `my`, `our`, `state` or
|
|
242
|
+
`has`, in a signature, after the `->` of a pointy block, or by being a
|
|
243
|
+
placeholder variable (`$^a`, `$:a`). A sigilless variable is offered
|
|
244
|
+
when it is declared with a backslash (`my \x`, `sub f(\x)`, `-> \x`),
|
|
245
|
+
and a constant when it is declared with `constant`. A term that is
|
|
246
|
+
declared as a routine (`sub term:<x>`) is not offered.
|
|
247
|
+
- In a string, only the code in `{ }` and in a subscript is completed,
|
|
248
|
+
not the method name of `"$x.name()"`.
|
|
249
|
+
|
|
250
|
+
Heuristics that can be wrong:
|
|
251
|
+
|
|
252
|
+
- A line is indented as the continuation of a statement when the line
|
|
253
|
+
before it ends in an operator or a comma, or when it starts with a
|
|
254
|
+
method call, with an operator that has a space after it, or with a
|
|
255
|
+
trait (`is`, `does`, `returns`, `handles`, `where`, `will`, as in
|
|
256
|
+
`is export {`). A statement that continues in another way is not
|
|
257
|
+
indented further. A line that starts with one of these words for
|
|
258
|
+
another reason, such as a call of the `is` of `Test`, is indented when
|
|
259
|
+
the line before it does not end in a `;` or a `}`. Inside `( )` and
|
|
260
|
+
`[ ]`, indentation follows the brackets only.
|
|
261
|
+
- A capitalized word is taken to be a type name.
|
|
262
|
+
- A symbol outside of ASCII is taken to be an operator, whatever it was
|
|
263
|
+
declared as. The built-in terms `∞` and `∅` are not: `∞` is a number,
|
|
264
|
+
and `∅` is followed by an operator.
|
|
265
|
+
- A set operator in parentheses, such as `(elem)` or `(<=)`, is an
|
|
266
|
+
operator after a term and a space: `$a (elem) $b`. Right after the
|
|
267
|
+
term, the parentheses hold arguments: `$f(elem)`.
|
|
268
|
+
- An operator in brackets, `&[+]`, is a routine when the operator is at
|
|
269
|
+
most 11 characters long, and not after a term, where the `&` is an
|
|
270
|
+
operator.
|
|
271
|
+
- An operator name in double angles, as in `infix:<< plus >>`, has to
|
|
272
|
+
end within 20 characters of where it starts.
|
|
273
|
+
- Whether `/` starts a regex and `<` starts a word list is decided from
|
|
274
|
+
the token before it. After a bare name, spacing decides: `say /x/` and
|
|
275
|
+
`say <a b>` are a regex and a word list, `foo / 2` and `n < 3` are not.
|
|
276
|
+
The built-in terms `pi`, `π`, `tau`, `τ`, `now`, `time` and `rand` are
|
|
277
|
+
followed by an operator whatever the spacing (`pi /2`), also when a
|
|
278
|
+
routine of your own has one of these names. After a closing brace, a
|
|
279
|
+
line break decides. After the value of a pair in angles, as in
|
|
280
|
+
`:ver<1>`, spacing decides as after a name, so that the import list of
|
|
281
|
+
`use Foo:ver<1> <a b>` is a word list.
|
|
282
|
+
- A `<…>` right after a term is a subscript only when it holds plain words
|
|
283
|
+
on one line: `%h<key>`, but not `$a<$b`, nor a key with a quote or
|
|
284
|
+
other punctuation in it (`%h<a"b>`). A `<<…>>` or `«…»` that touches
|
|
285
|
+
the term before it is a subscript when it is at most 24 characters
|
|
286
|
+
long and starts and ends in a word, a variable or a quote: `%h«$key»`,
|
|
287
|
+
but not the hyper operators of `@a<<+>>@b` and `@a«R-»@b`. A hyper
|
|
288
|
+
operator that is a word and touches both of its operands, as in
|
|
289
|
+
`@a<<min>>@b`, is misread as a subscript.
|
|
290
|
+
- A `<<` or `«` where a term is expected starts a word list when a `>>`
|
|
291
|
+
or `»` follows, within 10 lines if there is a `{ }`, `( )` or `;` in
|
|
292
|
+
between. One that is being typed takes the code up to there for its
|
|
293
|
+
content.
|
|
294
|
+
- In a `<<…>>` word list, a `>>` in a subscript or a call that is
|
|
295
|
+
interpolated ends the list: `<<@a[1 >> 2]>>`, and so does the `>` of
|
|
296
|
+
a subscript or a named capture right before the end, as in
|
|
297
|
+
`<<x %h<b>>>`, `<<x %*h<b>>>` and `<<x $<b>>>`. A heredoc that
|
|
298
|
+
is opened in a block in a word list or in a regex literal is not read
|
|
299
|
+
as one.
|
|
300
|
+
- `q`, `qq`, `Q`, `m`, `rx`, `s`, `tr` and their variants start a quote
|
|
301
|
+
when a delimiter follows directly: a bracket, one of
|
|
302
|
+
``/ ! | ~ ^ % @ " ' ` ``, or a symbol outside of ASCII. So a
|
|
303
|
+
sigilless `s/2` is misread.
|
|
304
|
+
`q`, `qq` and `Q` also take a bracket after blanks (`q {…}`), so a
|
|
305
|
+
routine or a sigilless variable of your own named `q`, before a block
|
|
306
|
+
or a subscript, is misread. The
|
|
307
|
+
regex words do not: `m {…}` and `s {…}` are calls.
|
|
308
|
+
- In a string, a method call after a variable is interpolated when it
|
|
309
|
+
has an argument list, or when the calls chained to it end in one
|
|
310
|
+
within 24 characters: `"$x.a.b()"`, but not `"$x.a.b"`. For an `@`,
|
|
311
|
+
`%` or `&` variable, the 24 characters count from its sigil.
|
|
312
|
+
- `%name` and `&name` are variables, except between two terms with no
|
|
313
|
+
space on either side: `$a%b`.
|
|
314
|
+
- After `multi`, `proto` or `only`, a name is taken to declare a sub when
|
|
315
|
+
a `(` or a `{` follows it, on the same line or the next:
|
|
316
|
+
`multi foo($x) { }`. One that follows a comment or more than 20
|
|
317
|
+
characters of whitespace is not seen, and a call such as `only foo(1)`, of a
|
|
318
|
+
routine of your own that is named `only`, is read as a declaration.
|
|
319
|
+
- A word spelled like a keyword is a keyword wherever it appears, except
|
|
320
|
+
as a method name, as a declared name, before `=>`, after a backslash
|
|
321
|
+
(`sub f(\class)`), for a declarator that a method is called on
|
|
322
|
+
(`class.say`), and for the keywords that are routines (`take`,
|
|
323
|
+
`return`, `next`, `not`, …) right before a `(`: `take(1)`. Elsewhere, a
|
|
324
|
+
sigilless variable or a routine of your own that is named like a
|
|
325
|
+
keyword is highlighted as one, and one that is named like a
|
|
326
|
+
declarator, as in `say role` or `method($n)`, starts a declaration.
|
|
327
|
+
- In a regex, a curly quote or a corner quote opens a quote, as Raku
|
|
328
|
+
has it. A lone one, as in `/‘/`, takes the text up to the next
|
|
329
|
+
closing quote on its line.
|
|
330
|
+
- A `$/` in the replacement of `s/…/…/` is the match variable when a `/`
|
|
331
|
+
follows on the same line, and a `$` before the closing delimiter
|
|
332
|
+
otherwise.
|
|
333
|
+
- A `:sym<…>` after the name of a declaration and blanks is part of the
|
|
334
|
+
name, also for a declaration that is not a regex.
|
|
335
|
+
- A quote that does not interpolate (`'…'`, `q{…}`), a regex and a
|
|
336
|
+
heredoc have to be closed. Otherwise their opener is read as ordinary
|
|
337
|
+
code.
|
|
338
|
+
- A quote that interpolates (`"…`, `qq[…`), a Pod block or an embedded
|
|
339
|
+
comment that is not closed runs to the end of the document. A
|
|
340
|
+
declarator comment with brackets (`#|( …`) that is not closed ends
|
|
341
|
+
with its line.
|
|
342
|
+
- The body of a regex declaration that is not closed runs up to the next
|
|
343
|
+
line that starts a `token`, `rule` or `regex` declaration, or to the
|
|
344
|
+
end of the document.
|
|
345
|
+
|
|
346
|
+
## Development
|
|
347
|
+
|
|
348
|
+
```sh
|
|
349
|
+
npm install
|
|
350
|
+
npm test # builds, then runs the tests in test/
|
|
351
|
+
npm run dev # serves demo/, an editor next to the syntax tree of its content
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
The demo loads the sources, so a change to the grammar shows up on reload.
|
|
355
|
+
|
|
356
|
+
Changes go in through pull requests. A pull request that changes what
|
|
357
|
+
users get adds its entry under `## [Unreleased]` in `CHANGELOG.md`. One
|
|
358
|
+
that adds a feature also adds a sample of it to
|
|
359
|
+
`test/fixtures/new-in-<next minor version>.raku` (`new-in-0.5.raku`, say),
|
|
360
|
+
and is labelled `enhancement` to make the next release a minor one.
|
|
361
|
+
|
|
362
|
+
Releases are made with [tagpr](https://github.com/Songmu/tagpr). It keeps
|
|
363
|
+
a release pull request open that bumps the version and turns
|
|
364
|
+
`## [Unreleased]` into the version's section. Merging it tags the merge
|
|
365
|
+
commit, and a workflow then stages the version on npm with Trusted
|
|
366
|
+
Publishing and creates the GitHub release from the section of
|
|
367
|
+
`CHANGELOG.md`. The staged version is public once the maintainer approves
|
|
368
|
+
it.
|
|
369
|
+
|
|
370
|
+
## License
|
|
371
|
+
|
|
372
|
+
[MIT](LICENSE)
|