@kmugalkhod/lightcode 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,443 @@
1
+ ; From tree-sitter-python licensed under MIT License
2
+ ; Copyright (c) 2016 Max Brunsfeld
3
+ ; Variables
4
+ (identifier) @variable
5
+
6
+ ; Reset highlighting in f-string interpolations
7
+ (interpolation) @none
8
+
9
+ ; Identifier naming conventions
10
+ ((identifier) @type
11
+ (#lua-match? @type "^[A-Z].*[a-z]"))
12
+
13
+ ((identifier) @constant
14
+ (#lua-match? @constant "^[A-Z][A-Z_0-9]*$"))
15
+
16
+ ((identifier) @constant.builtin
17
+ (#lua-match? @constant.builtin "^__[a-zA-Z0-9_]*__$"))
18
+
19
+ ((identifier) @constant.builtin
20
+ (#any-of? @constant.builtin
21
+ ; https://docs.python.org/3/library/constants.html
22
+ "NotImplemented" "Ellipsis" "quit" "exit" "copyright" "credits" "license"))
23
+
24
+ "_" @character.special ; match wildcard
25
+
26
+ ((assignment
27
+ left: (identifier) @type.definition
28
+ (type
29
+ (identifier) @_annotation))
30
+ (#eq? @_annotation "TypeAlias"))
31
+
32
+ ((assignment
33
+ left: (identifier) @type.definition
34
+ right: (call
35
+ function: (identifier) @_func))
36
+ (#any-of? @_func "TypeVar" "NewType"))
37
+
38
+ ; Function definitions
39
+ (function_definition
40
+ name: (identifier) @function)
41
+
42
+ (type
43
+ (identifier) @type)
44
+
45
+ (type
46
+ (subscript
47
+ (identifier) @type)) ; type subscript: Tuple[int]
48
+
49
+ ((call
50
+ function: (identifier) @_isinstance
51
+ arguments: (argument_list
52
+ (_)
53
+ (identifier) @type))
54
+ (#eq? @_isinstance "isinstance"))
55
+
56
+ ; Literals
57
+ (none) @constant.builtin
58
+
59
+ [
60
+ (true)
61
+ (false)
62
+ ] @boolean
63
+
64
+ (integer) @number
65
+
66
+ (float) @number.float
67
+
68
+ (comment) @comment @spell
69
+
70
+ ((module
71
+ .
72
+ (comment) @keyword.directive @nospell)
73
+ (#lua-match? @keyword.directive "^#!/"))
74
+
75
+ (string) @string
76
+
77
+ [
78
+ (escape_sequence)
79
+ (escape_interpolation)
80
+ ] @string.escape
81
+
82
+ ; doc-strings
83
+ (expression_statement
84
+ (string
85
+ (string_content) @spell) @string.documentation)
86
+
87
+ ; Tokens
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
+ ] @operator
127
+
128
+ ; Keywords
129
+ [
130
+ "and"
131
+ "in"
132
+ "is"
133
+ "not"
134
+ "or"
135
+ "is not"
136
+ "not in"
137
+ "del"
138
+ ] @keyword.operator
139
+
140
+ [
141
+ "def"
142
+ "lambda"
143
+ ] @keyword.function
144
+
145
+ [
146
+ "assert"
147
+ "exec"
148
+ "global"
149
+ "nonlocal"
150
+ "pass"
151
+ "print"
152
+ "with"
153
+ "as"
154
+ ] @keyword
155
+
156
+ [
157
+ "type"
158
+ "class"
159
+ ] @keyword.type
160
+
161
+ [
162
+ "async"
163
+ "await"
164
+ ] @keyword.coroutine
165
+
166
+ [
167
+ "return"
168
+ "yield"
169
+ ] @keyword.return
170
+
171
+ (yield
172
+ "from" @keyword.return)
173
+
174
+ (future_import_statement
175
+ "from" @keyword.import
176
+ "__future__" @module.builtin)
177
+
178
+ (import_from_statement
179
+ "from" @keyword.import)
180
+
181
+ "import" @keyword.import
182
+
183
+ (aliased_import
184
+ "as" @keyword.import)
185
+
186
+ (wildcard_import
187
+ "*" @character.special)
188
+
189
+ (import_statement
190
+ name: (dotted_name
191
+ (identifier) @module))
192
+
193
+ (import_statement
194
+ name: (aliased_import
195
+ name: (dotted_name
196
+ (identifier) @module)
197
+ alias: (identifier) @module))
198
+
199
+ (import_from_statement
200
+ module_name: (dotted_name
201
+ (identifier) @module))
202
+
203
+ (import_from_statement
204
+ module_name: (relative_import
205
+ (dotted_name
206
+ (identifier) @module)))
207
+
208
+ [
209
+ "if"
210
+ "elif"
211
+ "else"
212
+ "match"
213
+ "case"
214
+ ] @keyword.conditional
215
+
216
+ [
217
+ "for"
218
+ "while"
219
+ "break"
220
+ "continue"
221
+ ] @keyword.repeat
222
+
223
+ [
224
+ "try"
225
+ "except"
226
+ "except*"
227
+ "raise"
228
+ "finally"
229
+ ] @keyword.exception
230
+
231
+ (raise_statement
232
+ "from" @keyword.exception)
233
+
234
+ (try_statement
235
+ (else_clause
236
+ "else" @keyword.exception))
237
+
238
+ [
239
+ "("
240
+ ")"
241
+ "["
242
+ "]"
243
+ "{"
244
+ "}"
245
+ ] @punctuation.bracket
246
+
247
+ (interpolation
248
+ "{" @punctuation.special
249
+ "}" @punctuation.special)
250
+
251
+ (type_conversion) @function.macro
252
+
253
+ [
254
+ ","
255
+ "."
256
+ ":"
257
+ ";"
258
+ (ellipsis)
259
+ ] @punctuation.delimiter
260
+
261
+ ((identifier) @type.builtin
262
+ (#any-of? @type.builtin
263
+ ; https://docs.python.org/3/library/exceptions.html
264
+ "BaseException" "Exception" "ArithmeticError" "BufferError" "LookupError" "AssertionError"
265
+ "AttributeError" "EOFError" "FloatingPointError" "GeneratorExit" "ImportError"
266
+ "ModuleNotFoundError" "IndexError" "KeyError" "KeyboardInterrupt" "MemoryError" "NameError"
267
+ "NotImplementedError" "OSError" "OverflowError" "RecursionError" "ReferenceError" "RuntimeError"
268
+ "StopIteration" "StopAsyncIteration" "SyntaxError" "IndentationError" "TabError" "SystemError"
269
+ "SystemExit" "TypeError" "UnboundLocalError" "UnicodeError" "UnicodeEncodeError"
270
+ "UnicodeDecodeError" "UnicodeTranslateError" "ValueError" "ZeroDivisionError" "EnvironmentError"
271
+ "IOError" "WindowsError" "BlockingIOError" "ChildProcessError" "ConnectionError"
272
+ "BrokenPipeError" "ConnectionAbortedError" "ConnectionRefusedError" "ConnectionResetError"
273
+ "FileExistsError" "FileNotFoundError" "InterruptedError" "IsADirectoryError"
274
+ "NotADirectoryError" "PermissionError" "ProcessLookupError" "TimeoutError" "Warning"
275
+ "UserWarning" "DeprecationWarning" "PendingDeprecationWarning" "SyntaxWarning" "RuntimeWarning"
276
+ "FutureWarning" "ImportWarning" "UnicodeWarning" "BytesWarning" "ResourceWarning"
277
+ ; https://docs.python.org/3/library/stdtypes.html
278
+ "bool" "int" "float" "complex" "list" "tuple" "range" "str" "bytes" "bytearray" "memoryview"
279
+ "set" "frozenset" "dict" "type" "object"))
280
+
281
+ ; Normal parameters
282
+ (parameters
283
+ (identifier) @variable.parameter)
284
+
285
+ ; Lambda parameters
286
+ (lambda_parameters
287
+ (identifier) @variable.parameter)
288
+
289
+ (lambda_parameters
290
+ (tuple_pattern
291
+ (identifier) @variable.parameter))
292
+
293
+ ; Default parameters
294
+ (keyword_argument
295
+ name: (identifier) @variable.parameter)
296
+
297
+ ; Naming parameters on call-site
298
+ (default_parameter
299
+ name: (identifier) @variable.parameter)
300
+
301
+ (typed_parameter
302
+ (identifier) @variable.parameter)
303
+
304
+ (typed_default_parameter
305
+ name: (identifier) @variable.parameter)
306
+
307
+ ; Variadic parameters *args, **kwargs
308
+ (parameters
309
+ (list_splat_pattern ; *args
310
+ (identifier) @variable.parameter))
311
+
312
+ (parameters
313
+ (dictionary_splat_pattern ; **kwargs
314
+ (identifier) @variable.parameter))
315
+
316
+ ; Typed variadic parameters
317
+ (parameters
318
+ (typed_parameter
319
+ (list_splat_pattern ; *args: type
320
+ (identifier) @variable.parameter)))
321
+
322
+ (parameters
323
+ (typed_parameter
324
+ (dictionary_splat_pattern ; *kwargs: type
325
+ (identifier) @variable.parameter)))
326
+
327
+ ; Lambda parameters
328
+ (lambda_parameters
329
+ (list_splat_pattern
330
+ (identifier) @variable.parameter))
331
+
332
+ (lambda_parameters
333
+ (dictionary_splat_pattern
334
+ (identifier) @variable.parameter))
335
+
336
+ ((identifier) @variable.builtin
337
+ (#eq? @variable.builtin "self"))
338
+
339
+ ((identifier) @variable.builtin
340
+ (#eq? @variable.builtin "cls"))
341
+
342
+ ; After @type.builtin bacause builtins (such as `type`) are valid as attribute name
343
+ ((attribute
344
+ attribute: (identifier) @variable.member)
345
+ (#lua-match? @variable.member "^[%l_].*$"))
346
+
347
+ ; Class definitions
348
+ (class_definition
349
+ name: (identifier) @type)
350
+
351
+ (class_definition
352
+ body: (block
353
+ (function_definition
354
+ name: (identifier) @function.method)))
355
+
356
+ (class_definition
357
+ superclasses: (argument_list
358
+ (identifier) @type))
359
+
360
+ ((class_definition
361
+ body: (block
362
+ (expression_statement
363
+ (assignment
364
+ left: (identifier) @variable.member))))
365
+ (#lua-match? @variable.member "^[%l_].*$"))
366
+
367
+ ((class_definition
368
+ body: (block
369
+ (expression_statement
370
+ (assignment
371
+ left: (_
372
+ (identifier) @variable.member)))))
373
+ (#lua-match? @variable.member "^[%l_].*$"))
374
+
375
+ ((class_definition
376
+ (block
377
+ (function_definition
378
+ name: (identifier) @constructor)))
379
+ (#any-of? @constructor "__new__" "__init__"))
380
+
381
+ ; Function calls
382
+ (call
383
+ function: (identifier) @function.call)
384
+
385
+ (call
386
+ function: (attribute
387
+ attribute: (identifier) @function.method.call))
388
+
389
+ ((call
390
+ function: (identifier) @constructor)
391
+ (#lua-match? @constructor "^%u"))
392
+
393
+ ((call
394
+ function: (attribute
395
+ attribute: (identifier) @constructor))
396
+ (#lua-match? @constructor "^%u"))
397
+
398
+ ; Builtin functions
399
+ ((call
400
+ function: (identifier) @function.builtin)
401
+ (#any-of? @function.builtin
402
+ "abs" "all" "any" "ascii" "bin" "bool" "breakpoint" "bytearray" "bytes" "callable" "chr"
403
+ "classmethod" "compile" "complex" "delattr" "dict" "dir" "divmod" "enumerate" "eval" "exec"
404
+ "filter" "float" "format" "frozenset" "getattr" "globals" "hasattr" "hash" "help" "hex" "id"
405
+ "input" "int" "isinstance" "issubclass" "iter" "len" "list" "locals" "map" "max" "memoryview"
406
+ "min" "next" "object" "oct" "open" "ord" "pow" "print" "property" "range" "repr" "reversed"
407
+ "round" "set" "setattr" "slice" "sorted" "staticmethod" "str" "sum" "super" "tuple" "type"
408
+ "vars" "zip" "__import__"))
409
+
410
+ ; Regex from the `re` module
411
+ (call
412
+ function: (attribute
413
+ object: (identifier) @_re)
414
+ arguments: (argument_list
415
+ .
416
+ (string
417
+ (string_content) @string.regexp))
418
+ (#eq? @_re "re"))
419
+
420
+ ; Decorators
421
+ ((decorator
422
+ "@" @attribute)
423
+ (#set! priority 101))
424
+
425
+ (decorator
426
+ (identifier) @attribute)
427
+
428
+ (decorator
429
+ (attribute
430
+ attribute: (identifier) @attribute))
431
+
432
+ (decorator
433
+ (call
434
+ (identifier) @attribute))
435
+
436
+ (decorator
437
+ (call
438
+ (attribute
439
+ attribute: (identifier) @attribute)))
440
+
441
+ ((decorator
442
+ (identifier) @attribute.builtin)
443
+ (#any-of? @attribute.builtin "classmethod" "property" "staticmethod"))
@@ -0,0 +1,159 @@
1
+ ; Identifiers
2
+
3
+ (type_identifier) @type
4
+ (primitive_type) @type.builtin
5
+ (field_identifier) @property
6
+
7
+ ; Identifier conventions
8
+
9
+ ; Assume all-caps names are constants
10
+ ((identifier) @constant
11
+ (#match? @constant "^[A-Z][A-Z\\d_]+$'"))
12
+
13
+ ; Assume uppercase names are enum constructors
14
+ ((identifier) @constructor
15
+ (#match? @constructor "^[A-Z]"))
16
+
17
+ ; Assume that uppercase names in paths are types
18
+ ((scoped_identifier
19
+ path: (identifier) @type)
20
+ (#match? @type "^[A-Z]"))
21
+ ((scoped_identifier
22
+ path: (scoped_identifier
23
+ name: (identifier) @type))
24
+ (#match? @type "^[A-Z]"))
25
+ ((scoped_type_identifier
26
+ path: (identifier) @type)
27
+ (#match? @type "^[A-Z]"))
28
+ ((scoped_type_identifier
29
+ path: (scoped_identifier
30
+ name: (identifier) @type))
31
+ (#match? @type "^[A-Z]"))
32
+
33
+ ; Assume all qualified names in struct patterns are enum constructors. (They're
34
+ ; either that, or struct names; highlighting both as constructors seems to be
35
+ ; the less glaring choice of error, visually.)
36
+ (struct_pattern
37
+ type: (scoped_type_identifier
38
+ name: (type_identifier) @constructor))
39
+
40
+ ; Function calls
41
+
42
+ (call_expression
43
+ function: (identifier) @function)
44
+ (call_expression
45
+ function: (field_expression
46
+ field: (field_identifier) @function.method))
47
+ (call_expression
48
+ function: (scoped_identifier
49
+ "::"
50
+ name: (identifier) @function))
51
+
52
+ (generic_function
53
+ function: (identifier) @function)
54
+ (generic_function
55
+ function: (scoped_identifier
56
+ name: (identifier) @function))
57
+ (generic_function
58
+ function: (field_expression
59
+ field: (field_identifier) @function.method))
60
+
61
+ (macro_invocation
62
+ macro: (identifier) @function.macro
63
+ "!" @function.macro)
64
+
65
+ ; Function definitions
66
+
67
+ (function_item (identifier) @function)
68
+ (function_signature_item (identifier) @function)
69
+
70
+ (line_comment) @comment
71
+ (block_comment) @comment
72
+
73
+ (line_comment (doc_comment)) @comment.documentation
74
+ (block_comment (doc_comment)) @comment.documentation
75
+
76
+ "(" @punctuation.bracket
77
+ ")" @punctuation.bracket
78
+ "[" @punctuation.bracket
79
+ "]" @punctuation.bracket
80
+ "{" @punctuation.bracket
81
+ "}" @punctuation.bracket
82
+
83
+ (type_arguments
84
+ "<" @punctuation.bracket
85
+ ">" @punctuation.bracket)
86
+ (type_parameters
87
+ "<" @punctuation.bracket
88
+ ">" @punctuation.bracket)
89
+
90
+ "::" @punctuation.delimiter
91
+ ":" @punctuation.delimiter
92
+ "." @punctuation.delimiter
93
+ "," @punctuation.delimiter
94
+ ";" @punctuation.delimiter
95
+
96
+ (parameter (identifier) @variable.parameter)
97
+
98
+ (lifetime (identifier) @label)
99
+
100
+ "as" @keyword
101
+ "async" @keyword
102
+ "await" @keyword
103
+ "break" @keyword
104
+ "const" @keyword
105
+ "continue" @keyword
106
+ "default" @keyword
107
+ "dyn" @keyword
108
+ "else" @keyword
109
+ "enum" @keyword
110
+ "extern" @keyword
111
+ "fn" @keyword
112
+ "for" @keyword
113
+ "if" @keyword
114
+ "impl" @keyword
115
+ "in" @keyword
116
+ "let" @keyword
117
+ "loop" @keyword
118
+ "macro_rules!" @keyword
119
+ "match" @keyword
120
+ "mod" @keyword
121
+ "move" @keyword
122
+ "pub" @keyword
123
+ "ref" @keyword
124
+ "return" @keyword
125
+ "static" @keyword
126
+ "struct" @keyword
127
+ "trait" @keyword
128
+ "type" @keyword
129
+ "union" @keyword
130
+ "unsafe" @keyword
131
+ "use" @keyword
132
+ "where" @keyword
133
+ "while" @keyword
134
+ "yield" @keyword
135
+ (crate) @keyword
136
+ (mutable_specifier) @keyword
137
+ (use_list (self) @keyword)
138
+ (scoped_use_list (self) @keyword)
139
+ (scoped_identifier (self) @keyword)
140
+ (super) @keyword
141
+
142
+ (self) @variable.builtin
143
+
144
+ (char_literal) @string
145
+ (string_literal) @string
146
+ (raw_string_literal) @string
147
+
148
+ (boolean_literal) @constant.builtin
149
+ (integer_literal) @constant.builtin
150
+ (float_literal) @constant.builtin
151
+
152
+ (escape_sequence) @escape
153
+
154
+ (attribute_item) @attribute
155
+ (inner_attribute_item) @attribute
156
+
157
+ "*" @operator
158
+ "&" @operator
159
+ "'" @operator
@@ -0,0 +1,99 @@
1
+ (boolean_scalar) @boolean
2
+
3
+ (null_scalar) @constant.builtin
4
+
5
+ (double_quote_scalar) @string
6
+
7
+ (single_quote_scalar) @string
8
+
9
+ ((block_scalar) @string
10
+ (#set! priority 99))
11
+
12
+ (string_scalar) @string
13
+
14
+ (escape_sequence) @string.escape
15
+
16
+ (integer_scalar) @number
17
+
18
+ (float_scalar) @number
19
+
20
+ (comment) @comment @spell
21
+
22
+ [
23
+ (anchor_name)
24
+ (alias_name)
25
+ ] @label
26
+
27
+ (tag) @type
28
+
29
+ [
30
+ (yaml_directive)
31
+ (tag_directive)
32
+ (reserved_directive)
33
+ ] @keyword.directive
34
+
35
+ (block_mapping_pair
36
+ key: (flow_node
37
+ [
38
+ (double_quote_scalar)
39
+ (single_quote_scalar)
40
+ ] @property))
41
+
42
+ (block_mapping_pair
43
+ key: (flow_node
44
+ (plain_scalar
45
+ (string_scalar) @property)))
46
+
47
+ (flow_mapping
48
+ (_
49
+ key: (flow_node
50
+ [
51
+ (double_quote_scalar)
52
+ (single_quote_scalar)
53
+ ] @property)))
54
+
55
+ (flow_mapping
56
+ (_
57
+ key: (flow_node
58
+ (plain_scalar
59
+ (string_scalar) @property))))
60
+
61
+ [
62
+ ","
63
+ "-"
64
+ ":"
65
+ ">"
66
+ "?"
67
+ "|"
68
+ ] @punctuation.delimiter
69
+
70
+ [
71
+ "["
72
+ "]"
73
+ "{"
74
+ "}"
75
+ ] @punctuation.bracket
76
+
77
+ [
78
+ "*"
79
+ "&"
80
+ "---"
81
+ "..."
82
+ ] @punctuation.special
83
+
84
+ ; help deal with for yaml's norway problem https://www.bram.us/2022/01/11/yaml-the-norway-problem/
85
+ ; only using `true` and `false`, since Treesitter parser targets YAML spec 1.2 https://github.com/nvim-treesitter/nvim-treesitter/pull/7512#issuecomment-2565397302
86
+ (block_mapping_pair
87
+ value: (block_node
88
+ (block_sequence
89
+ (block_sequence_item
90
+ (flow_node
91
+ (plain_scalar
92
+ (string_scalar) @boolean
93
+ (#any-of? @boolean "TRUE" "FALSE" "True" "False")))))))
94
+
95
+ (block_mapping_pair
96
+ value: (flow_node
97
+ (plain_scalar
98
+ (string_scalar) @boolean
99
+ (#any-of? @boolean "TRUE" "FALSE" "True" "False"))))