aboutsummaryrefslogtreecommitdiff
path: root/runtime/queries/nim/highlights.scm
blob: 1d32568530b57520db23f2fec41aca14741671ee (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
;; Constants, Comments, and Literals

(comment) @comment.line
(multilineComment) @comment.block
(docComment) @comment.block.documentation
(multilineDocComment) @comment.block.documentation
; comments

[(literal) (generalizedLit)] @constant
[(nil_lit)] @constant.builtin
[(bool_lit)] @constant.builtin.boolean
[(char_lit)] @constant.character
[(char_esc_seq) (str_esc_seq)] @constant.character.escape
[(custom_numeric_lit)] @constant.numeric
[(int_lit) (int_suffix)] @constant.numeric.integer
[(float_lit) (float_suffix)] @constant.numeric.float
; literals
; note: somewhat irritatingly for testing, lits have the same syntax highlighting as types

[
  (str_lit)
  (triplestr_lit)
  (rstr_lit)
  (generalized_str_lit)
  (generalized_triplestr_lit)
  (interpolated_str_lit)
  (interpolated_triplestr_lit)
] @string
; [] @string.regexp
; string literals

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

[
  "and"
  "or"
  "xor"
  "not"
  "in"
  "notin"
  "is"
  "isnot"
  "div"
  "mod"
  "shl"
  "shr"
] @keyword.operator
; operators: we list them explicitly to deliminate them from symbolic operators

[(operator) (opr) "="] @operator
; all operators (must come after @keyword.operator)

(pragma) @attribute
; pragmas


;; Imports and Exports

(importStmt
  (keyw) @keyword.control.import
  (expr (primary (symbol) @namespace))?
  (expr (primary (arrayConstr (exprColonExprList (exprColonExpr (expr (primary (symbol) @namespace)))))))?)
(exportStmt
  (keyw) @keyword.control.import
  (expr (primary (symbol) @namespace))?
  (expr (primary (arrayConstr (exprColonExprList (exprColonExpr (expr (primary (symbol) @namespace)))))))?)
(fromStmt
  (keyw) @keyword.control.import
  (expr (primary (symbol) @namespace))?
  (expr (primary (arrayConstr (exprColonExprList (exprColonExpr (expr (primary (symbol) @namespace)))))))?)
(includeStmt
  (keyw) @keyword.control.import
  (expr (primary (symbol) @namespace))?
  (expr (primary (arrayConstr (exprColonExprList (exprColonExpr (expr (primary (symbol) @namespace)))))))?)
(importExceptStmt
  (keyw) @keyword.control.import
  (expr (primary (symbol) @namespace))?
  (expr (primary (arrayConstr (exprColonExprList (exprColonExpr (expr (primary (symbol) @namespace)))))))?)
; import statements
; yeah, this is a bit gross.


;; Control Flow

(ifStmt (keyw) @keyword.control.conditional)
(whenStmt (keyw) @keyword.control.conditional)
(elifStmt (keyw) @keyword.control.conditional)
(elseStmt (keyw) @keyword.control.conditional)
(caseStmt (keyw) @keyword.control.conditional)
(ofBranch (keyw) @keyword.control.conditional)
(inlineIfStmt (keyw) @keyword.control.conditional)
(inlineWhenStmt (keyw) @keyword.control.conditional)
; conditional statements
; todo: do block

(forStmt
  . (keyw) @keyword.control.repeat
  . (symbol) @variable
  . (keyw) @keyword.control.repeat)
(whileStmt (keyw) @keyword.control.repeat)
; loop statements

(returnStmt (keyw) @keyword.control.repeat)
(yieldStmt (keyw) @keyword.control.repeat)
(discardStmt (keyw) @keyword.control.repeat)
(breakStmt (keyw) @keyword.control.repeat)
(continueStmt (keyw) @keyword.control.repeat)
; control flow statements

(raiseStmt (keyw) @keyword.control.exception)
(tryStmt (keyw) @keyword.control.exception)
(tryExceptStmt (keyw) @keyword.control.exception)
(tryFinallyStmt (keyw) @keyword.control.exception)
(inlineTryStmt (keyw) @keyword.control.exception)
; (inlineTryExceptStmt (keyw) @keyword.control.exception)
; (inlineTryFinallyStmt (keyw) @keyword.control.exception)
; exception handling statements

(staticStmt (keyw) @keyword)
(deferStmt (keyw) @keyword)
(asmStmt (keyw) @keyword)
(bindStmt (keyw) @keyword)
(mixinStmt (keyw) @keyword)
; miscellaneous blocks

(blockStmt
  (keyw) @keyword.control
  (symbol) @label)
; block statements


;; Types and Type Declarations

(typeDef
  (keyw) @keyword.storage.type
  (symbol) @type)
; names of new types type declarations

(exprColonEqExpr
  . (expr (primary (symbol) @variable))
  . (expr (primary (symbol) @type)))
; variables in inline tuple declarations

(primarySuffix
  (indexSuffix
    (exprColonEqExprList
      (exprColonEqExpr
        (expr
          (primary
            (symbol) @type))))))
; nested types in brackets, i.e. seq[string]

(primaryTypeDef (symbol) @type)
; primary types of type declarations (NOT nested types)

(primaryTypeDef (primaryPrefix (keyw) @type))
; for consistency

(primaryTypeDesc (symbol) @type)
; type annotations, on declarations or in objects

(primaryTypeDesc (primaryPrefix (keyw) @type))
; var types etc

(genericParamList (genericParam (symbol) @type))
; types in generic blocks

(enumDecl (keyw) @keyword.storage.type)
(enumElement (symbol) @type.enum.variant)
; enum declarations and elements

(tupleDecl (keyw) @keyword.storage.type)
; tuple declarations

(objectDecl (keyw) @keyword.storage.type)
(objectPart (symbol) @variable.other.member)
; object declarations and fields

(objectCase
  (keyw) @keyword.control.conditional
  (symbol) @variable.other.member)
(objectBranch (keyw) @keyword.control.conditional)
(objectElif (keyw) @keyword.control.conditional)
(objectElse (keyw) @keyword.control.conditional)
(objectWhen (keyw) @keyword.control.conditional)
; variant objects

(conceptDecl (keyw) @keyword.storage.type)
(conceptParam (keyw) @type)
(conceptParam (symbol) @variable)
; concept declarations, parameters, and qualifiers on those parameters

((expr
  (primary (symbol))
  (operator) @operator
  (primary (symbol) @type))
 (#match? @operator "is"))
((exprStmt
  (primary (symbol))
  (operator) @operator
  (primary (symbol) @type))
 (#match? @operator "is"))
; symbols likely to be types: "x is t" means t is either a type or a type variable

; distinct?


;; Functions

(routine
  . (keyw) @keyword.function
  . (symbol) @function)
; function declarations

(routineExpr (keyw) @keyword.function)
; discarded function

(routineExprTypeDesc (keyw) @keyword.function)
; function declarations as types

(primary
  . (symbol) @function.call
  . (primarySuffix (functionCall)))
; regular function calls

(primary
  . (symbol) @function.call
  . (primarySuffix (cmdCall)))
; function calls without parenthesis

(primary
  (primarySuffix (qualifiedSuffix (symbol) @function.call))
  . (primarySuffix (functionCall)))
; uniform function call syntax calls

(primary
  (primarySuffix (qualifiedSuffix (symbol) @function.call))
  . (primarySuffix (cmdCall)))
; just in case

(primary
  (symbol) @constructor
  (primarySuffix (objectConstr)))
; object constructor

; does not appear to be a way to distinguish these without verbatium matching
; [] @function.builtin
; [] @function.method
; [] @function.macro
; [] @function.special


;; Variables

(paramList (paramColonEquals (symbol) @variable.parameter))
; parameter identifiers

(identColon (ident) @variable.other.member)
; named parts of tuples

(symbolColonExpr (symbol) @variable)
; object constructor parameters

(symbolEqExpr (symbol) @variable)
; named parameters

(variable
  (keyw) @keyword.storage.type
  (declColonEquals (symbol) @variable))
; let, var, const expressions

((primary (symbol) @variable.builtin)
 (#match? @variable.builtin "result"))
; `result` is an implicit builtin variable inside function scopes

((primary (symbol) @type)
 (#match? @type "^[A-Z]"))
; assume PascalCase identifiers to be types

((primary
  (primarySuffix
    (qualifiedSuffix
      (symbol) @type)))
 (#match? @type "^[A-Z]"))
; assume PascalCase member variables to be enum entries

(primary (symbol) @variable)
; overzealous, matches variables

(primary (primarySuffix (qualifiedSuffix (symbol) @variable.other.member)))
; overzealous, matches member variables: i.e. x in foo.x

(keyw) @keyword
; more specific matches are done above whenever possible