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
This commit is contained in:
Matthew Toohey 2022-04-07 20:30:44 -04:00 committed by GitHub
parent d37369c1e0
commit 31c468ab95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 169 additions and 0 deletions

View File

@ -50,9 +50,11 @@
| prolog | | | | `swipl` | | prolog | | | | `swipl` |
| protobuf | ✓ | | ✓ | | | protobuf | ✓ | | ✓ | |
| python | ✓ | ✓ | ✓ | `pylsp` | | python | ✓ | ✓ | ✓ | `pylsp` |
| r | ✓ | | | `R` |
| racket | | | | `racket` | | racket | | | | `racket` |
| regex | ✓ | | | | | regex | ✓ | | | |
| rescript | ✓ | ✓ | | `rescript-language-server` | | rescript | ✓ | ✓ | | `rescript-language-server` |
| rmarkdown | ✓ | | ✓ | `R` |
| ron | ✓ | | ✓ | | | ron | ✓ | | ✓ | |
| ruby | ✓ | | ✓ | `solargraph` | | ruby | ✓ | | ✓ | `solargraph` |
| rust | ✓ | ✓ | ✓ | `rust-analyzer` | | rust | ✓ | ✓ | ✓ | `rust-analyzer` |

View File

@ -1038,3 +1038,28 @@ roots = []
comment-token = "//" comment-token = "//"
indent = { tab-width = 4, unit = " " } indent = { tab-width = 4, unit = " " }
grammar = "rust" grammar = "rust"
[[language]]
name = "r"
scope = "source.r"
injection-regex = "(r|R)"
file-types = ["r", "R"]
shebangs = ["r", "R"]
roots = []
comment-token = "#"
indent = { tab-width = 2, unit = " " }
language-server = { command = "R", args = ["--slave", "-e", "languageserver::run()"] }
[[grammar]]
name = "r"
source = { git = "https://github.com/r-lib/tree-sitter-r", rev = "cc04302e1bff76fa02e129f332f44636813b0c3c" }
[[language]]
name = "rmarkdown"
scope = "source.rmd"
injection-regex = "(r|R)md"
file-types = ["rmd", "Rmd"]
roots = []
indent = { tab-width = 2, unit = " " }
grammar = "markdown"
language-server = { command = "R", args = ["--slave", "-e", "languageserver::run()"] }

View File

@ -0,0 +1,128 @@
; highlights.scm
; Literals
(integer) @constant.numeric.integer
(float) @constant.numeric.float
(complex) @constant.numeric.integer
(string) @string
(string (escape_sequence) @constant.character.escape)
(comment) @comment
(formal_parameters (identifier) @variable.parameter)
(formal_parameters (default_parameter (identifier) @variable.parameter))
; Operators
[
"="
"<-"
"<<-"
"->>"
"->"
] @operator
(unary operator: [
"-"
"+"
"!"
"~"
] @operator)
(binary operator: [
"-"
"+"
"*"
"/"
"^"
"<"
">"
"<="
">="
"=="
"!="
"||"
"|"
"&&"
"&"
":"
"~"
] @operator)
[
"|>"
(special)
] @operator
(lambda_function "\\" @operator)
[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket
(dollar "$" @operator)
(subset2
[
"[["
"]]"
] @punctuation.bracket)
[
"in"
(dots)
(break)
(next)
(inf)
] @keyword
[
(nan)
(na)
(null)
] @type.builtin
[
"if"
"else"
"switch"
] @keyword.control.conditional
[
"while"
"repeat"
"for"
] @keyword.control.repeat
[
(true)
(false)
] @constant.builtin.boolean
"function" @keyword.function
(call function: (identifier) @function)
(default_argument name: (identifier) @variable.parameter)
(namespace_get namespace: (identifier) @namespace
"::" @operator)
(namespace_get_internal namespace: (identifier) @namespace
":::" @operator)
(namespace_get function: (identifier) @function.method)
(namespace_get_internal function: (identifier) @function.method)
(identifier) @variable
; Error
(ERROR) @error

View File

@ -0,0 +1,11 @@
; locals.scm
(function_definition) @local.scope
(formal_parameters (identifier) @local.definition)
(left_assignment name: (identifier) @local.definition)
(equals_assignment name: (identifier) @local.definition)
(right_assignment name: (identifier) @local.definition)
(identifier) @local.reference

View File

@ -0,0 +1 @@
; inherits: markdown

View File

@ -0,0 +1 @@
; inherits: markdown

View File

@ -0,0 +1 @@
; inherits: markdown