@@ -1,214 +1,336 @@
1−; Identifier conventions
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.
4−; Assume all-caps names are constants
5−((identifier) @constant
6− (#match? @constant "^[A-Z][A-Z\\d_]+$"))
8−; Assume other uppercase names are enum constructors
10+; -------
9−(enum_variant) @type.enum.variant
11+; Types
10−((identifier) @constructor
12+; -------
11− (#match? @constructor "^[A-Z]"))
13−; Assume that uppercase names in paths are types
14+; ---
14−(mod_item
15+; Primitives
15− name: (identifier) @namespace)
16+; ---
17− path: (identifier) @namespace)
20− name: (identifier) @namespace))
21−(scoped_type_identifier
22− path: (identifier) @namespace)
23−(scoped_type_identifier
25− name: (identifier) @namespace))
27−((scoped_identifier
18+(escape_sequence) @escape
28− path: (identifier) @type)
19+(primitive_type) @type.builtin
29− (#match? @type "^[A-Z]"))
20+(boolean_literal) @constant.builtin
30−((scoped_identifier
21+[
31− path: (scoped_identifier
22+ (integer_literal)
32− name: (identifier) @type))
23+ (float_literal)
33− (#match? @type "^[A-Z]"))
24+] @number
37−(crate) @namespace
39+(self) @variable.builtin
38−(extern_crate_declaration
40+(enum_variant (identifier) @type.enum.variant)
40− name: (identifier) @namespace)
42− path: (identifier) @namespace)
44− path: (scoped_identifier
45− (identifier) @namespace))
46−(use_list (scoped_identifier (identifier) @namespace . (_)))
48−; Function calls
42+(field_initializer
43+ (field_identifier) @property)
44+(shorthand_field_initializer) @variable
45+(shorthand_field_identifier) @variable
50−(call_expression
47+(lifetime
51− function: (identifier) @function)
48+ "'" @label
52−(call_expression
49+ (identifier) @label)
53− function: (field_expression
50+(loop_label
54− field: (field_identifier) @function.method))
56− function: (scoped_identifier
58− name: (identifier) @function))
51+ (identifier) @type)
60−(generic_function
53+; ---
61− function: (identifier) @function)
54+; Punctuation
62−(generic_function
55+; ---
63− function: (scoped_identifier
64− name: (identifier) @function))
66− function: (field_expression
67− field: (field_identifier) @function.method))
70− macro: (identifier) @function.macro
58+ "::"
71− "!" @function.macro)
59+ "."
72−(macro_invocation
60+ ";"
73− macro: (scoped_identifier
61+] @punctuation.delimiter
74− (identifier) @function.macro .))
76−; (metavariable) @variable
63+[
77−(metavariable) @function.macro
64+ "("
68+] @punctuation.bracket
73+ ] @punctuation.bracket)
78+ ] @punctuation.bracket)
79−"$" @function.macro
80+; ---
81−; Function definitions
84+(parameter
85+ pattern: (identifier) @variable.parameter)
87+ (identifier) @variable.parameter)
83−(function_item (identifier) @function)
84−(function_signature_item (identifier) @function)
88−(type_identifier) @type
91+; -------
89−(primitive_type) @type.builtin
92+; Keywords
90−(field_identifier) @property
93+; -------
92−(line_comment) @comment
95+(for_expression
93−(block_comment) @comment
96+ "for" @keyword.control)
97+((identifier) @keyword.control
98+ (#match? @keyword.control "^yield$"))
95−"(" @punctuation.bracket
106+ "match"
96−")" @punctuation.bracket
107+ "if"
97−"[" @punctuation.bracket
108+ "else"
98−"]" @punctuation.bracket
109+ "return"
101− "<" @punctuation.bracket
102− ">" @punctuation.bracket)
104− "<" @punctuation.bracket
105− ">" @punctuation.bracket)
107−"::" @punctuation.delimiter
108−"." @punctuation.delimiter
109−";" @punctuation.delimiter
111−(parameter (identifier) @variable.parameter)
112−(closure_parameters (_) @variable.parameter)
114−(lifetime (identifier) @label)
134−"macro_rules!" @keyword
150(mutable_specifier) @keyword.mut
147(mutable_specifier) @keyword.mut
151−(use_list (self) @keyword)
152−(scoped_use_list (self) @keyword)
153−(scoped_identifier (self) @keyword)
157−(self) @variable.builtin
165−(boolean_literal) @constant.builtin
151+; -------
166−(integer_literal) @number
152+; Guess Other Types
167−(float_literal) @number
153+; -------
169−(escape_sequence) @escape
155+((identifier) @constant
156+ (#match? @constant "^[A-Z][A-Z\\d_]+$"))
159+; PascalCase identifiers in call_expressions (e.g. `Ok()`)
160+; are assumed to be enum constructors.
165+ ((identifier) @type.variant
166+ (#match? @type.variant "^[A-Z]"))
168+ name: ((identifier) @type.variant
169+ (#match? @type.variant "^[A-Z]")))
173+; Assume that types in match arms are enums and not
174+; tuple structs. Same for `if let` expressions.
179+ name: (identifier) @constructor))
180+(tuple_struct_pattern
182+ ((identifier) @constructor)
184+ name: (identifier) @constructor)
188+ ((type_identifier) @constructor)
189+ (scoped_type_identifier
190+ name: (type_identifier) @constructor)
194+; Other PascalCase identifiers are assumed to be structs.
198+ (#match? @type "^[A-Z]"))
208+ ((identifier) @function)
210+ name: (identifier) @function)
212+ field: (field_identifier) @function)
216+ ((identifier) @function)
218+ name: (identifier) @function)
220+ field: (field_identifier) @function.method)
224+ name: (identifier) @function)
231+ (identifier) @attribute)
171(attribute_item) @attribute
232(attribute_item) @attribute
172(inner_attribute_item) @attribute
233(inner_attribute_item) @attribute
236+ name: (identifier) @function.macro)
239+ ((identifier) @function.macro)
241+ name: (identifier) @function.macro)
243+ "!" @function.macro)
245+(metavariable) @variable.parameter
246+(fragment_specifier) @variable.parameter
212] @operator
292] @operator
301+ argument: (identifier) @namespace)
303+ (identifier) @namespace)
304+(extern_crate_declaration
305+ name: (identifier) @namespace)
307+ name: (identifier) @namespace)
309+ path: (identifier)? @namespace)
311+ (identifier) @namespace)
313+ path: (identifier)? @namespace
314+ alias: (identifier) @namespace)
321+ path: (identifier)? @namespace
322+ name: (identifier) @namespace)
323+(scoped_type_identifier
324+ path: (identifier) @namespace)
329+; Remaining Identifiers
214"?" @special
332"?" @special
334+(type_identifier) @type
335+(identifier) @variable
336+(field_identifier) @variable