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