Skip to content

Commit 31c468a

Browse files
authored
add languages r and rmarkdown (#1998)
* add languages `r` and `rmarkdown` * r: fix highlights * rmarkdown: add eof in queries * rmarkdown: update lang-support.md * r: fix highlight query precedence
1 parent d37369c commit 31c468a

7 files changed

Lines changed: 169 additions & 0 deletions

File tree

book/src/generated/lang-support.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@
5050
| prolog | | | | `swipl` |
5151
| protobuf || || |
5252
| python |||| `pylsp` |
53+
| r || | | `R` |
5354
| racket | | | | `racket` |
5455
| regex || | | |
5556
| rescript ||| | `rescript-language-server` |
57+
| rmarkdown || || `R` |
5658
| ron || || |
5759
| ruby || || `solargraph` |
5860
| rust |||| `rust-analyzer` |

languages.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,3 +1038,28 @@ roots = []
10381038
comment-token = "//"
10391039
indent = { tab-width = 4, unit = " " }
10401040
grammar = "rust"
1041+
1042+
[[language]]
1043+
name = "r"
1044+
scope = "source.r"
1045+
injection-regex = "(r|R)"
1046+
file-types = ["r", "R"]
1047+
shebangs = ["r", "R"]
1048+
roots = []
1049+
comment-token = "#"
1050+
indent = { tab-width = 2, unit = " " }
1051+
language-server = { command = "R", args = ["--slave", "-e", "languageserver::run()"] }
1052+
1053+
[[grammar]]
1054+
name = "r"
1055+
source = { git = "https://github.com/r-lib/tree-sitter-r", rev = "cc04302e1bff76fa02e129f332f44636813b0c3c" }
1056+
1057+
[[language]]
1058+
name = "rmarkdown"
1059+
scope = "source.rmd"
1060+
injection-regex = "(r|R)md"
1061+
file-types = ["rmd", "Rmd"]
1062+
roots = []
1063+
indent = { tab-width = 2, unit = " " }
1064+
grammar = "markdown"
1065+
language-server = { command = "R", args = ["--slave", "-e", "languageserver::run()"] }

runtime/queries/r/highlights.scm

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
; highlights.scm
2+
3+
4+
; Literals
5+
6+
(integer) @constant.numeric.integer
7+
8+
(float) @constant.numeric.float
9+
10+
(complex) @constant.numeric.integer
11+
12+
(string) @string
13+
(string (escape_sequence) @constant.character.escape)
14+
15+
(comment) @comment
16+
17+
(formal_parameters (identifier) @variable.parameter)
18+
(formal_parameters (default_parameter (identifier) @variable.parameter))
19+
20+
; Operators
21+
[
22+
"="
23+
"<-"
24+
"<<-"
25+
"->>"
26+
"->"
27+
] @operator
28+
29+
(unary operator: [
30+
"-"
31+
"+"
32+
"!"
33+
"~"
34+
] @operator)
35+
36+
(binary operator: [
37+
"-"
38+
"+"
39+
"*"
40+
"/"
41+
"^"
42+
"<"
43+
">"
44+
"<="
45+
">="
46+
"=="
47+
"!="
48+
"||"
49+
"|"
50+
"&&"
51+
"&"
52+
":"
53+
"~"
54+
] @operator)
55+
56+
[
57+
"|>"
58+
(special)
59+
] @operator
60+
61+
(lambda_function "\\" @operator)
62+
63+
[
64+
"("
65+
")"
66+
"["
67+
"]"
68+
"{"
69+
"}"
70+
] @punctuation.bracket
71+
72+
(dollar "$" @operator)
73+
74+
(subset2
75+
[
76+
"[["
77+
"]]"
78+
] @punctuation.bracket)
79+
80+
[
81+
"in"
82+
(dots)
83+
(break)
84+
(next)
85+
(inf)
86+
] @keyword
87+
88+
[
89+
(nan)
90+
(na)
91+
(null)
92+
] @type.builtin
93+
94+
[
95+
"if"
96+
"else"
97+
"switch"
98+
] @keyword.control.conditional
99+
100+
[
101+
"while"
102+
"repeat"
103+
"for"
104+
] @keyword.control.repeat
105+
106+
[
107+
(true)
108+
(false)
109+
] @constant.builtin.boolean
110+
111+
"function" @keyword.function
112+
113+
(call function: (identifier) @function)
114+
(default_argument name: (identifier) @variable.parameter)
115+
116+
117+
(namespace_get namespace: (identifier) @namespace
118+
"::" @operator)
119+
(namespace_get_internal namespace: (identifier) @namespace
120+
":::" @operator)
121+
122+
(namespace_get function: (identifier) @function.method)
123+
(namespace_get_internal function: (identifier) @function.method)
124+
125+
(identifier) @variable
126+
127+
; Error
128+
(ERROR) @error

runtime/queries/r/locals.scm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; locals.scm
2+
3+
(function_definition) @local.scope
4+
5+
(formal_parameters (identifier) @local.definition)
6+
7+
(left_assignment name: (identifier) @local.definition)
8+
(equals_assignment name: (identifier) @local.definition)
9+
(right_assignment name: (identifier) @local.definition)
10+
11+
(identifier) @local.reference
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
; inherits: markdown
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
; inherits: markdown
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
; inherits: markdown

0 commit comments

Comments
 (0)