diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index c380a03b..164cb9c0 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -237,7 +237,7 @@ | qmv | | | | | | | | quarto | ✓ | | ✓ | | | | | quint | ✓ | | | | | `quint-language-server` | -| r | ✓ | | | | | `R` | +| r | ✓ | ✓ | | ✓ | ✓ | `R` | | racket | ✓ | | ✓ | | ✓ | `racket` | | regex | ✓ | | | | ✓ | | | rego | ✓ | | | | | `regols` | diff --git a/languages.toml b/languages.toml index b820bfc4..118a58e9 100644 --- a/languages.toml +++ b/languages.toml @@ -2518,7 +2518,7 @@ language-servers = [ "r" ] [[grammar]] name = "r" -source = { git = "https://github.com/r-lib/tree-sitter-r", rev = "cc04302e1bff76fa02e129f332f44636813b0c3c" } +source = { git = "https://github.com/r-lib/tree-sitter-r", rev = "0e6ef7741712c09dc3ee6e81c42e919820cc65ef" } [[language]] name = "rmarkdown" diff --git a/runtime/queries/r/highlights.scm b/runtime/queries/r/highlights.scm index 779d223b..8d664a74 100644 --- a/runtime/queries/r/highlights.scm +++ b/runtime/queries/r/highlights.scm @@ -12,6 +12,7 @@ [ (float) (nan) + (inf) ] @constant.numeric.float [ @@ -22,88 +23,76 @@ [ (na) (null) + (dots) + (dot_dot_i) ] @constant.builtin (string) @string -(string (escape_sequence) @constant.character.escape) +(string (string_content (escape_sequence) @constant.character.escape)) -(comment) @comment +; Comments -(formal_parameters (identifier) @variable.parameter) -(formal_parameters (default_parameter (identifier) @variable.parameter)) +(comment) @comment ; Operators -[ - "=" - "<-" - "<<-" - "->>" - "->" -] @operator - -(unary operator: [ - "-" - "+" - "!" - "~" -] @operator) - -(binary operator: [ - "-" - "+" - "*" - "/" - "^" - "<" - ">" - "<=" - ">=" - "==" - "!=" - "||" - "|" - "&&" - "&" - ":" - "~" -] @operator) [ - "|>" - (special) + "!" "!=" "$" "&" "&&" "*" "**" "+" "-" "->" "->>" "/" ":" ":::" ":::" ":=" "<" + "<-" "<<-" "<=" "=" "==" ">" ">=" "?" "@" "^" "special" "|" "|>" "||" "~" ] @operator -(lambda_function "\\" @operator) +(function_definition name: "\\" @operator) + +; Punctuation [ - "(" - ")" - "[" - "]" - "{" - "}" + "(" ")" + "[" "]" + "{" "}" + "[[" "]]" ] @punctuation.bracket -(dollar "$" @operator) +(comma) @punctuation.delimiter -(subset2 - [ - "[[" - "]]" - ] @punctuation.bracket) +; Functions + +(binary_operator + lhs: (identifier) @function + operator: "<-" + rhs: (function_definition)) + +(binary_operator + lhs: (identifier) @function + operator: "=" + rhs: (function_definition)) + +; Calls + +(call function: (identifier) @function) +(call function: (namespace_operator rhs: (identifier) @function)) + +; Parameters + +(parameters (parameter name: (identifier) @variable.parameter)) +(arguments (argument name: (identifier) @variable.parameter)) + +; Namespaces + +(namespace_operator lhs: (identifier) @namespace) + +; Keywords [ - "in" - (dots) - (break) - (next) - (inf) + "in" + (next) + (break) ] @keyword +(return) @keyword.control.return + [ "if" "else" - "switch" ] @keyword.control.conditional [ @@ -114,14 +103,3 @@ "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) diff --git a/runtime/queries/r/locals.scm b/runtime/queries/r/locals.scm index ddfd09e6..0650222d 100644 --- a/runtime/queries/r/locals.scm +++ b/runtime/queries/r/locals.scm @@ -2,6 +2,6 @@ (function_definition) @local.scope -(formal_parameters (identifier) @local.definition.variable.parameter) +(parameters (parameter name: (identifier) @local.definition.variable.parameter)) (identifier) @local.reference diff --git a/runtime/queries/r/rainbows.scm b/runtime/queries/r/rainbows.scm new file mode 100644 index 00000000..8b332dd6 --- /dev/null +++ b/runtime/queries/r/rainbows.scm @@ -0,0 +1,16 @@ +[ + (parameters) + (if_statement) + (for_statement) + (while_statement) + (braced_expression) + (parenthesized_expression) + (arguments) +] @rainbow.scope + +[ + "(" ")" + "[" "]" + "{" "}" + "[[" "]]" +] @rainbow.bracket diff --git a/runtime/queries/r/tags.scm b/runtime/queries/r/tags.scm new file mode 100644 index 00000000..1462b778 --- /dev/null +++ b/runtime/queries/r/tags.scm @@ -0,0 +1,9 @@ +(binary_operator + lhs: [(identifier) (string)] @name + operator: "<-" + rhs: (function_definition)) @definition.function + +(binary_operator + lhs: [(identifier) (string)] @name + operator: "=" + rhs: (function_definition)) @definition.function diff --git a/runtime/queries/r/textobjects.scm b/runtime/queries/r/textobjects.scm new file mode 100644 index 00000000..451a4c8a --- /dev/null +++ b/runtime/queries/r/textobjects.scm @@ -0,0 +1,16 @@ +; Comments + +(comment) @comment.inside +(comment)+ @comment.around + +; Functions + +(function_definition body: (_) @function.inside) @function.around + +; Parameters + +(parameters + ((_) @parameter.inside . (comma)? @parameter.around) @parameter.around) + +(arguments + ((_) @parameter.inside . (comma)? @parameter.around) @parameter.around)