aboutsummaryrefslogtreecommitdiffstats
path: root/queries/rust/highlights.scm
blob: 1a3e53e802a81329d5c881ab65be86c19bd46e9e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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
; Forked from https://github.com/tree-sitter/tree-sitter-rust
; Copyright (c) 2017 Maxim Sokolov
; Licensed under the MIT license.

; Identifier conventions

; Assume all-caps names are constants
((identifier) @constant
 (#vim-match? @constant "^[A-Z][A-Z\\d_]+$'"))

; Other identifiers

(type_identifier) @type
(primitive_type) @type.builtin
(field_identifier) @field


; Function calls
(call_expression
  function: (identifier) @function)
(call_expression
  function: (field_expression
    field: (field_identifier) @function))

(generic_function
  function: (identifier) @function)
(generic_function
  function: (scoped_identifier
    name: (identifier) @function))
(generic_function
  function: (field_expression
    field: (field_identifier) @function))

; Assume other uppercase names are enum constructors
([(identifier) (field_identifier)] @constant
 (#match? @constant "^[A-Z]"))

; Assume that uppercase names in paths are types
((scoped_identifier
  path: (identifier) @type)
 (#match? @type "^[A-Z]"))
((scoped_identifier
    name: (identifier) @type)
 (#match? @type "^[A-Z]"))

(use_list (identifier) @type (#match? @type "^[A-Z]"))
(use_as_clause alias: (identifier) @type (#match? @type "^[A-Z]"))

;; Correct enum constructors
(call_expression
  function: (scoped_identifier
    "::"
    name: (identifier) @constant)
  (#match? @constant "^[A-Z]"))

;; Assume that all `#[derive]` arguments are types
(meta_item
  (identifier) @meta
  arguments: (meta_arguments (meta_item (identifier) @type))
  (#eq? @meta "derive"))

(macro_invocation
  macro: (identifier) @function.macro
  "!" @function.macro)

; Function definitions

(function_item (identifier) @function)
(function_signature_item (identifier) @function)

[
(line_comment)
(block_comment)
 ] @comment

[
"("
")"
"["
"]"
 ] @punctuation.bracket

(type_arguments
  "<" @punctuation.bracket
  ">" @punctuation.bracket)
(type_parameters
  "<" @punctuation.bracket
  ">" @punctuation.bracket)

[
"::"
"."
";"
 ] @punctuation.delimiter

(parameter (identifier) @parameter)

(lifetime (identifier) @label)

(self) @variable.builtin

[
"break"
"const"
"default"
"dyn"
"enum"
"extern"
"fn"
"impl"
"let"
"macro_rules!"
"match"
"mod"
"move"
"pub"
"ref"
"return"
"static"
"struct"
"trait"
"type"
"union"
"unsafe"
"async"
"await"
"use"
"where"
(mutable_specifier)
(super)
; TODO(vigoux): attribute items should have some kind of injections
(attribute_item)
(inner_attribute_item)
 ] @keyword

(use_list (self) @keyword)
(scoped_use_list (self) @keyword)
(scoped_identifier (self) @keyword)

[
"continue"
"else"
"if"
] @conditional

[
"for"
"in"
"loop"
"while"
] @repeat

[
(char_literal)
(string_literal)
(raw_string_literal)
] @string

(boolean_literal) @boolean
(integer_literal) @number
(float_literal) @float

(escape_sequence) @string.escape

[
"as"
"*"
"&"
"'"
 ] @operator

(closure_parameters "|" @operator "|" @operator)