@@ -0,0 +1,336 @@
1+; -------
2+; Tree-Sitter doesn't allow overrides in regards to captures,
3+; though it is possible to affect the child node of a captured
4+; node. Thus, the approach here is to flip the order so that
5+; overrides are unnecessary.
6+; -------
7+
8+; -------
9+; Types
10+; -------
11+
12+; ---
13+; Primitives
14+; ---
15+
16+(escape_sequence) @constant.character.escape
17+(primitive_type) @type.builtin
18+(boolean_literal) @constant.builtin.boolean
19+(integer_literal) @constant.numeric.integer
20+(float_literal) @constant.numeric.float
21+(char_literal) @constant.character
22+[
23+ (string_literal)
24+ (raw_string_literal)
25+] @string
26+[
27+ (line_comment)
28+ (block_comment)
29+] @comment
30+
31+; ---
32+; Extraneous
33+; ---
34+
35+(self) @variable.builtin
36+(enum_variant (identifier) @type.enum.variant)
37+
38+(field_initializer
39+ (field_identifier) @variable.other.member)
40+(shorthand_field_initializer
41+ (identifier) @variable.other.member)
42+(shorthand_field_identifier) @variable.other.member
43+
44+(loop_label
45+ "'" @label
46+ (identifier) @label)
47+
48+; ---
49+; Punctuation
50+; ---
51+
52+[
53+ "::"
54+ "."
55+ ";"
56+ ","
57+] @punctuation.delimiter
58+
59+[
60+ "("
61+ ")"
62+ "["
63+ "]"
64+ "{"
65+ "}"
66+ "#"
67+] @punctuation.bracket
68+(type_arguments
69+ [
70+ "<"
71+ ">"
72+ ] @punctuation.bracket)
73+(type_parameters
74+ [
75+ "<"
76+ ">"
77+ ] @punctuation.bracket)
78+(closure_parameters
79+ "|" @punctuation.bracket)
80+
81+; ---
82+; Variables
83+; ---
84+
85+(let_declaration
86+ pattern: [
87+ ((identifier) @variable)
88+ ((tuple_pattern
89+ (identifier) @variable))
90+ ])
91+
92+; It needs to be anonymous to not conflict with `call_expression` further below.
93+(_
94+ value: (field_expression
95+ value: (identifier)? @variable
96+ field: (field_identifier) @variable.other.member))
97+
98+(parameter
99+ pattern: (identifier) @variable.parameter)
100+(closure_parameters
101+ (identifier) @variable.parameter)
102+
103+; -------
104+; Keywords
105+; -------
106+
107+(for_expression
108+ "for" @keyword.control.repeat)
109+((identifier) @keyword.control
110+ (#match? @keyword.control "^yield$"))
111+
112+"in" @keyword.control
113+
114+[
115+ "match"
116+ "if"
117+ "else"
118+] @keyword.control.conditional
119+
120+[
121+ "while"
122+] @keyword.control.repeat
123+
124+[
125+ "break"
126+ "continue"
127+ "return"
128+] @keyword.control.return
129+
130+[
131+ "contract"
132+ "script"
133+ "predicate"
134+] @keyword.other
135+
136+"use" @keyword.control.import
137+(dep_item "dep" @keyword.control.import !body)
138+(use_as_clause "as" @keyword.control.import)
139+
140+(type_cast_expression "as" @keyword.operator)
141+
142+[
143+ "as"
144+ "pub"
145+ "dep"
146+
147+ "abi"
148+ "impl"
149+ "where"
150+ "trait"
151+ "for"
152+] @keyword
153+
154+[
155+ "struct"
156+ "enum"
157+ "storage"
158+ "configurable"
159+] @keyword.storage.type
160+
161+"let" @keyword.storage
162+"fn" @keyword.function
163+"abi" @keyword.function
164+
165+(mutable_specifier) @keyword.storage.modifier.mut
166+
167+(reference_type "&" @keyword.storage.modifier.ref)
168+(self_parameter "&" @keyword.storage.modifier.ref)
169+
170+[
171+ "const"
172+ "ref"
173+ "deref"
174+ "move"
175+] @keyword.storage.modifier
176+
177+; TODO: variable.mut to highlight mutable identifiers via locals.scm
178+
179+; -------
180+; Guess Other Types
181+; -------
182+
183+((identifier) @constant
184+ (#match? @constant "^[A-Z][A-Z\\d_]*$"))
185+
186+; ---
187+; PascalCase identifiers in call_expressions (e.g. `Ok()`)
188+; are assumed to be enum constructors.
189+; ---
190+
191+(call_expression
192+ function: [
193+ ((identifier) @type.enum.variant
194+ (#match? @type.enum.variant "^[A-Z]"))
195+ (scoped_identifier
196+ name: ((identifier) @type.enum.variant
197+ (#match? @type.enum.variant "^[A-Z]")))
198+ ])
199+
200+; ---
201+; Assume that types in match arms are enums and not
202+; tuple structs. Same for `if let` expressions.
203+; ---
204+
205+(match_pattern
206+ (scoped_identifier
207+ name: (identifier) @constructor))
208+(tuple_struct_pattern
209+ type: [
210+ ((identifier) @constructor)
211+ (scoped_identifier
212+ name: (identifier) @constructor)
213+ ])
214+(struct_pattern
215+ type: [
216+ ((type_identifier) @constructor)
217+ (scoped_type_identifier
218+ name: (type_identifier) @constructor)
219+ ])
220+
221+; ---
222+; Other PascalCase identifiers are assumed to be structs.
223+; ---
224+
225+((identifier) @type
226+ (#match? @type "^[A-Z]"))
227+
228+; -------
229+; Functions
230+; -------
231+
232+(call_expression
233+ function: [
234+ ((identifier) @function)
235+ (scoped_identifier
236+ name: (identifier) @function)
237+ (field_expression
238+ field: (field_identifier) @function)
239+ ])
240+(generic_function
241+ function: [
242+ ((identifier) @function)
243+ (scoped_identifier
244+ name: (identifier) @function)
245+ (field_expression
246+ field: (field_identifier) @function.method)
247+ ])
248+
249+(function_item
250+ name: (identifier) @function)
251+
252+(function_signature_item
253+ name: (identifier) @function)
254+
255+; -------
256+; Operators
257+; -------
258+
259+[
260+ "*"
261+ "'"
262+ "->"
263+ "=>"
264+ "<="
265+ "="
266+ "=="
267+ "!"
268+ "!="
269+ "%"
270+ "%="
271+ "&"
272+ "&="
273+ "&&"
274+ "|"
275+ "|="
276+ "||"
277+ "^"
278+ "^="
279+ "*"
280+ "*="
281+ "-"
282+ "-="
283+ "+"
284+ "+="
285+ "/"
286+ "/="
287+ ">"
288+ "<"
289+ ">="
290+ ">>"
291+ "<<"
292+ ">>="
293+ "<<="
294+ "@"
295+ ".."
296+ "..="
297+ "'"
298+] @operator
299+
300+; -------
301+; Paths
302+; -------
303+
304+(use_declaration
305+ argument: (identifier) @namespace)
306+(use_wildcard
307+ (identifier) @namespace)
308+(dep_item
309+ name: (identifier) @namespace)
310+(scoped_use_list
311+ path: (identifier)? @namespace)
312+(use_list
313+ (identifier) @namespace)
314+(use_as_clause
315+ path: (identifier)? @namespace
316+ alias: (identifier) @namespace)
317+
318+; ---
319+; Remaining Paths
320+; ---
321+
322+(scoped_identifier
323+ path: (identifier)? @namespace
324+ name: (identifier) @namespace)
325+(scoped_type_identifier
326+ path: (identifier) @namespace)
327+
328+; -------
329+; Remaining Identifiers
330+; -------
331+
332+"?" @special
333+
334+(type_identifier) @type
335+(identifier) @variable
336+(field_identifier) @variable.other.member