Skip to content

Commit

Permalink
fix: update r queries (#736)
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiAragaki authored Sep 8, 2024
1 parent 7007cbc commit 5074001
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 93 deletions.
156 changes: 68 additions & 88 deletions queries/r/highlights.scm
Original file line number Diff line number Diff line change
@@ -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

[
Expand All @@ -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
15 changes: 11 additions & 4 deletions queries/r/locals.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 21 additions & 0 deletions queries/r/tags.scm
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion repos/r
Submodule r updated 139 files

0 comments on commit 5074001

Please sign in to comment.