Debian Codegraph @

runtime/queries/sway/highlights.scm

raw symbols SCIP
1 ; -------
2 ; Basic identifiers
3 ; -------
4
5 ; We do not style ? as an operator on purpose as it allows styling ? differently, as many highlighters do. @operator.special might have been a better scope, but @special is already documented so the change would break themes (including the intent of the default theme)
6 "?" @special
7
8 (type_identifier) @type
9 (identifier) @variable
10 (field_identifier) @variable.other.member
11
12 ; -------
13 ; Operators
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 ] @operator
56
57 ; -------
58 ; Paths
59 ; -------
60
61 (use_declaration
62 argument: (identifier) @namespace)
63 (use_wildcard
64 (identifier) @namespace)
65 (dep_item
66 name: (identifier) @namespace)
67 (scoped_use_list
68 path: (identifier)? @namespace)
69 (use_list
70 (identifier) @namespace)
71 (use_as_clause
72 path: (identifier)? @namespace
73 alias: (identifier) @namespace)
74
75 ; ---
76 ; Remaining Paths
77 ; ---
78
79 (scoped_identifier
80 path: (identifier)? @namespace
81 name: (identifier) @namespace)
82 (scoped_type_identifier
83 path: (identifier) @namespace)
84
85 ; ---
86 ; Primitives
87 ; ---
88
89 (escape_sequence) @constant.character.escape
90 (primitive_type) @type.builtin
91 (boolean_literal) @constant.builtin.boolean
92 (integer_literal) @constant.numeric.integer
93 (float_literal) @constant.numeric.float
94 (char_literal) @constant.character
95 [
96 (string_literal)
97 (raw_string_literal)
98 ] @string
99 [
100 (line_comment)
101 (block_comment)
102 ] @comment
103
104 ; ---
105 ; Extraneous
106 ; ---
107
108 (self) @variable.builtin
109 (enum_variant (identifier) @type.enum.variant)
110
111 (field_initializer
112 (field_identifier) @variable.other.member)
113 (shorthand_field_initializer
114 (identifier) @variable.other.member)
115 (shorthand_field_identifier) @variable.other.member
116
117 (loop_label
118 "'" @label
119 (identifier) @label)
120
121 ; ---
122 ; Punctuation
123 ; ---
124
125 [
126 "::"
127 "."
128 ";"
129 ","
130 ] @punctuation.delimiter
131
132 [
133 "("
134 ")"
135 "["
136 "]"
137 "{"
138 "}"
139 "#"
140 ] @punctuation.bracket
141 (type_arguments
142 [
143 "<"
144 ">"
145 ] @punctuation.bracket)
146 (type_parameters
147 [
148 "<"
149 ">"
150 ] @punctuation.bracket)
151 (closure_parameters
152 "|" @punctuation.bracket)
153
154 ; ---
155 ; Variables
156 ; ---
157
158 (let_declaration
159 pattern: [
160 ((identifier) @variable)
161 ((tuple_pattern
162 (identifier) @variable))
163 ])
164
165 ; It needs to be anonymous to not conflict with `call_expression` further below.
166 (_
167 value: (field_expression
168 value: (identifier)? @variable
169 field: (field_identifier) @variable.other.member))
170
171 (parameter
172 pattern: (identifier) @variable.parameter)
173 (closure_parameters
174 (identifier) @variable.parameter)
175
176 ; -------
177 ; Keywords
178 ; -------
179
180 (for_expression
181 "for" @keyword.control.repeat)
182 ((identifier) @keyword.control
183 (#match? @keyword.control "^yield$"))
184
185 "in" @keyword.control
186
187 [
188 "match"
189 "if"
190 "else"
191 ] @keyword.control.conditional
192
193 [
194 "while"
195 ] @keyword.control.repeat
196
197 [
198 "break"
199 "continue"
200 "return"
201 ] @keyword.control.return
202
203 [
204 "contract"
205 "script"
206 "predicate"
207 ] @keyword.other
208
209 "use" @keyword.control.import
210 (dep_item "dep" @keyword.control.import !body)
211 (use_as_clause "as" @keyword.control.import)
212
213 (type_cast_expression "as" @keyword.operator)
214
215 [
216 "as"
217 "pub"
218 "dep"
219
220 "abi"
221 "impl"
222 "where"
223 "trait"
224 "for"
225 ] @keyword
226
227 [
228 "struct"
229 "enum"
230 "storage"
231 "configurable"
232 ] @keyword.storage.type
233
234 "let" @keyword.storage
235 "fn" @keyword.function
236 "abi" @keyword.function
237
238 (mutable_specifier) @keyword.storage.modifier.mut
239
240 (reference_type "&" @keyword.storage.modifier.ref)
241 (self_parameter "&" @keyword.storage.modifier.ref)
242
243 [
244 "const"
245 "ref"
246 "deref"
247 "move"
248 ] @keyword.storage.modifier
249
250 ; TODO: variable.mut to highlight mutable identifiers via locals.scm
251
252 ; -------
253 ; Guess Other Types
254 ; -------
255 ; Other PascalCase identifiers are assumed to be structs.
256
257 ((identifier) @type
258 (#match? @type "^[A-Z]"))
259
260 ((identifier) @constant
261 (#match? @constant "^[A-Z][A-Z\\d_]*$"))
262
263 ; ---
264 ; PascalCase identifiers in call_expressions (e.g. `Ok()`)
265 ; are assumed to be enum constructors.
266 ; ---
267
268 (call_expression
269 function: [
270 ((identifier) @constructor
271 (#match? @constructor "^[A-Z]"))
272 (scoped_identifier
273 name: ((identifier) @constructor
274 (#match? @constructor "^[A-Z]")))
275 ])
276
277 ; ---
278 ; PascalCase identifiers under a path which is also PascalCase
279 ; are assumed to be constructors if they have methods or fields.
280 ; ---
281
282 (field_expression
283 value: (scoped_identifier
284 path: [
285 (identifier) @type
286 (scoped_identifier
287 name: (identifier) @type)
288 ]
289 name: (identifier) @constructor
290 (#match? @type "^[A-Z]")
291 (#match? @constructor "^[A-Z]")))
292
293 ; -------
294 ; Functions
295 ; -------
296
297 (call_expression
298 function: [
299 ((identifier) @function)
300 (scoped_identifier
301 name: (identifier) @function)
302 (field_expression
303 field: (field_identifier) @function)
304 ])
305 (generic_function
306 function: [
307 ((identifier) @function)
308 (scoped_identifier
309 name: (identifier) @function)
310 (field_expression
311 field: (field_identifier) @function.method)
312 ])
313
314 (function_item
315 name: (identifier) @function)
316
317 (function_signature_item
318 name: (identifier) @function)