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