@willbooster/tree-sitter-python 2.2.0 → 2.3.1
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.
- package/grammar.js +105 -27
- package/package.json +1 -1
- package/queries/highlights.scm +3 -0
- package/src/node-types.json +80 -4
- package/tree-sitter-python.wasm +0 -0
- package/tree-sitter.json +1 -1
package/grammar.js
CHANGED
|
@@ -43,6 +43,12 @@ module.exports = grammar({
|
|
|
43
43
|
extras: ($) => [$.comment, /[\s\f\uFEFF\u2060\u200B]|\r?\n/, $.line_continuation],
|
|
44
44
|
|
|
45
45
|
conflicts: ($) => [
|
|
46
|
+
[$.default_type_parameter, $.primary_expression],
|
|
47
|
+
[$.primary_expression, $._default_type_primary],
|
|
48
|
+
[$.primary_expression, $._default_generic_type],
|
|
49
|
+
[$.primary_expression, $._default_member_type],
|
|
50
|
+
[$.list, $._default_type_list],
|
|
51
|
+
[$._type_parameter_expression, $.expression],
|
|
46
52
|
[$.primary_expression, $.pattern],
|
|
47
53
|
[$.primary_expression, $.list_splat_pattern],
|
|
48
54
|
[$.tuple, $.tuple_pattern],
|
|
@@ -51,6 +57,7 @@ module.exports = grammar({
|
|
|
51
57
|
[$.named_expression, $.as_pattern],
|
|
52
58
|
[$.print_statement, $.primary_expression],
|
|
53
59
|
[$.match_statement, $.primary_expression],
|
|
60
|
+
[$.primary_expression, $.generic_type],
|
|
54
61
|
],
|
|
55
62
|
|
|
56
63
|
supertypes: ($) => [
|
|
@@ -94,6 +101,8 @@ module.exports = grammar({
|
|
|
94
101
|
$._expressions,
|
|
95
102
|
$._left_hand_side,
|
|
96
103
|
$.keyword_identifier,
|
|
104
|
+
$._type_parameter_name,
|
|
105
|
+
$._default_member_base,
|
|
97
106
|
],
|
|
98
107
|
|
|
99
108
|
reserved: {
|
|
@@ -144,8 +153,6 @@ module.exports = grammar({
|
|
|
144
153
|
|
|
145
154
|
_statement: ($) => choice($._simple_statements, $._compound_statement),
|
|
146
155
|
|
|
147
|
-
// Simple statements
|
|
148
|
-
|
|
149
156
|
_simple_statements: ($) => seq(sep1($._simple_statement, SEMICOLON), optional(SEMICOLON), sym('_newline')),
|
|
150
157
|
|
|
151
158
|
_simple_statement: ($) =>
|
|
@@ -244,8 +251,6 @@ module.exports = grammar({
|
|
|
244
251
|
break_statement: () => prec.left('break'),
|
|
245
252
|
continue_statement: () => prec.left('continue'),
|
|
246
253
|
|
|
247
|
-
// Compound statements
|
|
248
|
-
|
|
249
254
|
_compound_statement: ($) =>
|
|
250
255
|
choice(
|
|
251
256
|
$.if_statement,
|
|
@@ -393,7 +398,100 @@ module.exports = grammar({
|
|
|
393
398
|
':',
|
|
394
399
|
field('body', $._suite)
|
|
395
400
|
),
|
|
396
|
-
type_parameter: ($) =>
|
|
401
|
+
type_parameter: ($) =>
|
|
402
|
+
seq('[', commaSep1(choice($.type, $.splat_type, $.default_type_parameter)), optional(','), ']'),
|
|
403
|
+
|
|
404
|
+
default_type_parameter: ($) =>
|
|
405
|
+
choice(
|
|
406
|
+
seq(
|
|
407
|
+
choice(
|
|
408
|
+
seq(
|
|
409
|
+
field('name', $._type_parameter_name),
|
|
410
|
+
optional(seq(':', field('bound', alias($._type_parameter_expression, $.type))))
|
|
411
|
+
),
|
|
412
|
+
seq('**', field('name', $._type_parameter_name))
|
|
413
|
+
),
|
|
414
|
+
'=',
|
|
415
|
+
field('value', alias($._type_parameter_expression, $.type))
|
|
416
|
+
),
|
|
417
|
+
seq(
|
|
418
|
+
'*',
|
|
419
|
+
field('name', $._type_parameter_name),
|
|
420
|
+
'=',
|
|
421
|
+
field(
|
|
422
|
+
'value',
|
|
423
|
+
choice(alias($._type_parameter_expression, $.type), alias($._default_splat_type, $.list_splat))
|
|
424
|
+
)
|
|
425
|
+
)
|
|
426
|
+
),
|
|
427
|
+
|
|
428
|
+
_type_parameter_name: ($) =>
|
|
429
|
+
choice($.identifier, alias(choice('type', 'match', 'print', 'exec', 'lazy'), $.identifier)),
|
|
430
|
+
|
|
431
|
+
_default_member_base: ($) => choice($._type_parameter_name, alias($._default_member_type, $.member_type)),
|
|
432
|
+
|
|
433
|
+
_type_parameter_expression: ($) => choice($._expression_without_named_expression, prec.dynamic(1, $._default_type)),
|
|
434
|
+
|
|
435
|
+
_default_type: ($) => choice($._default_type_primary, alias($._default_union_type, $.union_type)),
|
|
436
|
+
|
|
437
|
+
_default_type_primary: ($) =>
|
|
438
|
+
choice(
|
|
439
|
+
$.identifier,
|
|
440
|
+
$.keyword_identifier,
|
|
441
|
+
$.none,
|
|
442
|
+
$.string,
|
|
443
|
+
alias($._default_member_type, $.member_type),
|
|
444
|
+
alias($._default_generic_type, $.generic_type),
|
|
445
|
+
alias($._default_type_list, $.list),
|
|
446
|
+
alias($._default_type_tuple, $.tuple),
|
|
447
|
+
alias($._default_parenthesized_type, $.parenthesized_expression)
|
|
448
|
+
),
|
|
449
|
+
|
|
450
|
+
_default_member_type: ($) => seq($._default_member_base, '.', $.identifier),
|
|
451
|
+
|
|
452
|
+
_default_generic_type: ($) => seq($._default_member_base, alias($._default_type_arguments, $.type_parameter)),
|
|
453
|
+
|
|
454
|
+
_default_union_type: ($) =>
|
|
455
|
+
prec.left(PREC.bitwise_or, seq(alias($._default_type, $.type), '|', alias($._default_type_primary, $.type))),
|
|
456
|
+
|
|
457
|
+
_default_parenthesized_type: ($) => seq('(', alias($._default_type, $.type), ')'),
|
|
458
|
+
|
|
459
|
+
_default_type_arguments: ($) =>
|
|
460
|
+
seq(
|
|
461
|
+
'[',
|
|
462
|
+
commaSep1(
|
|
463
|
+
choice(
|
|
464
|
+
alias($._type_parameter_expression, $.type),
|
|
465
|
+
$.named_expression,
|
|
466
|
+
alias($._default_splat_argument, $.splat_type),
|
|
467
|
+
$.slice
|
|
468
|
+
)
|
|
469
|
+
),
|
|
470
|
+
optional(','),
|
|
471
|
+
']'
|
|
472
|
+
),
|
|
473
|
+
|
|
474
|
+
_default_splat_argument: ($) => seq('*', alias($._type_parameter_expression, $.type)),
|
|
475
|
+
|
|
476
|
+
_default_type_list: ($) =>
|
|
477
|
+
prec.dynamic(
|
|
478
|
+
1,
|
|
479
|
+
seq('[', optional(seq(commaSep1(alias($._type_parameter_expression, $.type)), optional(','))), ']')
|
|
480
|
+
),
|
|
481
|
+
|
|
482
|
+
_default_type_tuple: ($) =>
|
|
483
|
+
prec.dynamic(
|
|
484
|
+
1,
|
|
485
|
+
seq(
|
|
486
|
+
'(',
|
|
487
|
+
alias($._type_parameter_expression, $.type),
|
|
488
|
+
',',
|
|
489
|
+
optional(seq(commaSep1(alias($._type_parameter_expression, $.type)), optional(','))),
|
|
490
|
+
')'
|
|
491
|
+
)
|
|
492
|
+
),
|
|
493
|
+
|
|
494
|
+
_default_splat_type: ($) => seq('*', choice($.primary_expression, prec.dynamic(1, alias($._default_type, $.type)))),
|
|
397
495
|
|
|
398
496
|
_generic_type_arguments: ($) =>
|
|
399
497
|
seq('[', commaSep1(choice($.type, alias($._list_splat_argument, $.splat_type))), optional(','), ']'),
|
|
@@ -434,8 +532,6 @@ module.exports = grammar({
|
|
|
434
532
|
|
|
435
533
|
dotted_name: ($) => prec(1, sep1($.identifier, '.')),
|
|
436
534
|
|
|
437
|
-
// Match cases
|
|
438
|
-
|
|
439
535
|
case_pattern: ($) => prec(1, choice(alias($._as_pattern, $.as_pattern), $.keyword_pattern, $._simple_pattern)),
|
|
440
536
|
|
|
441
537
|
_simple_pattern: ($) =>
|
|
@@ -482,8 +578,6 @@ module.exports = grammar({
|
|
|
482
578
|
complex_pattern: ($) =>
|
|
483
579
|
prec(1, seq(optional('-'), choice($.integer, $.float), choice('+', '-'), choice($.integer, $.float))),
|
|
484
580
|
|
|
485
|
-
// Patterns
|
|
486
|
-
|
|
487
581
|
_parameters: ($) => seq(commaSep1($.parameter), optional(',')),
|
|
488
582
|
|
|
489
583
|
_patterns: ($) => seq(commaSep1($.pattern), optional(',')),
|
|
@@ -529,13 +623,9 @@ module.exports = grammar({
|
|
|
529
623
|
|
|
530
624
|
dictionary_splat_pattern: ($) => seq('**', choice($.identifier, $.keyword_identifier, $.subscript, $.attribute)),
|
|
531
625
|
|
|
532
|
-
// Extended patterns (patterns allowed in match statement are far more flexible than simple patterns though still a subset of "expression")
|
|
533
|
-
|
|
534
626
|
as_pattern: ($) =>
|
|
535
627
|
prec.left(seq($.expression, 'as', field('alias', alias($.expression, sym('as_pattern_target'))))),
|
|
536
628
|
|
|
537
|
-
// Expressions
|
|
538
|
-
|
|
539
629
|
_expression_within_for_in_clause: ($) => choice($.expression, alias($.lambda_within_for_in_clause, $.lambda)),
|
|
540
630
|
|
|
541
631
|
expression: ($) => choice($._expression_without_named_expression, $.named_expression, $.as_pattern),
|
|
@@ -749,7 +839,7 @@ module.exports = grammar({
|
|
|
749
839
|
type: ($) => choice(prec(1, $.expression), $.generic_type, $.union_type, $.constrained_type, $.member_type),
|
|
750
840
|
splat_type: ($) => prec(1, seq(choice('*', '**'), $.identifier)),
|
|
751
841
|
generic_type: ($) =>
|
|
752
|
-
prec(
|
|
842
|
+
prec.dynamic(
|
|
753
843
|
1,
|
|
754
844
|
seq(choice($.identifier, alias('type', $.identifier)), alias($._generic_type_arguments, $.type_parameter))
|
|
755
845
|
),
|
|
@@ -760,8 +850,6 @@ module.exports = grammar({
|
|
|
760
850
|
keyword_argument: ($) =>
|
|
761
851
|
seq(field('name', choice($.identifier, $.keyword_identifier)), '=', field('value', $.expression)),
|
|
762
852
|
|
|
763
|
-
// Literals
|
|
764
|
-
|
|
765
853
|
list: ($) => seq('[', optional($._collection_elements), ']'),
|
|
766
854
|
|
|
767
855
|
set: ($) => seq('{', $._collection_elements, '}'),
|
|
@@ -883,13 +971,7 @@ module.exports = grammar({
|
|
|
883
971
|
seq(choice('0x', '0X'), repeat1(/_?[A-Fa-f0-9]+/), optional(/[Ll]/)),
|
|
884
972
|
seq(choice('0o', '0O'), repeat1(/_?[0-7]+/), optional(/[Ll]/)),
|
|
885
973
|
seq(choice('0b', '0B'), repeat1(/_?[0-1]+/), optional(/[Ll]/)),
|
|
886
|
-
seq(
|
|
887
|
-
repeat1(/[0-9]+_?/),
|
|
888
|
-
choice(
|
|
889
|
-
optional(/[Ll]/), // long numbers
|
|
890
|
-
optional(/[jJ]/) // complex numbers
|
|
891
|
-
)
|
|
892
|
-
)
|
|
974
|
+
seq(repeat1(/[0-9]+_?/), choice(optional(/[Ll]/), optional(/[jJ]/)))
|
|
893
975
|
)
|
|
894
976
|
),
|
|
895
977
|
|
|
@@ -940,8 +1022,6 @@ module.exports = grammar({
|
|
|
940
1022
|
Object.assign(module.exports, { PREC });
|
|
941
1023
|
|
|
942
1024
|
/**
|
|
943
|
-
* Creates a rule to match one or more of the rules separated by a comma
|
|
944
|
-
*
|
|
945
1025
|
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} rule
|
|
946
1026
|
*
|
|
947
1027
|
* @returns {import('@willbooster/web-tree-sitter/dsl').SeqRule}
|
|
@@ -951,8 +1031,6 @@ function commaSep1(rule) {
|
|
|
951
1031
|
}
|
|
952
1032
|
|
|
953
1033
|
/**
|
|
954
|
-
* Creates a rule to match one or more occurrences of `rule` separated by `sep`
|
|
955
|
-
*
|
|
956
1034
|
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} rule
|
|
957
1035
|
*
|
|
958
1036
|
* @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} separator
|
package/package.json
CHANGED
package/queries/highlights.scm
CHANGED
package/src/node-types.json
CHANGED
|
@@ -1307,6 +1307,46 @@
|
|
|
1307
1307
|
}
|
|
1308
1308
|
}
|
|
1309
1309
|
},
|
|
1310
|
+
{
|
|
1311
|
+
"type": "default_type_parameter",
|
|
1312
|
+
"named": true,
|
|
1313
|
+
"fields": {
|
|
1314
|
+
"bound": {
|
|
1315
|
+
"multiple": false,
|
|
1316
|
+
"required": false,
|
|
1317
|
+
"types": [
|
|
1318
|
+
{
|
|
1319
|
+
"type": "type",
|
|
1320
|
+
"named": true
|
|
1321
|
+
}
|
|
1322
|
+
]
|
|
1323
|
+
},
|
|
1324
|
+
"name": {
|
|
1325
|
+
"multiple": false,
|
|
1326
|
+
"required": true,
|
|
1327
|
+
"types": [
|
|
1328
|
+
{
|
|
1329
|
+
"type": "identifier",
|
|
1330
|
+
"named": true
|
|
1331
|
+
}
|
|
1332
|
+
]
|
|
1333
|
+
},
|
|
1334
|
+
"value": {
|
|
1335
|
+
"multiple": false,
|
|
1336
|
+
"required": true,
|
|
1337
|
+
"types": [
|
|
1338
|
+
{
|
|
1339
|
+
"type": "list_splat",
|
|
1340
|
+
"named": true
|
|
1341
|
+
},
|
|
1342
|
+
{
|
|
1343
|
+
"type": "type",
|
|
1344
|
+
"named": true
|
|
1345
|
+
}
|
|
1346
|
+
]
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
},
|
|
1310
1350
|
{
|
|
1311
1351
|
"type": "delete_statement",
|
|
1312
1352
|
"named": true,
|
|
@@ -1994,6 +2034,10 @@
|
|
|
1994
2034
|
"type": "identifier",
|
|
1995
2035
|
"named": true
|
|
1996
2036
|
},
|
|
2037
|
+
{
|
|
2038
|
+
"type": "member_type",
|
|
2039
|
+
"named": true
|
|
2040
|
+
},
|
|
1997
2041
|
{
|
|
1998
2042
|
"type": "type_parameter",
|
|
1999
2043
|
"named": true
|
|
@@ -2370,6 +2414,10 @@
|
|
|
2370
2414
|
{
|
|
2371
2415
|
"type": "list_splat",
|
|
2372
2416
|
"named": true
|
|
2417
|
+
},
|
|
2418
|
+
{
|
|
2419
|
+
"type": "type",
|
|
2420
|
+
"named": true
|
|
2373
2421
|
}
|
|
2374
2422
|
]
|
|
2375
2423
|
}
|
|
@@ -2458,6 +2506,10 @@
|
|
|
2458
2506
|
{
|
|
2459
2507
|
"type": "primary_expression",
|
|
2460
2508
|
"named": true
|
|
2509
|
+
},
|
|
2510
|
+
{
|
|
2511
|
+
"type": "type",
|
|
2512
|
+
"named": true
|
|
2461
2513
|
}
|
|
2462
2514
|
]
|
|
2463
2515
|
}
|
|
@@ -2527,6 +2579,10 @@
|
|
|
2527
2579
|
"type": "identifier",
|
|
2528
2580
|
"named": true
|
|
2529
2581
|
},
|
|
2582
|
+
{
|
|
2583
|
+
"type": "member_type",
|
|
2584
|
+
"named": true
|
|
2585
|
+
},
|
|
2530
2586
|
{
|
|
2531
2587
|
"type": "type",
|
|
2532
2588
|
"named": true
|
|
@@ -2785,6 +2841,10 @@
|
|
|
2785
2841
|
"type": "expression",
|
|
2786
2842
|
"named": true
|
|
2787
2843
|
},
|
|
2844
|
+
{
|
|
2845
|
+
"type": "type",
|
|
2846
|
+
"named": true
|
|
2847
|
+
},
|
|
2788
2848
|
{
|
|
2789
2849
|
"type": "yield",
|
|
2790
2850
|
"named": true
|
|
@@ -3029,6 +3089,10 @@
|
|
|
3029
3089
|
{
|
|
3030
3090
|
"type": "primary_expression",
|
|
3031
3091
|
"named": true
|
|
3092
|
+
},
|
|
3093
|
+
{
|
|
3094
|
+
"type": "type",
|
|
3095
|
+
"named": true
|
|
3032
3096
|
}
|
|
3033
3097
|
]
|
|
3034
3098
|
}
|
|
@@ -3162,6 +3226,10 @@
|
|
|
3162
3226
|
{
|
|
3163
3227
|
"type": "list_splat",
|
|
3164
3228
|
"named": true
|
|
3229
|
+
},
|
|
3230
|
+
{
|
|
3231
|
+
"type": "type",
|
|
3232
|
+
"named": true
|
|
3165
3233
|
}
|
|
3166
3234
|
]
|
|
3167
3235
|
}
|
|
@@ -3205,10 +3273,6 @@
|
|
|
3205
3273
|
"type": "generic_type",
|
|
3206
3274
|
"named": true
|
|
3207
3275
|
},
|
|
3208
|
-
{
|
|
3209
|
-
"type": "identifier",
|
|
3210
|
-
"named": true
|
|
3211
|
-
},
|
|
3212
3276
|
{
|
|
3213
3277
|
"type": "member_type",
|
|
3214
3278
|
"named": true
|
|
@@ -3254,6 +3318,18 @@
|
|
|
3254
3318
|
"multiple": true,
|
|
3255
3319
|
"required": true,
|
|
3256
3320
|
"types": [
|
|
3321
|
+
{
|
|
3322
|
+
"type": "default_type_parameter",
|
|
3323
|
+
"named": true
|
|
3324
|
+
},
|
|
3325
|
+
{
|
|
3326
|
+
"type": "named_expression",
|
|
3327
|
+
"named": true
|
|
3328
|
+
},
|
|
3329
|
+
{
|
|
3330
|
+
"type": "slice",
|
|
3331
|
+
"named": true
|
|
3332
|
+
},
|
|
3257
3333
|
{
|
|
3258
3334
|
"type": "splat_type",
|
|
3259
3335
|
"named": true
|
package/tree-sitter-python.wasm
CHANGED
|
Binary file
|