1(identifier) @variable
2(metavariable) @variable
3(type_identifier) @type
4(fragment_specifier) @type
5(primitive_type) @type.builtin
6(self) @variable.special
7(field_identifier) @property
8(shorthand_field_identifier) @property
9
10(trait_item name: (type_identifier) @type.interface)
11(impl_item trait: (type_identifier) @type.interface)
12(abstract_type trait: (type_identifier) @type.interface)
13(dynamic_type trait: (type_identifier) @type.interface)
14(trait_bounds (type_identifier) @type.interface)
15
16(call_expression
17 function: [
18 (identifier) @function
19 (scoped_identifier
20 name: (identifier) @function)
21 (field_expression
22 field: (field_identifier) @function.method)
23 ])
24
25(generic_function
26 function: [
27 (identifier) @function
28 (scoped_identifier
29 name: (identifier) @function)
30 (field_expression
31 field: (field_identifier) @function.method)
32 ])
33
34(function_item name: (identifier) @function.definition)
35(function_signature_item name: (identifier) @function.definition)
36
37(macro_invocation
38 macro: [
39 (identifier) @function.special
40 (scoped_identifier
41 name: (identifier) @function.special)
42 ])
43
44(macro_definition
45 name: (identifier) @function.special.definition)
46
47; Identifier conventions
48
49; Assume uppercase names are types/enum-constructors
50((identifier) @type
51 (#match? @type "^[A-Z]"))
52
53; Assume all-caps names are constants
54((identifier) @constant
55 (#match? @constant "^_*[A-Z][A-Z\\d_]*$"))
56
57[
58 "("
59 ")"
60 "{"
61 "}"
62 "["
63 "]"
64] @punctuation.bracket
65
66(_
67 .
68 "<" @punctuation.bracket
69 ">" @punctuation.bracket)
70
71[
72 "."
73 ";"
74 ","
75 "::"
76] @punctuation.delimiter
77
78[
79 "#"
80] @punctuation.special
81
82[
83 "as"
84 "async"
85 "await"
86 "const"
87 "default"
88 "dyn"
89 "enum"
90 "extern"
91 "fn"
92 "impl"
93 "let"
94 "macro_rules!"
95 "mod"
96 "move"
97 "pub"
98 "raw"
99 "ref"
100 "static"
101 "struct"
102 "trait"
103 "type"
104 "union"
105 "unsafe"
106 "use"
107 "where"
108 (crate)
109 (mutable_specifier)
110 (super)
111] @keyword
112
113[
114 "break"
115 "continue"
116 "else"
117 "for"
118 "if"
119 "in"
120 "loop"
121 "match"
122 "return"
123 "while"
124 "yield"
125] @keyword.control
126
127[
128 (string_literal)
129 (raw_string_literal)
130 (char_literal)
131] @string
132
133(escape_sequence) @string.escape
134
135[
136 (integer_literal)
137 (float_literal)
138] @number
139
140(boolean_literal) @boolean
141
142[
143 (line_comment)
144 (block_comment)
145] @comment
146
147[
148 (line_comment (doc_comment))
149 (block_comment (doc_comment))
150] @comment.doc
151
152[
153 "!="
154 "%"
155 "%="
156 "&"
157 "&="
158 "&&"
159 "*"
160 "*="
161 "+"
162 "+="
163 "-"
164 "-="
165 "->"
166 ".."
167 "..="
168 "..."
169 "/="
170 ":"
171 "<<"
172 "<<="
173 "<"
174 "<="
175 "="
176 "=="
177 "=>"
178 ">"
179 ">="
180 ">>"
181 ">>="
182 "@"
183 "^"
184 "^="
185 "|"
186 "|="
187 "||"
188 "?"
189] @operator
190
191; Avoid highlighting these as operators when used in doc comments.
192(unary_expression "!" @operator)
193operator: "/" @operator
194
195(lifetime) @lifetime
196
197(parameter (identifier) @variable.parameter)
198
199(attribute_item (attribute [
200 (identifier) @attribute
201 (scoped_identifier name: (identifier) @attribute)
202 (token_tree (identifier) @attribute (#match? @attribute "^[a-z\\d_]*$"))
203 (token_tree (identifier) @none "::" (#match? @none "^[a-z\\d_]*$"))
204]))
205
206(inner_attribute_item (attribute [
207 (identifier) @attribute
208 (scoped_identifier name: (identifier) @attribute)
209 (token_tree (identifier) @attribute (#match? @attribute "^[a-z\\d_]*$"))
210 (token_tree (identifier) @none "::" (#match? @none "^[a-z\\d_]*$"))
211]))