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; Identifiers
59
60((identifier) @constant.builtin
61 (#match? @constant.builtin "^__(FILE|LINE|ENCODING)__$"))
62
63(file) @constant.builtin
64(line) @constant.builtin
65(encoding) @constant.builtin
66
67(hash_splat_nil
68 "**" @operator
69) @constant.builtin
70
71((constant) @constant
72 (#match? @constant "^[A-Z\\d_]+$"))
73
74(global_variable) @constant
75
76(constant) @type
77
78(self) @variable.special
79(super) @variable.special
80
81[
82 (class_variable)
83 (instance_variable)
84] @variable.member
85
86
87; Literals
88
89[
90 (string)
91 (bare_string)
92 (subshell)
93 (heredoc_body)
94 (heredoc_beginning)
95] @string
96
97[
98 (simple_symbol)
99 (delimited_symbol)
100 (hash_key_symbol)
101 (bare_symbol)
102] @string.special.symbol
103
104(regex) @string.regex
105(escape_sequence) @escape
106
107[
108 (integer)
109 (float)
110] @number
111
112[
113 (nil)
114 (true)
115 (false)
116] @constant.builtin
117
118(comment) @comment
119
120; Operators
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 (operator)
166] @operator
167
168[
169 ","
170 ";"
171 "."
172] @punctuation.delimiter
173
174[
175 "("
176 ")"
177 "["
178 "]"
179 "{"
180 "}"
181 "%w("
182 "%i("
183] @punctuation.bracket
184
185(interpolation
186 "#{" @punctuation.special
187 "}" @punctuation.special) @embedded