@exercism/codemirror-lang-r 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 ADDED
@@ -0,0 +1,31 @@
1
+ ## 1.0.1
2
+
3
+ The README is restructured. This release is the first published from GitHub Actions, with npm provenance.
4
+
5
+ ## 1.0.0
6
+
7
+ This is Exercism's first release of the package, published as
8
+ `@exercism/codemirror-lang-r`. It adds completion of the names assigned in the
9
+ file, function parameters, loop variables, snippets and more of base R.
10
+
11
+ ## 0.1.1 (2026-08-06)
12
+
13
+ The repository link, which npm renders as a link and a browser cannot follow
14
+ with `git+` in front of it.
15
+
16
+ ## 0.1.0 (2026-08-02)
17
+
18
+ ### First release
19
+
20
+ R language support: a Lezer grammar ported from R's own `gram.y`, plus
21
+ highlighting, folding, indentation and completion.
22
+
23
+ CodeMirror has never shipped R. What stands in for it is the stream mode
24
+ carried over from CodeMirror 5, which colours a keyword list and builds no
25
+ tree. The one other Lezer grammar on npm reads 28% of real R, having no unary
26
+ minus, no `<` or `>`, no `:`, no `|>`, no `%in%`, no braceless body, no `\(x)`
27
+ and no raw string.
28
+
29
+ The grammar was developed against 2 322 files from R itself, ggplot2, dplyr,
30
+ tidyr, data.table, shiny, testthat and devtools, of which 99.70% parse with no
31
+ error node. The seven that do not are not R.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CodinCod
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 all
13
+ 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 THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,111 @@
1
- # Temporary Holding Version
1
+ # @exercism/codemirror-lang-r
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
+ [ [**CHANGELOG**](CHANGELOG.md) ]
4
+
5
+ This package implements R language support for the
6
+ [CodeMirror](https://codemirror.net/) code editor, using a
7
+ [Lezer](https://lezer.codemirror.net/) grammar ported from R's own.
8
+ Exercism uses it in the R editor on [exercism.org](https://exercism.org).
9
+
10
+ CodeMirror 6 has never shipped R. What stands in for it is the stream mode
11
+ carried over from CodeMirror 5, which colours a keyword list and builds no
12
+ tree, so nothing above it can fold a function, indent an argument list or ask
13
+ what the name under the cursor is. There is one other Lezer grammar for R on
14
+ npm, and it reads under a third of real R: no unary minus, no `<` or `>`, no
15
+ `:`, no `|>`, no `%in%`, no braceless body, no `\(x)`, no raw string.
16
+
17
+ This code is released under an [MIT license](LICENSE).
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ npm install @exercism/codemirror-lang-r
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```javascript
28
+ import {EditorView, basicSetup} from "codemirror"
29
+ import {r} from "@exercism/codemirror-lang-r"
30
+
31
+ const view = new EditorView({
32
+ parent: document.body,
33
+ doc: `greet <- function(name = "world") {
34
+ sprintf("Hello, %s!", name)
35
+ }
36
+ `,
37
+ extensions: [basicSetup, r()]
38
+ })
39
+ ```
40
+
41
+ ## Completion
42
+
43
+ `r()` includes completion for:
44
+
45
+ - The names assigned in the file with `<-`, `=`, `->` and `<<-`, the
46
+ parameters of the functions around the cursor, and loop variables. A name
47
+ assigned inside a function is offered inside that function and nowhere else.
48
+ A name assigned at the top of the file is offered everywhere.
49
+ - Snippets for a function, a lambda, `if`, `if` with `else`, `for`, `while`,
50
+ `repeat`, `switch` and `tryCatch`.
51
+ - Base R, including `return`, `utf8ToInt` and `bitwAnd`, and the constants
52
+ `T`, `F`, `pi`, `letters` and `LETTERS`.
53
+
54
+ Nothing is offered inside strings and comments, or after `$`, `@` and `::`.
55
+
56
+ ## Coverage
57
+
58
+ R 4.5. Every assignment R has, including `:=`; functions written with
59
+ `function` and with `\(x)`; `if`, `for`, `while` and `repeat` with braces and
60
+ without; calls with named, empty and dotted arguments; `[`, `[[` and their
61
+ empty subscripts; `::`, `:::`, `$` and `@`; formulas; the native pipe and the
62
+ ones packages define between percent signs; raw strings; backtick names;
63
+ integer, double, hexadecimal and complex literals; roxygen comments; and `...`,
64
+ `..1` and the pipe placeholder.
65
+
66
+ Measured against 2 322 R files from eight open source projects (R itself,
67
+ ggplot2, dplyr, tidyr, data.table, shiny, testthat and devtools), which is
68
+ 15 MiB of code, of which 99.70% parse with no error node. The seven files that
69
+ do not are not R: three are fixtures in R's own test suite that hold a
70
+ deliberate parse error, two are shiny templates holding `{{ }}` placeholders,
71
+ one is testthat's `syntax-error` fixture, and one is written in Latin-1.
72
+
73
+ ## What the grammar cannot say
74
+
75
+ The grammar is a port of `src/main/gram.y` from the R sources, which is an
76
+ LALR grammar and so nearly a Lezer grammar already. Its precedence table is R's
77
+ read from the other end, and every production answers to one there. Three
78
+ things are settled in `src/tokens.ts` instead, because no context free rule can
79
+ decide them.
80
+
81
+ **A line break ends an expression when the expression is finished.** R has no
82
+ statement terminator. `x <- 1` followed by a line holding `-2` is two
83
+ expressions, and `x <- 1 +` followed by a line holding `2` is one. The
84
+ tokenizer offers a terminator of no width at every line break and the parser
85
+ takes it only where an expression may end, which is nowhere inside a bracket
86
+ and nowhere after an operator still waiting for its right hand side. That is
87
+ the whole rule, and it needs one exception: a line may open with `else`, which
88
+ R itself allows inside braces and refuses outside them.
89
+
90
+ **A raw string carries its own delimiter.** `r"(a\d+)"` holds a backslash and
91
+ ends at `)"`. `r"---(x)---"` ends only at the dashes it opened with, and how
92
+ many there were is not something a regular expression can remember.
93
+
94
+ **A string is cut into pieces.** The escapes inside it are coloured apart from
95
+ the text around them, so the tokenizer hands over a start, the runs of text,
96
+ the escapes and an end. Each quote character has its own set of those tokens,
97
+ which is how the tokenizer knows what it is looking for without keeping any
98
+ state.
99
+
100
+ ## Building and testing
101
+
102
+ ```bash
103
+ npm install # installs the dependencies and builds dist/
104
+ npm run build # regenerates the parser and rebuilds dist/
105
+ npm test # builds, then runs the tests
106
+ ```
107
+
108
+ ## Contributing
109
+
110
+ Please read about how to [contribute to Exercism](https://exercism.org/docs/building).
111
+ Be sure to read the Exercism [Code of Conduct](https://exercism.org/docs/using/legal/code-of-conduct).