From 50740010879b660242c728dcbeeb771aebabbf88 Mon Sep 17 00:00:00 2001 From: Kai Aragaki <7370516+KaiAragaki@users.noreply.github.com> Date: Sat, 7 Sep 2024 22:08:45 -0400 Subject: [PATCH] fix: update r queries (#736) --- queries/r/highlights.scm | 156 +++++++++++++++++---------------------- queries/r/locals.scm | 15 +++- queries/r/tags.scm | 21 ++++++ repos/r | 2 +- 4 files changed, 101 insertions(+), 93 deletions(-) create mode 100644 queries/r/tags.scm diff --git a/queries/r/highlights.scm b/queries/r/highlights.scm index a9affede..ff538d09 100644 --- a/queries/r/highlights.scm +++ b/queries/r/highlights.scm @@ -1,106 +1,90 @@ ; highlights.scm - ; Literals (integer) @number - -(float) @float - +(float) @number (complex) @number (string) @string -(string (escape_sequence) @string.escape) - -(comment) @comment +(string (string_content (escape_sequence) @string.escape)) -;; tune for tree-sitter-langs as it make all as variable -;; (identifier) @variable -(left_assignment name: (identifier) @variable) -(equals_assignment name: (identifier) @variable) -(right_assignment name: (identifier) @variable) +; Comments -(formal_parameters (identifier) @parameter) -(formal_parameters (default_parameter (identifier) @parameter)) +(comment) @comment ; Operators -[ - "=" - "<-" - "<<-" - "->>" - "->" -] @operator - -(unary operator: [ - "-" - "+" - "!" - "~" -] @operator) - -(binary operator: [ - "-" - "+" - "*" - "/" - "^" - "<" - ">" - "<=" - ">=" - "==" - "!=" - "||" - "|" - "&&" - "&" - ":" - "~" -] @operator) [ - "|>" - (special) + "?" ":=" "=" "<-" "<<-" "->" "->>" + "~" "|>" "||" "|" "&&" "&" + "<" "<=" ">" ">=" "==" "!=" + "+" "-" "*" "/" "::" ":::" + "**" "^" "$" "@" ":" + "special" ] @operator -(lambda_function "\\" @operator) +; Punctuation [ - "(" - ")" - "[" - "]" - "{" - "}" + "(" ")" + "{" "}" + "[" "]" + "[[" "]]" ] @punctuation.bracket -(dollar "$" @operator) +(comma) @punctuation.delimiter -(subset2 - [ - "[[" - "]]" - ] @punctuation.bracket) +; Variables -[ - "in" - (dots) - (break) - (next) - (inf) -] @keyword +(identifier) @variable + +; Functions + +(binary_operator + lhs: (identifier) @function + operator: "<-" + rhs: (function_definition) +) + +(binary_operator + lhs: (identifier) @function + operator: "=" + rhs: (function_definition) +) + +; Calls + +(call function: (identifier) @function) + +; Parameters + +(parameters (parameter name: (identifier) @variable.parameter)) +(arguments (argument name: (identifier) @variable.parameter)) + +; Namespace + +(namespace_operator lhs: (identifier) @namespace) + +(call + function: (namespace_operator rhs: (identifier) @function) +) + +; Keywords + +(function_definition name: "function" @keyword.function) +(function_definition name: "\\" @operator) [ - (nan) - (na) - (null) -] @type.builtin + "in" + (return) + (next) + (break) +] @keyword [ "if" "else" - "switch" ] @conditional [ @@ -114,19 +98,15 @@ (false) ] @boolean -"function" @keyword.function - -(call function: (identifier) @function) -(default_argument name: (identifier) @parameter) - - -(namespace_get function: (identifier) @method) -(namespace_get_internal function: (identifier) @method) - -(namespace_get namespace: (identifier) @namespace - "::" @operator) -(namespace_get_internal namespace: (identifier) @namespace - ":::" @operator) +[ + (null) + (inf) + (nan) + (na) + (dots) + (dot_dot_i) +] @constant.builtin ; Error + (ERROR) @error diff --git a/queries/r/locals.scm b/queries/r/locals.scm index be6cc637..5d4697a5 100644 --- a/queries/r/locals.scm +++ b/queries/r/locals.scm @@ -2,10 +2,17 @@ (function_definition) @local.scope -(formal_parameters (identifier) @local.definition) +(argument name: (identifier) @local.definition) +(parameter name: (identifier) @local.definition) -(left_assignment name: (identifier) @local.definition) -(equals_assignment name: (identifier) @local.definition) -(right_assignment name: (identifier) @local.definition) +(binary_operator + lhs: (identifier) @local.definition + operator: "<-") +(binary_operator + lhs: (identifier) @local.definition + operator: "=") +(binary_operator + operator: "->" + rhs: (identifier) @local.definition) (identifier) @local.reference diff --git a/queries/r/tags.scm b/queries/r/tags.scm new file mode 100644 index 00000000..39809c59 --- /dev/null +++ b/queries/r/tags.scm @@ -0,0 +1,21 @@ +(binary_operator + lhs: (identifier) @name + operator: "<-" + rhs: (function_definition) +) @definition.function + +(binary_operator + lhs: (identifier) @name + operator: "=" + rhs: (function_definition) +) @definition.function + +(call + function: (identifier) @name +) @reference.call + +(call + function: (namespace_operator + rhs: (identifier) @name + ) +) @reference.call diff --git a/repos/r b/repos/r index 39140057..b1e211f5 160000 --- a/repos/r +++ b/repos/r @@ -1 +1 @@ -Subproject commit 391400572538ff9854341a175ed8ab4b1e45f44b +Subproject commit b1e211f52ad8f8e1e182bbbcc16dcd5e3688eb7d