1; Keywords
2
3[
4 "alias"
5 "and"
6 "begin"
7 "break"
8 "case"
9 "class"
10 "def"
11 "do"
12 "else"
13 "elsif"
14 "end"
15 "ensure"
16 "for"
17 "if"
18 "in"
19 "module"
20 "next"
21 "or"
22 "rescue"
23 "retry"
24 "return"
25 "then"
26 "unless"
27 "until"
28 "when"
29 "while"
30 "yield"
31] @keyword
32
33((identifier) @keyword
34 (#match? @keyword "^(private|protected|public)$"))
35
36; Function calls
37
38((identifier) @function.method.builtin
39 (#eq? @function.method.builtin "require"))
40
41"defined?" @function.method.builtin
42
43(call
44 method: [(identifier) (constant)] @function.method)
45
46; Function definitions
47
48(alias (identifier) @function.method)
49(setter (identifier) @function.method)
50(method name: [(identifier) (constant)] @function.method)
51(singleton_method name: [(identifier) (constant)] @function.method)
52(method_parameters [
53 (identifier) @variable.parameter
54 (optional_parameter name: (identifier) @variable.parameter)
55 (keyword_parameter [name: (identifier) (":")] @variable.parameter)
56 ])
57
58(block_parameters (identifier) @variable.parameter)
59
60; Identifiers
61
62((identifier) @constant.builtin
63 (#match? @constant.builtin "^__(FILE|LINE|ENCODING)__$"))
64
65(file) @constant.builtin
66(line) @constant.builtin
67(encoding) @constant.builtin
68
69(hash_splat_nil
70 "**" @operator
71) @constant.builtin
72
73(global_variable) @constant
74
75(constant) @type
76
77((constant) @constant
78 (#match? @constant "^[A-Z\\d_]+$"))
79
80(superclass
81 (constant) @type.super)
82
83(superclass
84 (scope_resolution
85 (constant) @type.super))
86
87(superclass
88 (scope_resolution
89 (scope_resolution
90 (constant) @type.super)))
91
92(self) @variable.special
93(super) @variable.special
94
95[
96 (class_variable)
97 (instance_variable)
98] @variable.member
99
100
101; Literals
102
103[
104 (string)
105 (bare_string)
106 (subshell)
107 (heredoc_body)
108 (heredoc_beginning)
109] @string
110
111[
112 (simple_symbol)
113 (delimited_symbol)
114 (hash_key_symbol)
115 (bare_symbol)
116] @string.special.symbol
117
118(regex) @string.regex
119(escape_sequence) @escape
120
121[
122 (integer)
123 (float)
124] @number
125
126[
127 (nil)
128 (true)
129 (false)
130] @constant.builtin
131
132(comment) @comment
133
134; Operators
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 (operator)
180] @operator
181
182[
183 ","
184 ";"
185 "."
186 "::"
187] @punctuation.delimiter
188
189[
190 "("
191 ")"
192 "["
193 "]"
194 "{"
195 "}"
196 "%w("
197 "%i("
198] @punctuation.bracket
199
200(interpolation
201 "#{" @punctuation.special
202 "}" @punctuation.special) @embedded