Skip to content

Commit f1b8f54

Browse files
maikol-solismeain
authored andcommitted
Add R support
I use the original work from the PRs #45 (Jen-Chieh Shen, @jcs090218, jcs090218@gmail.com) and #104 (Shuguang Sun, @ShuguangSun, shuguang79@qq.com); rebased against master and updated the submodule to the latest version. Also, I added a changelog entry.
1 parent c4de103 commit f1b8f54

File tree

6 files changed

+150
-1
lines changed

6 files changed

+150
-1
lines changed

.gitmodules

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,10 @@
222222
url = https://github.com/WhatsApp/tree-sitter-erlang
223223
branch = main
224224
update = none
225-
ignore = dirty
225+
ignore = dirty
226+
[submodule "repos/r"]
227+
path = repos/r
228+
url = https://github.com/r-lib/tree-sitter-r.git
229+
branch = master
230+
update = none
231+
ignore = dirty

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Changelog
22

33
## Unreleased
4+
- Add `R` grammar
5+
46

57
## 0.12.5 - 2022-11-14
68
- Add `erlang` grammar

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

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

repos/r

Submodule r added at 80efda5

tree-sitter-langs.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ See `tree-sitter-langs-repos'."
109109
(elm-mode . elm)
110110
(elixir-mode . elixir)
111111
(erlang-mode . erlang)
112+
(ess-r-mode . r)
112113
(go-mode . go)
113114
(haskell-mode . haskell)
114115
(hcl-mode . hcl)

0 commit comments

Comments
 (0)