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 "ref"
103 "return"
104 "static"
105 "struct"
106 "trait"
107 "type"
108 "union"
109 "unsafe"
110 "use"
111 "where"
112 "while"
113 "yield"
114 (crate)
115 (mutable_specifier)
116 (super)
117] @keyword
118
119[
120 (string_literal)
121 (raw_string_literal)
122 (char_literal)
123] @string
124
125(escape_sequence) @string.escape
126
127[
128 (integer_literal)
129 (float_literal)
130] @number
131
132(boolean_literal) @boolean
133
134[
135 (line_comment)
136 (block_comment)
137] @comment
138
139[
140 (line_comment (doc_comment))
141 (block_comment (doc_comment))
142] @comment.doc
143
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] @operator
182
183; Avoid highlighting these as operators when used in doc comments.
184(unary_expression "!" @operator)
185operator: "/" @operator
186
187(lifetime) @lifetime
188
189(parameter (identifier) @variable.parameter)
190
191(attribute_item) @attribute
192(inner_attribute_item) @attribute