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) @variable
34
35((identifier) @keyword
36 (#match? @keyword "^(private|protected|public)$"))
37
38; Function calls
39
40((identifier) @function.method.builtin
41 (#eq? @function.method.builtin "require"))
42
43"defined?" @function.method.builtin
44
45(call
46 method: [(identifier) (constant)] @function.method)
47
48; Function definitions
49
50(alias (identifier) @function.method)
51(setter (identifier) @function.method)
52(method name: [(identifier) (constant)] @function.method)
53(singleton_method name: [(identifier) (constant)] @function.method)
54
55; Identifiers
56
57[
58 (class_variable)
59 (instance_variable)
60] @property
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((constant) @constant
74 (#match? @constant "^[A-Z\\d_]+$"))
75
76(constant) @type
77
78(self) @variable.special
79(super) @variable.special
80
81; Literals
82
83[
84 (string)
85 (bare_string)
86 (subshell)
87 (heredoc_body)
88 (heredoc_beginning)
89] @string
90
91[
92 (simple_symbol)
93 (delimited_symbol)
94 (hash_key_symbol)
95 (bare_symbol)
96] @string.special.symbol
97
98(regex) @string.regex
99(escape_sequence) @escape
100
101[
102 (integer)
103 (float)
104] @number
105
106[
107 (nil)
108 (true)
109 (false)
110] @constant.builtin
111
112(comment) @comment
113
114; Operators
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 (operator)
160] @operator
161
162[
163 ","
164 ";"
165 "."
166] @punctuation.delimiter
167
168[
169 "("
170 ")"
171 "["
172 "]"
173 "{"
174 "}"
175 "%w("
176 "%i("
177] @punctuation.bracket
178
179(interpolation
180 "#{" @punctuation.special
181 "}" @punctuation.special) @embedded