From 773ec8eefc6509dcde1b67f0913e879634dbccf2 Mon Sep 17 00:00:00 2001 From: echasnovski Date: Tue, 9 Mar 2021 21:06:07 +0200 Subject: Add support for R language. --- lua/nvim-treesitter/parsers.lua | 8 ++++ queries/r/highlights.scm | 86 +++++++++++++++++++++++++++++++++++++++++ queries/r/locals.scm | 11 ++++++ 3 files changed, 105 insertions(+) create mode 100755 queries/r/highlights.scm create mode 100755 queries/r/locals.scm diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index a1727fc10..2c6022175 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -474,6 +474,14 @@ list.svelte = { maintainers = { "@elianiva" }, } +list.r = { + install_info = { + url = "https://github.com/r-lib/tree-sitter-r", + files = { "src/parser.c" } + }, + maintainers = { "@jimhester" }, +} + local M = { list = list } diff --git a/queries/r/highlights.scm b/queries/r/highlights.scm new file mode 100755 index 000000000..11f355e83 --- /dev/null +++ b/queries/r/highlights.scm @@ -0,0 +1,86 @@ +; highlights.scm + +(call function: (identifier) @function) +(namespace_get function: (identifier) @function.method) +(namespace_get_internal function: (identifier) @function.method) + +; Literals + +(integer) @number + +(float) @number + +(complex) @number + +(string) @string + +(comment) @comment + +(formal_parameters (identifier) @variable.parameter) + +(identifier) @variable + +; Operators +[ + "=" + "<-" + "<<-" + "->" +] @operator + +(unary operator: [ + "-" + "+" + "!" + "~" +] @operator) + +(binary operator: [ + "-" + "+" + "*" + "/" + "^" + "<" + ">" + "<=" + ">=" + "==" + "!=" + "||" + "|" + "&&" + "&" + ":" + "~" +] @operator) + +(special) @operator + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +[ + "while" + "if" + "else" + "function" + "repeat" + "for" + "in" + (dots) + (true) + (false) + (break) + (next) + (inf) + (nan) + (na) + (null) +] @keyword diff --git a/queries/r/locals.scm b/queries/r/locals.scm new file mode 100755 index 000000000..be6cc6379 --- /dev/null +++ b/queries/r/locals.scm @@ -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 -- cgit v1.2.3-70-g09d2