aboutsummaryrefslogtreecommitdiffstats
path: root/queries/ruby/highlights.scm
blob: 9e5852cdf1eff6068ce5bdcf86c30ec80e359043 (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
; Keywords

"alias" @keyword
"and" @keyword
"begin" @keyword
"break" @keyword
"case" @conditional
"class" @keyword
"def" @keyword
"do" @keyword
"else" @conditional
"elsif" @conditional
"end" @keyword
"ensure" @keyword
"for" @repeat
"if" @conditional
"in" @keyword
"module" @keyword
"next" @keyword
"or" @keyword
"rescue" @keyword
"retry" @keyword
"return" @keyword
"then" @keyword
"unless" @conditional
"until" @repeat
"when" @conditional
"while" @repeat
"yield" @keyword

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

; Function calls

((identifier) @function
 (#eq? @function "require"))

"defined?" @function

(call
  receiver: (constant) @constant)
(method_call
  receiver: (constant) @constant)
(call
  method: (identifier) @function)
(method_call
  method: (identifier) @function)
(call
  method: (constant) @function)
(method_call
  method: (constant) @function)

; Function definitions

(alias (identifier) @function)
(setter (identifier) @function)
(method name: (identifier) @function)
(method name: (constant) @constant)
(class name: (constant) @constant)
(singleton_method name: (identifier) @function)
(singleton_method name: (constant) @constant)

; Identifiers

(class_variable) @label
(instance_variable) @label

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

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

(constant) @constant

(self) @constant.builtin
(super) @constant.builtin

(method_parameters (identifier) @parameter)
(lambda_parameters (identifier) @parameter)
(block_parameters (identifier) @parameter)
(splat_parameter (identifier) @parameter)
(hash_splat_parameter (identifier) @parameter)
(optional_parameter (identifier) @parameter)
(destructured_parameter (identifier) @parameter)
(block_parameter (identifier) @parameter)
(keyword_parameter (identifier) @parameter)

; TODO: Re-enable this once it is supported
; ((identifier) @function
;  (#is-not? local))

; Literals

(string) @string
(bare_string) @string
(bare_symbol) @constant
(subshell) @string
(heredoc_beginning) @constant
(heredoc_body) @string
(heredoc_end) @constant
(symbol) @constant
(regex) @string.regex
(escape_sequence) @string.escape
(integer) @number
(float) @float

(nil) @boolean
(true) @boolean
(false) @boolean

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

(comment) @comment

; Operators

"=" @operator
"=>" @operator
"->" @operator
"+" @operator
"-" @operator
"*" @operator
"/" @operator

"," @punctuation.delimiter
";" @punctuation.delimiter
"." @punctuation.delimiter

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

(ERROR) @error