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 "break"
87 "const"
88 "continue"
89 "default"
90 "dyn"
91 "else"
92 "enum"
93 "extern"
94 "fn"
95 "for"
96 "if"
97 "impl"
98 "in"
99 "let"
100 "loop"
101 "macro_rules!"
102 "match"
103 "mod"
104 "move"
105 "pub"
106 "raw"
107 "ref"
108 "return"
109 "static"
110 "struct"
111 "trait"
112 "type"
113 "union"
114 "unsafe"
115 "use"
116 "where"
117 "while"
118 "yield"
119 (crate)
120 (mutable_specifier)
121 (super)
122] @keyword
123
124[
125 (string_literal)
126 (raw_string_literal)
127 (char_literal)
128] @string
129
130(escape_sequence) @string.escape
131
132[
133 (integer_literal)
134 (float_literal)
135] @number
136
137(boolean_literal) @boolean
138
139[
140 (line_comment)
141 (block_comment)
142] @comment
143
144[
145 (line_comment (doc_comment))
146 (block_comment (doc_comment))
147] @comment.doc
148
149[
150 "!="
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] @operator
187
188; Avoid highlighting these as operators when used in doc comments.
189(unary_expression "!" @operator)
190operator: "/" @operator
191
192(lifetime) @lifetime
193
194(parameter (identifier) @variable.parameter)
195
196(attribute_item (attribute [
197 (identifier) @attribute
198 (scoped_identifier name: (identifier) @attribute)
199 (token_tree (identifier) @attribute (#match? @attribute "^[a-z\\d_]*$"))
200 (token_tree (identifier) @none "::" (#match? @none "^[a-z\\d_]*$"))
201]))
202
203(inner_attribute_item (attribute [
204 (identifier) @attribute
205 (scoped_identifier name: (identifier) @attribute)
206 (token_tree (identifier) @attribute (#match? @attribute "^[a-z\\d_]*$"))
207 (token_tree (identifier) @none "::" (#match? @none "^[a-z\\d_]*$"))
208]))