highlights.scm

  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_invocation
 45  "!" @function.special)
 46
 47(macro_definition
 48  name: (identifier) @function.special.definition)
 49
 50; Identifier conventions
 51
 52; Assume uppercase names are types/enum-constructors
 53((identifier) @type
 54 (#match? @type "^[A-Z]"))
 55
 56; Assume all-caps names are constants
 57((identifier) @constant
 58 (#match? @constant "^_*[A-Z][A-Z\\d_]*$"))
 59
 60[
 61  "("
 62  ")"
 63  "{"
 64  "}"
 65  "["
 66  "]"
 67] @punctuation.bracket
 68
 69(_
 70  .
 71  "<" @punctuation.bracket
 72  ">" @punctuation.bracket)
 73
 74[
 75  "."
 76  ";"
 77  ","
 78  "::"
 79] @punctuation.delimiter
 80
 81[
 82  "#"
 83] @punctuation.special
 84
 85[
 86  "as"
 87  "async"
 88  "const"
 89  "default"
 90  "dyn"
 91  "enum"
 92  "extern"
 93  "fn"
 94  "impl"
 95  "let"
 96  "macro_rules!"
 97  "mod"
 98  "move"
 99  "pub"
100  "raw"
101  "ref"
102  "static"
103  "struct"
104  "for"
105  "trait"
106  "type"
107  "union"
108  "unsafe"
109  "use"
110  "where"
111  (crate)
112  (mutable_specifier)
113  (super)
114] @keyword
115
116[
117  "await"
118  "break"
119  "continue"
120  "else"
121  "if"
122  "in"
123  "loop"
124  "match"
125  "return"
126  "while"
127  "yield"
128] @keyword.control
129
130(for_expression
131  ("for" @keyword.control))
132
133[
134  (string_literal)
135  (raw_string_literal)
136  (char_literal)
137] @string
138
139(escape_sequence) @string.escape
140
141[
142  (integer_literal)
143  (float_literal)
144] @number
145
146(boolean_literal) @boolean
147
148[
149  (line_comment)
150  (block_comment)
151] @comment
152
153[
154  (line_comment (doc_comment))
155  (block_comment (doc_comment))
156] @comment.doc
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  "^"
190  "^="
191  "|"
192  "|="
193  "||"
194  "?"
195] @operator
196
197; Avoid highlighting these as operators when used in doc comments.
198(unary_expression "!" @operator)
199operator: "/" @operator
200
201(lifetime
202  "'" @lifetime
203  (identifier) @lifetime)
204
205(parameter (identifier) @variable.parameter)
206
207(attribute_item (attribute [
208  (identifier) @attribute
209  (scoped_identifier name: (identifier) @attribute)
210  (token_tree (identifier) @attribute (#match? @attribute "^[a-z\\d_]*$"))
211  (token_tree (identifier) @none "::" (#match? @none "^[a-z\\d_]*$"))
212]))
213
214(inner_attribute_item (attribute [
215  (identifier) @attribute
216  (scoped_identifier name: (identifier) @attribute)
217  (token_tree (identifier) @attribute (#match? @attribute "^[a-z\\d_]*$"))
218  (token_tree (identifier) @none "::" (#match? @none "^[a-z\\d_]*$"))
219]))