Skip to content

Commit

Permalink
update ruby highlights
Browse files Browse the repository at this point in the history
  • Loading branch information
danillos committed Apr 4, 2023
1 parent 2bdb58f commit 50b5d9a
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 39 deletions.
2 changes: 1 addition & 1 deletion languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ indent = { tab-width = 2, unit = " " }

[[grammar]]
name = "ruby"
source = { git = "https://github.com/tree-sitter/tree-sitter-ruby", rev = "4c600a463d97e36a0ca5ac57e11f3ac8c297a0fa" }
source = { git = "https://github.com/tree-sitter/tree-sitter-ruby", rev = "206c7077164372c596ffa8eaadb9435c28941364" }

[[language]]
name = "bash"
Expand Down
124 changes: 86 additions & 38 deletions runtime/queries/ruby/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,44 +1,71 @@
; Keywords

[
"BEGIN"
"END"
"alias"
"and"
"begin"
"break"
"case"
"class"
"def"
"do"
"else"
"elsif"
"end"
"ensure"
"for"
"if"
"in"
"module"
"next"
"or"
"in"
"rescue"
"retry"
"return"
"then"
"unless"
"until"
"ensure"
] @keyword

[
"if"
"else"
"elsif"
"when"
"case"
"unless"
"then"
] @keyword.control.conditional

[
"for"
"while"
"retry"
"until"
"redo"
] @keyword.control.repeat

[
"yield"
] @keyword
"return"
"next"
"break"
] @keyword.control.return

[
"def"
"undef"
] @keyword.function

((identifier) @keyword.control.import
(#match? @keyword.control.import "^(require|require_relative|load|autoload)$"))

[
"or"
"and"
"not"
] @keyword.operator

((identifier) @keyword
(#match? @keyword "^(private|protected|public)$"))
((identifier) @keyword.control.exception
(#match? @keyword.control.exception "^(raise|fail)$"))


((identifier) @keyword.storage.modifier
(#match? @keyword.storage.modifier "^(private|protected|public)$"))

; Function calls

((identifier) @function.method.builtin
(#eq? @function.method.builtin "require"))
((identifier) @function.builtin
(#match? @function.builtin "^(attr|attr_accessor|attr_reader|attr_writer|include|prepend|refine)$"))

"defined?" @function.method.builtin
"defined?" @function.builtin

(call
method: [(identifier) (constant)] @function.method)
Expand All @@ -58,30 +85,34 @@
] @variable.other.member

((identifier) @constant.builtin
(#match? @constant.builtin "^__(FILE|LINE|ENCODING)__$"))
(#match? @constant.builtin "^(__FILE__|__LINE__|__ENCODING__)$"))

((constant) @constant.builtin
(#match? @constant.builtin "^(ENV|ARGV|ARGF|RUBY_PLATFORM|RUBY_RELEASE_DATE|RUBY_VERSION|STDERR|STDIN|STDOUT|TOPLEVEL_BINDING)$"))

((constant) @constant
(#match? @constant "^[A-Z\\d_]+$"))

(constant) @constructor

(self) @variable.builtin
(super) @variable.builtin
(super) @function.builtin

[(forward_parameter)(forward_argument)] @variable.parameter
(keyword_parameter name:((_)":" @variable.parameter) @variable.parameter)
(optional_parameter name:((_)"=" @operator) @variable.parameter)
(optional_parameter name: (identifier) @variable.parameter)
(splat_parameter name: (identifier) @variable.parameter) @variable.parameter
(hash_splat_parameter name: (identifier) @variable.parameter) @variable.parameter
(method_parameters (identifier) @variable.parameter)
(block_parameter (identifier) @variable.parameter)
(block_parameters (identifier) @variable.parameter)
(destructured_parameter (identifier) @variable.parameter)
(hash_splat_parameter (identifier) @variable.parameter)
(lambda_parameters (identifier) @variable.parameter)
(method_parameters (identifier) @variable.parameter)
(splat_parameter (identifier) @variable.parameter)

(keyword_parameter name: (identifier) @variable.parameter)
(optional_parameter name: (identifier) @variable.parameter)

((identifier) @function.method
(#is-not? local))
(identifier) @variable
[
(identifier)
] @variable

; Literals

Expand All @@ -96,10 +127,11 @@
[
(simple_symbol)
(delimited_symbol)
(hash_key_symbol)
(bare_symbol)
] @string.special.symbol

(pair key: ((_)":" @string.special.symbol) @string.special.symbol)

(regex) @string.regexp
(escape_sequence) @constant.character.escape

Expand All @@ -112,7 +144,7 @@
(nil)
(true)
(false)
]@constant.builtin
] @constant.builtin

(interpolation
"#{" @punctuation.special
Expand All @@ -121,20 +153,36 @@
(comment) @comment

; Operators

[
"="
":"
"?"
"~"
"=>"
"->"
"!"
] @operator

(assignment
"=" @operator)

(operator_assignment
operator: ["+=" "-=" "*=" "**=" "/=" "||=" "|=" "&&=" "&=" "%=" ">>=" "<<=" "^="] @operator)

(binary
operator: ["/" "|" "==" "===" "||" "&&" ">>" "<<" "<" ">" "<=" ">=" "&" "^" "!~" "=~" "<=>" "**" "*" "!=" "%" "-" "+"] @operator)

(range
operator: [".." "..."] @operator)

[
","
";"
"."
"&."
] @punctuation.delimiter

[
"|"
"("
")"
"["
Expand Down
6 changes: 6 additions & 0 deletions runtime/queries/ruby/injections.scm
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
((comment) @injection.content
(#set! injection.language "comment"))

((heredoc_beginning) @name
(heredoc_body
(heredoc_content) @injection.content
(#set! injection.language "sql"))
(#eq? @name "<<~SQL"))

0 comments on commit 50b5d9a

Please sign in to comment.