aboutsummaryrefslogtreecommitdiff
path: root/runtime/queries/nim/highlights.scm
blob: e02ba5165cba52076035f281759ec414470d9625 (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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
;; Constants, Comments, and Literals

(comment) @comment.line
(block_comment) @comment.block
[
  (documentation_comment)
  (block_documentation_comment)
] @comment.block.documentation

(nil_literal) @constant.builtin
((identifier) @constant.builtin.boolean
  (#any-of? @constant.builtin.boolean "true" "false" "on" "off"))

(char_literal) @constant.character
(escape_sequence) @constant.character.escape
(custom_numeric_literal) @constant.numeric
(integer_literal) @constant.numeric.integer
(float_literal) @constant.numeric.float
; literals
; todo: literal?

[
  (long_string_literal)
  (raw_string_literal)
  (generalized_string)
  (interpreted_string_literal)
] @string
; (generalized_string (string_content) @none) ; todo: attempt to un-match string_content
; [] @string.regexp

[
  "."
  ","
  ";"
  ":"
] @punctuation.delimiter
[
  "("
  ")"
  "["
  "]"
  "{"
  "}"
  "{."
  ".}"
] @punctuation.bracket
; todo: interpolated_str_lit?? & { }?

[
  "and"
  "or"
  "xor"
  "not"
  "div"
  "mod"
  "shl"
  "shr"
  "from"
  "as"
  "of"
  "in"
  "notin"
  "is"
  "isnot"
] @keyword.operator

[(operator) "="] @operator
(infix_expression operator: _ @operator)
(prefix_expression operator: _ @operator)

(pragma_list
  (identifier)? @attribute
  (colon_expression
    (identifier) @attribute)?)

;; Imports and Exports

[
  "import"
  "export"
  "include"
  "from"
] @keyword.control.import

(import_statement
  [
    (identifier) @namespace
    (expression_list (identifier) @namespace)
    (except_clause
      "except" @keyword.control.import
      (expression_list (identifier) @namespace))])
(import_from_statement
  (identifier) @namespace
  (expression_list (identifier) @namespace))
(include_statement (expression_list (identifier) @namespace))
(export_statement (expression_list (identifier) @namespace))

;; Control Flow

[
  "if"
  "when"
  "case"
  "elif"
  "else"
] @keyword.control.conditional
(of_branch "of" @keyword.control.conditional)
; conditional statements
; todo: do block

"block" @keyword.control
(block label: (_) @label)

[
  "for"
  "while"
  "continue"
  "break"
] @keyword.control.repeat
(for "in" @keyword.control.repeat)

[
  "return"
  "yield"
] @keyword.control.return
; return statements

[
  "try"
  "except"
  "finally"
  "raise"
] @keyword.control.exception
; exception handling statements

[
  "asm"
  "bind"
  "mixin"
  "defer"
  "static"
] @keyword
; miscellaneous keywords

;; Types and Type Declarations

[
  "let"
  "var"
  "const"
  "type"
  "object"
  "tuple"
  "enum"
  "concept"
] @keyword.storage.type

(var_type "var" @keyword.storage.modifier)
(out_type "out" @keyword.storage.modifier)
(distinct_type "distinct" @keyword.storage.modifier)
(ref_type "ref" @keyword.storage.modifier)
(pointer_type "ptr" @keyword.storage.modifier)

(var_parameter "var" @keyword.storage.modifier)
(type_parameter "type" @keyword.storage.modifier)
(static_parameter "static" @keyword.storage.modifier)
(ref_parameter "ref" @keyword.storage.modifier)
(pointer_parameter "ptr" @keyword.storage.modifier)
; (var_parameter (identifier) @variable.parameter)
; (type_parameter (identifier) @variable.parameter)
; (static_parameter (identifier) @variable.parameter)
; (ref_parameter (identifier) @variable.parameter)
; (pointer_parameter (identifier) @variable.parameter)
; todo: when are these used??

(type_section
  (type_declaration
    (type_symbol_declaration
      name: (_) @type)))
; types in type declarations

(enum_field_declaration
  (symbol_declaration
    name: (_) @type.enum.variant))
; types as enum variants

(variant_declaration
  alternative: (of_branch
    values: (expression_list (_) @type.enum.variant)))
; types as object variants

(case
  (of_branch
    values: (expression_list (_) @constant)))
; case values are guaranteed to be constant

(type_expression
  [
    (identifier) @type
    (bracket_expression
      [
        (identifier) @type
        (argument_list (identifier) @type)])
    (tuple_construction
      [
        (identifier) @type
        (bracket_expression
          [
            (identifier) @type
            (argument_list (identifier) @type)])])])
; types in type expressions

(call
  function: (bracket_expression
    right: (argument_list (identifier) @type)))
; types as generic parameters

; (dot_generic_call
;   generic_arguments: (_) @type)
; ???

(infix_expression
  operator:
    [
      "is"
      "isnot"
    ]
  right: (_) @type)
; types in "is" comparisions

(except_branch
  values: (expression_list
    [
      (identifier) @type
      (infix_expression
        left: (identifier) @type
        operator: "as"
        right: (_) @variable)]))
; types in exception branches

;; Functions

[
  "proc"
  "func"
  "method"
  "converter"
  "iterator"
  "template"
  "macro"
] @keyword.function

(exported_symbol "*" @attribute)
(_ "=" @punctuation.delimiter [body: (_) value: (_)])

(proc_declaration name: (_) @function)
(func_declaration name: (_) @function)
(iterator_declaration name: (_) @function)
(converter_declaration name: (_) @function)
(method_declaration name: (_) @function.method)
(template_declaration name: (_) @function.macro)
(macro_declaration name: (_) @function.macro)
(symbol_declaration name: (_) @variable)

(call
  function: [
    (identifier) @function.call
    (dot_expression
      right: (identifier) @function.call)
    (bracket_expression
      left: [
        (identifier) @function.call
        (dot_expression
          right: (identifier) @function.call)])])
(generalized_string
  function: [
    (identifier) @function.call
    (dot_expression
      right: (identifier) @function.call)
    (bracket_expression
      left: [
        (identifier) @function.call
        (dot_expression
          right: (identifier) @function.call)])])
(dot_generic_call function: (_) @function.call)

;; Variables

(parameter_declaration
  (symbol_declaration_list
    (symbol_declaration
      name: (_) @variable.parameter)))
(argument_list
  (equal_expression
    left: (_) @variable.parameter))
(concept_declaration
  parameters: (parameter_list (identifier) @variable.parameter))

(field_declaration
  (symbol_declaration_list
    (symbol_declaration
      name: (_) @variable.other.member)))
(call
  (argument_list
    (colon_expression
      left: (_) @variable.other.member)))
(tuple_construction
  (colon_expression
    left: (_) @variable.other.member))
(variant_declaration
  (variant_discriminator_declaration
    (symbol_declaration_list
      (symbol_declaration
        name: (_) @variable.other.member))))

;; Miscellaneous Matches

[
  "cast"
  "discard"
  "do"
] @keyword
; also: addr end interface using

(blank_identifier) @variable.builtin
((identifier) @variable.builtin
  (#eq? @variable.builtin "result"))

(dot_expression
  left: (identifier) @variable
  right: (identifier) @variable.other.member)

(identifier) @variable