1; Variables
2
3(identifier) @variable
4
5; Parameters
6
7(parameter
8 name: (identifier) @variable.parameter)
9
10; Types
11
12(parameter
13 type: (identifier) @type)
14
15((identifier) @type
16 (#match? @type "^[A-Z_][a-zA-Z0-9_]*"))
17
18(variable_declaration
19 (identifier) @type
20 "="
21 [
22 (struct_declaration)
23 (enum_declaration)
24 (union_declaration)
25 (opaque_declaration)
26 ])
27
28[
29 (builtin_type)
30 "anyframe"
31] @type.builtin
32
33; Constants
34
35((identifier) @constant
36 (#match? @constant "^[A-Z][A-Z_0-9]+$"))
37
38[
39 "null"
40 "unreachable"
41 "undefined"
42] @constant.builtin
43
44(field_expression
45 .
46 member: (identifier) @constant)
47
48(enum_declaration
49 (container_field
50 type: (identifier) @constant))
51
52; Labels
53
54(block_label (identifier) @label)
55
56(break_label (identifier) @label)
57
58; Fields
59
60(field_initializer
61 .
62 (identifier) @variable.member)
63
64(field_expression
65 (_)
66 member: (identifier) @property)
67
68(field_expression
69 (_)
70 member: (identifier) @type (#match? @type "^[A-Z_][a-zA-Z0-9_]*"))
71
72(container_field
73 name: (identifier) @property)
74
75(initializer_list
76 (assignment_expression
77 left: (field_expression
78 .
79 member: (identifier) @property)))
80
81; Functions
82
83(builtin_identifier) @function.builtin
84
85(call_expression
86 function: (identifier) @function.call)
87
88(call_expression
89 function: (field_expression
90 member: (identifier) @function.call))
91
92(function_declaration
93 name: (identifier) @function)
94
95; Modules
96
97(variable_declaration
98 (identifier) @module
99 (builtin_function
100 (builtin_identifier) @keyword.import
101 (#any-of? @keyword.import "@import" "@cImport")))
102
103; Builtins
104
105[
106 "c"
107 "..."
108] @variable.builtin
109
110((identifier) @variable.builtin
111 (#eq? @variable.builtin "_"))
112
113(calling_convention
114 (identifier) @variable.builtin)
115
116; Keywords
117
118[
119 "asm"
120 "defer"
121 "errdefer"
122 "test"
123 "error"
124 "const"
125 "var"
126] @keyword
127
128[
129 "struct"
130 "union"
131 "enum"
132 "opaque"
133] @keyword.type
134
135[
136 "async"
137 "await"
138 "suspend"
139 "nosuspend"
140 "resume"
141] @keyword.coroutine
142
143"fn" @keyword.function
144
145[
146 "and"
147 "or"
148 "orelse"
149] @keyword.operator
150
151"return" @keyword.return
152
153[
154 "if"
155 "else"
156 "switch"
157] @keyword.conditional
158
159[
160 "for"
161 "while"
162 "break"
163 "continue"
164] @keyword.repeat
165
166[
167 "usingnamespace"
168 "export"
169] @keyword.import
170
171[
172 "try"
173 "catch"
174] @keyword.exception
175
176[
177 "volatile"
178 "allowzero"
179 "noalias"
180 "addrspace"
181 "align"
182 "callconv"
183 "linksection"
184 "pub"
185 "inline"
186 "noinline"
187 "extern"
188 "comptime"
189 "packed"
190 "threadlocal"
191] @keyword.modifier
192
193; Operator
194
195[
196 "="
197 "*="
198 "*%="
199 "*|="
200 "/="
201 "%="
202 "+="
203 "+%="
204 "+|="
205 "-="
206 "-%="
207 "-|="
208 "<<="
209 "<<|="
210 ">>="
211 "&="
212 "^="
213 "|="
214 "!"
215 "~"
216 "-"
217 "-%"
218 "&"
219 "=="
220 "!="
221 ">"
222 ">="
223 "<="
224 "<"
225 "&"
226 "^"
227 "|"
228 "<<"
229 ">>"
230 "<<|"
231 "+"
232 "++"
233 "+%"
234 "-%"
235 "+|"
236 "-|"
237 "*"
238 "/"
239 "%"
240 "**"
241 "*%"
242 "*|"
243 "||"
244 ".*"
245 ".?"
246 "?"
247 ".."
248] @operator
249
250; Literals
251
252(character) @string
253
254([
255 (string)
256 (multiline_string)
257] @string
258 (#set! "priority" 95))
259
260(integer) @number
261
262(float) @number.float
263
264(boolean) @boolean
265
266(escape_sequence) @string.escape
267
268; Punctuation
269
270[
271 "["
272 "]"
273 "("
274 ")"
275 "{"
276 "}"
277] @punctuation.bracket
278
279[
280 ";"
281 "."
282 ","
283 ":"
284 "=>"
285 "->"
286] @punctuation.delimiter
287
288(payload "|" @punctuation.bracket)
289
290; Comments
291
292(comment) @comment
293
294((comment) @comment.documentation
295 (#match? @comment.documentation "^//(/|!)"))