summaryrefslogtreecommitdiff
path: root/runtime/queries/ruby/highlights.scm
blob: 7c69276ba6cf04efeb71a08fa4bf1933fe63321a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
; Keywords

[
  "BEGIN"
  "END"
  "alias"
  "begin"
  "class"
  "do"
  "end"
  "module"
  "in"
  "rescue"
  "ensure"
] @keyword

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

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

[
  "yield"
  "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.control.exception
 (#match? @keyword.control.exception "^(raise|fail)$"))

; Function calls

((identifier) @function.builtin
 (#match? @function.builtin "^(attr|attr_accessor|attr_reader|attr_writer|include|prepend|refine|private|protected|public)$"))

"defined?" @function.builtin

(call
  method: [(identifier) (constant)] @function.method)

; Function definitions

(alias (identifier) @function.method)
(setter (identifier) @function.method)
(method name: [(identifier) (constant)] @function.method)
(singleton_method name: [(identifier) (constant)] @function.method)

; Identifiers

[
  (class_variable)
  (instance_variable)
] @variable.other.member

((identifier) @constant.builtin
 (#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) @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)

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

; Literals

[
  (string)
  (bare_string)
  (subshell)
  (heredoc_body)
  (heredoc_beginning)
] @string

[
  (simple_symbol)
  (delimited_symbol)
  (bare_symbol)
] @string.special.symbol

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

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

[
  (integer)
  (float)
] @constant.numeric.integer

[
  (nil)
  (true)
  (false)
] @constant.builtin

(interpolation
  "#{" @punctuation.special
  "}" @punctuation.special) @embedded

(comment) @comment

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

(assignment
  "=" @operator)

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

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

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

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

[
  "|"
  "("
  ")"
  "["
  "]"
  "{"
  "}"
  "%w("
  "%i("
] @punctuation.bracket