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