codemirror-lang-raku 0.0.0-stage → 0.1.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 ADDED
@@ -0,0 +1,16 @@
1
+ ## 0.1.0 (2026-10-06)
2
+
3
+ ### New features
4
+
5
+ First release.
6
+
7
+ - Syntax highlighting with the standard tags of `@lezer/highlight`:
8
+ comments and Pod, quotes of all kinds with interpolation, heredocs,
9
+ regexes, numbers, variables with sigils and twigils, keywords, operators
10
+ and declarations
11
+ - A syntax tree with nodes for package, routine, regex, enum, subset and
12
+ constant declarations and their names
13
+ - Indentation, folding and matching of `{ }`, `( )` and `[ ]`, and folding
14
+ of Pod blocks, heredocs and embedded comments
15
+ - Completion of keywords and of the commonly used built-in types,
16
+ routines, methods and special variables
package/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ MIT License
2
+
3
+ Copyright (C) 2026 by Kan Fushihara
4
+ Copyright (C) 2021 by Marijn Haverbeke <marijnh@gmail.com> and others
5
+ (the CodeMirror language package template this project started from)
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,166 @@
1
- # Temporary Holding Version
1
+ # codemirror-lang-raku
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/codemirror-lang-raku)](https://www.npmjs.com/package/codemirror-lang-raku)
4
+ [![Test](https://github.com/kan/codemirror-lang-raku/actions/workflows/test.yml/badge.svg)](https://github.com/kan/codemirror-lang-raku/actions/workflows/test.yml)
5
+ [![License: MIT](https://img.shields.io/npm/l/codemirror-lang-raku)](LICENSE)
6
+
7
+ [Raku](https://raku.org/) (formerly Perl 6) language support for the
8
+ [CodeMirror 6](https://codemirror.net/) code editor: syntax highlighting,
9
+ indentation, code folding, bracket matching and completion, built on a
10
+ [Lezer](https://lezer.codemirror.net/) grammar.
11
+
12
+ It covers comments and Pod, quotes of all kinds (`'…'`, `"…"`, `q` / `qq` /
13
+ `Q` with any delimiter, heredocs, `<word lists>`) with interpolation,
14
+ regexes, numbers, variables with sigils and twigils, keywords, operators,
15
+ blocks and declarations.
16
+
17
+ Try it in the [demo](https://kan.github.io/codemirror-lang-raku/), which
18
+ shows the syntax tree next to the editor.
19
+
20
+ > **Status: 0.x.** The node names of the syntax tree can still change
21
+ > between minor versions. See [Known limitations](#known-limitations) for
22
+ > what is missing.
23
+
24
+ ## Installation
25
+
26
+ ```sh
27
+ npm install codemirror-lang-raku
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ ```javascript
33
+ import {EditorView, basicSetup} from "codemirror"
34
+ import {raku} from "codemirror-lang-raku"
35
+
36
+ new EditorView({
37
+ doc: 'say "Hello, Raku!";',
38
+ extensions: [basicSetup, raku()],
39
+ parent: document.body
40
+ })
41
+ ```
42
+
43
+ Highlighting uses only the standard tags of `@lezer/highlight`, so any
44
+ CodeMirror theme or highlight style applies.
45
+
46
+ To load the language on demand, the way `@codemirror/language-data` does:
47
+
48
+ ```javascript
49
+ import {LanguageDescription} from "@codemirror/language"
50
+
51
+ const rakuDescription = LanguageDescription.of({
52
+ name: "Raku",
53
+ alias: ["perl6"],
54
+ extensions: ["raku", "rakumod", "rakutest", "rakudoc", "p6", "pl6", "pm6", "pod6"],
55
+ load: () => import("codemirror-lang-raku").then(m => m.raku())
56
+ })
57
+ ```
58
+
59
+ ## API Reference
60
+
61
+ <dl>
62
+ <dt><code><strong>raku</strong>() → LanguageSupport</code></dt>
63
+ <dd><p>Raku language support, with completion.</p></dd>
64
+ <dt><code><strong>rakuLanguage</strong>: LRLanguage</code></dt>
65
+ <dd><p>A language provider based on the Lezer Raku parser, extended with
66
+ highlighting and indentation information.</p></dd>
67
+ <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
+ leave it out, use <code>rakuLanguage</code> in place of <code>raku()</code>.</p></dd>
71
+ <dt><code><strong>parser</strong>: LRParser</code></dt>
72
+ <dd><p>The Lezer parser for Raku, without the editor-specific node props.
73
+ Use <code>rakuLanguage.parser</code> for the configured one.</p></dd>
74
+ </dl>
75
+
76
+ ## Syntax tree
77
+
78
+ The grammar does not parse statements and expressions. It tokenizes the
79
+ input, nests brackets, and recognizes declarations, which is enough for
80
+ highlighting, folding and building an outline, and keeps the tree usable
81
+ on incomplete code.
82
+
83
+ | Node | Covers |
84
+ |---|---|
85
+ | `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` |
87
+ | `RegexDeclaration` | `token`, `rule`, `regex`, with a `RegexName` child, up to the body `Block`, which holds one `Regex` |
88
+ | `EnumDeclaration`, `SubsetDeclaration`, `ConstantDeclaration` | The declarator and its `EnumName`, `SubsetName` or `ConstantName` |
89
+ | `Block`, `Parens`, `Brackets` | `{ }`, `( )`, `[ ]` |
90
+ | `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 |
95
+
96
+ 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.
99
+
100
+ ## Known limitations
101
+
102
+ Not supported yet:
103
+
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.
126
+
127
+ Heuristics that can be wrong:
128
+
129
+ - A capitalized word is taken to be a type name.
130
+ - Whether `/` starts a regex and `<` starts a word list is decided from
131
+ 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.
134
+ - A `<…>` right after a term is a subscript only when it holds plain words
135
+ on one line: `%h<key>`, but not `$a<$b`.
136
+ - `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.
139
+ - `%name` and `&name` are variables, except between two terms with no
140
+ space on either side: `$a%b`.
141
+ - 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.
153
+
154
+ ## Development
155
+
156
+ ```sh
157
+ npm install
158
+ npm test # builds, then runs the tests in test/
159
+ npm run dev # serves demo/, an editor next to the syntax tree of its content
160
+ ```
161
+
162
+ The demo loads the sources, so a change to the grammar shows up on reload.
163
+
164
+ ## License
165
+
166
+ [MIT](LICENSE)