Debian Codegraph @

runtime/queries/nim/highlights.scm

raw symbols SCIP
1 ;; Constants, Comments, and Literals
2
3 (comment) @comment.line
4 (block_comment) @comment.block
5 [
6 (documentation_comment)
7 (block_documentation_comment)
8 ] @comment.block.documentation
9
10 (nil_literal) @constant.builtin
11
12 (char_literal) @constant.character
13 (escape_sequence) @constant.character.escape
14 (custom_numeric_literal) @constant.numeric
15 (integer_literal) @constant.numeric.integer
16 (float_literal) @constant.numeric.float
17 ; literals
18 ; todo: literal?
19
20 [
21 (long_string_literal)
22 (raw_string_literal)
23 (generalized_string)
24 (interpreted_string_literal)
25 ] @string
26 ; (generalized_string (string_content) @none) ; todo: attempt to un-match string_content
27 ; [] @string.regexp
28
29 [
30 "."
31 ","
32 ";"
33 ":"
34 ] @punctuation.delimiter
35 [
36 "("
37 ")"
38 "["
39 "]"
40 "{"
41 "}"
42 "{."
43 ".}"
44 ] @punctuation.bracket
45 ; todo: interpolated_str_lit?? & { }?
46
47 [
48 "and"
49 "or"
50 "xor"
51 "not"
52 "div"
53 "mod"
54 "shl"
55 "shr"
56 "from"
57 "as"
58 "of"
59 "in"
60 "notin"
61 "is"
62 "isnot"
63 ] @keyword.operator
64
65 [(operator) "="] @operator
66 (infix_expression operator: _ @operator)
67 (prefix_expression operator: _ @operator)
68
69 (pragma_list
70 (identifier)? @attribute
71 (colon_expression
72 (identifier) @attribute)?)
73
74 ;; Imports and Exports
75
76 [
77 "import"
78 "export"
79 "include"
80 "from"
81 ] @keyword.control.import
82
83 (import_statement
84 [
85 (identifier) @namespace
86 (expression_list (identifier) @namespace)
87 (except_clause
88 "except" @keyword.control.import
89 (expression_list (identifier) @namespace))])
90 (import_from_statement
91 (identifier) @namespace
92 (expression_list (identifier) @namespace))
93 (include_statement (expression_list (identifier) @namespace))
94 (export_statement (expression_list (identifier) @namespace))
95
96 ;; Control Flow
97
98 [
99 "if"
100 "when"
101 "case"
102 "elif"
103 "else"
104 ] @keyword.control.conditional
105 (of_branch "of" @keyword.control.conditional)
106 ; conditional statements
107 ; todo: do block
108
109 "block" @keyword.control
110 (block label: (_) @label)
111
112 [
113 "for"
114 "while"
115 "continue"
116 "break"
117 ] @keyword.control.repeat
118 (for "in" @keyword.control.repeat)
119
120 [
121 "return"
122 "yield"
123 ] @keyword.control.return
124 ; return statements
125
126 [
127 "try"
128 "except"
129 "finally"
130 "raise"
131 ] @keyword.control.exception
132 ; exception handling statements
133
134 [
135 "asm"
136 "bind"
137 "mixin"
138 "defer"
139 "static"
140 ] @keyword
141 ; miscellaneous keywords
142
143 ;; Types and Type Declarations
144
145 [
146 "let"
147 "var"
148 "const"
149 "type"
150 "object"
151 "tuple"
152 "enum"
153 "concept"
154 ] @keyword.storage.type
155
156 (var_type "var" @keyword.storage.modifier)
157 (out_type "out" @keyword.storage.modifier)
158 (distinct_type "distinct" @keyword.storage.modifier)
159 (ref_type "ref" @keyword.storage.modifier)
160 (pointer_type "ptr" @keyword.storage.modifier)
161
162 (var_parameter "var" @keyword.storage.modifier)
163 (type_parameter "type" @keyword.storage.modifier)
164 (static_parameter "static" @keyword.storage.modifier)
165 (ref_parameter "ref" @keyword.storage.modifier)
166 (pointer_parameter "ptr" @keyword.storage.modifier)
167 ; (var_parameter (identifier) @variable.parameter)
168 ; (type_parameter (identifier) @variable.parameter)
169 ; (static_parameter (identifier) @variable.parameter)
170 ; (ref_parameter (identifier) @variable.parameter)
171 ; (pointer_parameter (identifier) @variable.parameter)
172 ; todo: when are these used??
173
174 (type_section
175 (type_declaration
176 (type_symbol_declaration
177 name: (_) @type)))
178 ; types in type declarations
179
180 (enum_field_declaration
181 (symbol_declaration
182 name: (_) @type.enum.variant))
183 ; types as enum variants
184
185 (variant_declaration
186 alternative: (of_branch
187 values: (expression_list (_) @type.enum.variant)))
188 ; types as object variants
189
190 (case
191 (of_branch
192 values: (expression_list (_) @constant)))
193 ; case values are guaranteed to be constant
194
195 (type_expression
196 [
197 (identifier) @type
198 (bracket_expression
199 [
200 (identifier) @type
201 (argument_list (identifier) @type)])
202 (tuple_construction
203 [
204 (identifier) @type
205 (bracket_expression
206 [
207 (identifier) @type
208 (argument_list (identifier) @type)])])])
209 ; types in type expressions
210
211 (call
212 function: (bracket_expression
213 right: (argument_list (identifier) @type)))
214 ; types as generic parameters
215
216 ; (dot_generic_call
217 ; generic_arguments: (_) @type)
218 ; ???
219
220 (infix_expression
221 operator:
222 [
223 "is"
224 "isnot"
225 ]
226 right: (_) @type)
227 ; types in "is" comparisons
228
229 (except_branch
230 values: (expression_list
231 [
232 (identifier) @type
233 (infix_expression
234 left: (identifier) @type
235 operator: "as"
236 right: (_) @variable)]))
237 ; types in exception branches
238
239 ;; Functions
240
241 [
242 "proc"
243 "func"
244 "method"
245 "converter"
246 "iterator"
247 "template"
248 "macro"
249 ] @keyword.function
250
251 (exported_symbol "*" @attribute)
252 (_ "=" @punctuation.delimiter [body: (_) value: (_)])
253
254 (proc_declaration name: (_) @function)
255 (func_declaration name: (_) @function)
256 (iterator_declaration name: (_) @function)
257 (converter_declaration name: (_) @function)
258 (method_declaration name: (_) @function.method)
259 (template_declaration name: (_) @function.macro)
260 (macro_declaration name: (_) @function.macro)
261 (symbol_declaration name: (_) @variable)
262
263 ; Member access: the field of a dot expression (o.field). Before the call
264 ; rule below so a method call's right-hand identifier reclaims @function.
265 (dot_expression
266 right: (identifier) @variable.other.member)
267
268 (call
269 function: [
270 (identifier) @function
271 (dot_expression
272 right: (identifier) @function)
273 (bracket_expression
274 left: [
275 (identifier) @function
276 (dot_expression
277 right: (identifier) @function)])])
278 (generalized_string
279 function: [
280 (identifier) @function
281 (dot_expression
282 right: (identifier) @function)
283 (bracket_expression
284 left: [
285 (identifier) @function
286 (dot_expression
287 right: (identifier) @function)])])
288 (dot_generic_call function: (_) @function)
289
290 ;; Variables
291
292 (parameter_declaration
293 (symbol_declaration_list
294 (symbol_declaration
295 name: (_) @variable.parameter)))
296 (argument_list
297 (equal_expression
298 left: (_) @variable.parameter))
299 (concept_declaration
300 parameters: (parameter_list (identifier) @variable.parameter))
301
302 (field_declaration
303 (symbol_declaration_list
304 (symbol_declaration
305 name: (_) @variable.other.member)))
306 (call
307 (argument_list
308 (colon_expression
309 left: (_) @variable.other.member)))
310 (tuple_construction
311 (colon_expression
312 left: (_) @variable.other.member))
313 (variant_declaration
314 (variant_discriminator_declaration
315 (symbol_declaration_list
316 (symbol_declaration
317 name: (_) @variable.other.member))))
318
319 ;; Miscellaneous Matches
320
321 [
322 "cast"
323 "discard"
324 "do"
325 ] @keyword
326 ; also: addr end interface using
327
328 (blank_identifier) @variable.builtin
329
330 ; Highlight left side of dot expressions (variables being accessed)
331 (dot_expression
332 left: (identifier) @variable)
333
334 ;; ============================================================================
335 ;; Fallback identifier patterns (applied last, after all specific contexts)
336 ;; ============================================================================
337
338 ;; Special built-in identifiers
339 ((identifier) @variable.builtin
340 (#eq? @variable.builtin "result"))
341
342 ;; Built-in constants
343 ((identifier) @constant.builtin
344 (#match? @constant.builtin "^(NaN|Inf|NegInf|isMainModule|appType|CompileDate|CompileTime|cpuEndian|hostOS|hostCPU|NimVersion|NimMajor|NimMinor|NimPatch|nimvm|QuitSuccess|QuitFailure)$"))
345
346 ;; Built-in boolean constants
347 ((identifier) @constant.builtin.boolean
348 (#any-of? @constant.builtin.boolean "true" "false" "on" "off"))
349
350 ;; Built-in types (primitive and common types)
351 ((identifier) @type.builtin
352 (#match? @type.builtin "^(int|int8|int16|int32|int64|uint|uint8|uint16|uint32|uint64|float|float32|float64|bool|char|string|cstring|pointer|ptr|ref|void|auto|any|type|typed|untyped|typedesc|range|array|openArray|openarray|varargs|seq|set|tuple|object|enum|concept|distinct|proc|iterator|cstringArray|csize|csize_t|clonglong|culonglong|clong|culong|cint|cuint|cshort|cushort|cchar|cschar|cuchar|cfloat|cdouble|clongdouble|byte|Natural|Positive|sink|lent|owned|iterable|static)$"))
353
354 ;; Constants (ALL_CAPS naming convention) - fallback for unmatched identifiers
355 ((identifier) @constant
356 (#match? @constant "^[A-Z][A-Z0-9_]*$"))
357
358 ;; Type names (PascalCase - starts with capital, contains lowercase) - fallback
359 ((identifier) @type
360 (#match? @type "^[A-Z][a-z]"))