Debian Codegraph @

runtime/queries/haskell/highlights.scm

raw symbols SCIP
1 ;----------------------------------------------------------------------------
2 ; Parameters and variables
3 ; NOTE: These are at the top, so that they have low priority,
4 ; and don't override destructured parameters
5 (variable) @variable
6
7 (pattern/wildcard) @variable
8
9 (decl/function
10 patterns: (patterns
11 (_) @variable.parameter))
12
13 (expression/lambda
14 (_)+ @variable.parameter
15 "->")
16
17 (decl/function
18 (infix
19 (pattern) @variable.parameter))
20
21 ; ----------------------------------------------------------------------------
22 ; Literals and comments
23 (integer) @constant.numeric.integer
24
25 (negation) @constant.numeric
26
27 (expression/literal
28 (float)) @constant.numeric.float
29
30 (char) @constant.character
31
32 (string) @string
33
34 (unit) @string.special.symbol ; unit, as in ()
35
36 (comment) @comment
37
38 ((haddock) @comment.documentation)
39
40 ; ----------------------------------------------------------------------------
41 ; Punctuation
42 [
43 "("
44 ")"
45 "{"
46 "}"
47 "["
48 "]"
49 ] @punctuation.bracket
50
51 [
52 ","
53 ";"
54 ] @punctuation.delimiter
55
56 ; ----------------------------------------------------------------------------
57 ; Keywords, operators, includes
58 [
59 "forall"
60 ; "∀" ; utf-8 is not cross-platform safe
61 ] @keyword.control.repeat
62
63 (pragma) @keyword.directive
64
65 [
66 "if"
67 "then"
68 "else"
69 "case"
70 "of"
71 ] @keyword.control.conditional
72
73 [
74 "import"
75 "qualified"
76 "module"
77 ] @keyword.control.import
78
79 [
80 (operator)
81 (constructor_operator)
82 (all_names)
83 (wildcard)
84 "."
85 ".."
86 "="
87 "|"
88 "::"
89 "=>"
90 "->"
91 "<-"
92 "\\"
93 "`"
94 "@"
95 ] @operator
96
97 ; TODO broken, also huh?
98 ; ((qualified_module
99 ; (module) @constructor)
100 ; .
101 ; (module))
102
103 (module
104 (module_id) @namespace)
105
106 [
107 "where"
108 "let"
109 "in"
110 "class"
111 "instance"
112 "pattern"
113 "data"
114 "newtype"
115 "family"
116 "type"
117 "as"
118 "hiding"
119 "deriving"
120 "via"
121 "stock"
122 "anyclass"
123 "do"
124 "mdo"
125 "rec"
126 "infix"
127 "infixl"
128 "infixr"
129 ] @keyword
130
131 ; ----------------------------------------------------------------------------
132 ; Functions and variables
133 (decl
134 [
135 name: (variable) @function
136 names: (binding_list (variable) @function)
137 ])
138
139 (decl/bind
140 name: (variable) @variable)
141
142 ; Consider signatures (and accompanying functions)
143 ; with only one value on the rhs as variables
144 (decl/signature
145 name: (variable) @variable
146 type: (type))
147
148 ((decl/signature
149 name: (variable) @variable.name
150 type: (type))
151 .
152 (decl
153 name: (variable) @variable)
154 match: (_)
155 (#eq? @variable.name @variable))
156
157 ; but consider a type that involves 'IO' a decl/function
158 (decl/signature
159 name: (variable) @function
160 type: (type/apply
161 constructor: (name) @type)
162 (#eq? @type "IO"))
163
164 ((decl/signature
165 name: (variable) @function.name
166 type: (type/apply
167 constructor: (name) @type)
168 (#eq? @type "IO"))
169 .
170 (decl
171 name: (variable) @function)
172 match: (_)
173 (#eq? @function.name @function))
174
175 ((decl/signature) @function
176 .
177 (decl/function
178 name: (variable) @function))
179
180 (decl/bind
181 name: (variable) @function
182 (match
183 expression: (expression/lambda)))
184
185 ; view patterns
186 (view_pattern
187 [
188 (expression/variable) @function
189 (expression/qualified
190 (variable) @function)
191 ])
192
193 ; consider infix functions as operators
194 (infix_id
195 [
196 (variable) @operator
197 (qualified
198 (variable) @operator)
199 ])
200
201 ; decl/function calls with an infix operator
202 ; e.g. func <$> a <*> b
203 (infix
204 [
205 (variable) @function
206 (qualified
207 ((module) @namespace
208 (variable) @function))
209 ]
210 .
211 (operator))
212
213 ; infix operators applied to variables
214 ((expression/variable) @variable
215 .
216 (operator))
217
218 ((operator)
219 .
220 [
221 (expression/variable) @variable
222 (expression/qualified
223 (variable) @variable)
224 ])
225
226 ; decl/function calls with infix operators
227 ([
228 (expression/variable) @function
229 (expression/qualified
230 (variable) @function)
231 ]
232 .
233 (operator) @operator
234 (#any-of? @operator "$" "<$>" ">>=" "=<<"))
235
236 ; right hand side of infix operator
237 ((infix
238 [
239 (operator)
240 (infix_id (variable))
241 ] ; infix or `func`
242 .
243 [
244 (variable) @function
245 (qualified
246 (variable) @function)
247 ])
248 .
249 (operator) @operator
250 (#any-of? @operator "$" "<$>" "=<<"))
251
252 ; decl/function composition, arrows, monadic composition (lhs)
253 (
254 [
255 (expression/variable) @function
256 (expression/qualified
257 (variable) @function)
258 ]
259 .
260 (operator) @operator
261 (#any-of? @operator "." ">>>" "***" ">=>" "<=<"))
262
263 ; right hand side of infix operator
264 ((infix
265 [
266 (operator)
267 (infix_id (variable))
268 ] ; infix or `func`
269 .
270 [
271 (variable) @function
272 (qualified
273 (variable) @function)
274 ])
275 .
276 (operator) @operator
277 (#any-of? @operator "." ">>>" "***" ">=>" "<=<"))
278
279 ; function composition, arrows, monadic composition (rhs)
280 ((operator) @operator
281 .
282 [
283 (expression/variable) @function
284 (expression/qualified
285 (variable) @function)
286 ]
287 (#any-of? @operator "." ">>>" "***" ">=>" "<=<"))
288
289 ; function defined in terms of a function composition
290 (decl/function
291 name: (variable) @function
292 (match
293 expression: (infix
294 operator: (operator) @operator
295 (#any-of? @operator "." ">>>" "***" ">=>" "<=<"))))
296
297 (apply
298 [
299 (expression/variable) @function
300 (expression/qualified
301 (variable) @function)
302 ])
303
304 ; function compositions, in parentheses, applied
305 ; lhs
306 (apply
307 .
308 (expression/parens
309 (infix
310 [
311 (variable) @function
312 (qualified
313 (variable) @function)
314 ]
315 .
316 (operator))))
317
318 ; rhs
319 (apply
320 .
321 (expression/parens
322 (infix
323 (operator)
324 .
325 [
326 (variable) @function
327 (qualified
328 (variable) @function)
329 ])))
330
331 ; variables being passed to a function call
332 (apply
333 (_)
334 .
335 [
336 (expression/variable) @variable
337 (expression/qualified
338 (variable) @variable)
339 ])
340
341 ; main is always a function
342 ; (this prevents `main = undefined` from being highlighted as a variable)
343 (decl/bind
344 name: (variable) @function
345 (#eq? @function "main"))
346
347 ; scoped function types (func :: a -> b)
348 (signature
349 pattern: (pattern/variable) @function
350 type: (quantified_type))
351
352 ; signatures that have a function type
353 ; + binds that follow them
354 (decl/signature
355 name: (variable) @function
356 type: (quantified_type))
357
358 ((decl/signature
359 name: (variable) @function.name
360 type: (quantified_type))
361 .
362 (decl/bind
363 (variable) @function)
364 (#eq? @function @function.name))
365
366 ; ----------------------------------------------------------------------------
367 ; Types
368 (name) @type
369
370 (type/star) @type
371
372 ; (variable) @type
373
374 (constructor) @constructor
375
376 ; True or False
377 ((constructor) @constant.builtin.boolean
378 (#any-of? @constant.builtin.boolean "True" "False"))
379
380 ; otherwise (= True)
381 ((variable) @constant.builtin.boolean
382 (#eq? @constant.builtin.boolean "otherwise"))
383
384 ; ----------------------------------------------------------------------------
385 ; Quasi-quotes
386 (quoter) @function
387
388 (quasiquote
389 [
390 (quoter) @_name
391 (_
392 (variable) @_name)
393 ]
394 (#eq? @_name "qq")
395 (quasiquote_body) @string)
396
397 (quasiquote
398 (_
399 (variable) @_name)
400 (#eq? @_name "qq")
401 (quasiquote_body) @string)
402
403 ; namespaced quasi-quoter
404 (quasiquote
405 (_
406 (module) @namespace
407 .
408 (variable) @function))
409
410 ; Highlighting of quasiquote_body for other languages is handled by injections.scm
411 ; ----------------------------------------------------------------------------
412 ; Exceptions/error handling
413 ((variable) @keyword.exception
414 (#any-of? @keyword.exception
415 "error" "undefined" "try" "tryJust" "tryAny" "catch" "catches" "catchJust" "handle" "handleJust"
416 "throw" "throwIO" "throwTo" "throwError" "ioError" "mask" "mask_" "uninterruptibleMask"
417 "uninterruptibleMask_" "bracket" "bracket_" "bracketOnErrorSource" "finally" "fail"
418 "onException" "expectationFailure"))
419
420 ; ----------------------------------------------------------------------------
421 ; Debugging
422 ((variable) @keyword.debug
423 (#any-of? @keyword.debug
424 "trace" "traceId" "traceShow" "traceShowId" "traceWith" "traceShowWith" "traceStack" "traceIO"
425 "traceM" "traceShowM" "traceEvent" "traceEventWith" "traceEventIO" "flushEventLog" "traceMarker"
426 "traceMarkerIO"))
427
428 ; ----------------------------------------------------------------------------
429 ; Fields
430
431 (field_name
432 (variable) @variable.other.member)
433
434 (import_name
435 (name)
436 .
437 (children
438 (variable) @variable.other.member))