@willbooster/tree-sitter-python 6.0.1 → 8.0.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.
package/grammar.js CHANGED
@@ -43,26 +43,19 @@ 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],
46
+ [$.default_type_parameter, $._default_type_primary, $.primary_expression],
47
47
  [$.primary_expression, $._default_type_primary],
48
48
  [$.primary_expression, $._default_generic_type],
49
- [$._default_generic_type, $.primary_expression, $.generic_type],
50
- [$._default_type_arguments, $.expression],
51
- [$._default_type_arguments, $._generic_type_arguments],
52
49
  [$.primary_expression, $._default_member_type],
53
50
  [$.list, $._default_type_list],
54
51
  [$._type_parameter_expression, $.expression],
55
- [$.list_splat, $._type_parameter_expression],
56
52
  [$.primary_expression, $.pattern],
57
53
  [$.primary_expression, $.list_splat_pattern],
58
54
  [$.tuple, $.tuple_pattern],
59
55
  [$.list, $.list_pattern],
60
56
  [$.with_item, $.tuple],
61
- [$.named_expression, $.as_pattern],
62
57
  [$.print_statement, $.primary_expression],
63
- [$.print_statement, $.primary_expression, $.generic_type],
64
58
  [$.match_statement, $.primary_expression],
65
- [$.primary_expression, $.generic_type],
66
59
  ],
67
60
 
68
61
  supertypes: ($) => [
@@ -345,7 +338,10 @@ module.exports = grammar({
345
338
  optional(token(prec(1, '*'))),
346
339
  optional(
347
340
  choice(
348
- seq(field('value', $.expression), optional(seq('as', field('alias', $.expression)))),
341
+ seq(
342
+ field('value', $.expression),
343
+ optional(seq('as', field('alias', choice($.identifier, $.keyword_identifier))))
344
+ ),
349
345
  commaSep1(field('value', $.expression))
350
346
  )
351
347
  ),
@@ -360,7 +356,7 @@ module.exports = grammar({
360
356
  with_clause: ($) =>
361
357
  choice(seq(commaSep1($.with_item), optional(',')), seq('(', commaSep1($.with_item), optional(','), ')')),
362
358
 
363
- with_item: ($) => prec.dynamic(1, seq(field('value', $.expression))),
359
+ with_item: ($) => prec.dynamic(1, field('value', choice($.expression, $.as_pattern))),
364
360
 
365
361
  function_definition: ($) =>
366
362
  seq(
@@ -392,7 +388,7 @@ module.exports = grammar({
392
388
  type_alias_statement: ($) =>
393
389
  seq('type', field('left', alias($._type_alias_name, $.type)), '=', field('right', $.type)),
394
390
 
395
- _type_alias_name: ($) => choice($.identifier, alias($._generic_type_definition, $.generic_type)),
391
+ _type_alias_name: ($) => choice($.identifier, alias($._generic_type_definition, sym('generic_type'))),
396
392
 
397
393
  _generic_type_definition: ($) => seq($.identifier, $.type_parameter),
398
394
 
@@ -406,7 +402,14 @@ module.exports = grammar({
406
402
  field('body', $._suite)
407
403
  ),
408
404
  type_parameter: ($) =>
409
- seq('[', commaSep1(choice($.type, $.splat_type, $.default_type_parameter)), optional(','), ']'),
405
+ seq(
406
+ '[',
407
+ commaSep1(
408
+ choice($.type, alias($._constrained_type_expression, $.type), $.splat_type, $.default_type_parameter)
409
+ ),
410
+ optional(','),
411
+ ']'
412
+ ),
410
413
 
411
414
  default_type_parameter: ($) =>
412
415
  choice(
@@ -439,11 +442,16 @@ module.exports = grammar({
439
442
  prec(-3, alias(choice('print', 'exec'), $.identifier))
440
443
  ),
441
444
 
442
- _default_member_base: ($) => choice($._type_parameter_name, alias($._default_member_type, $.member_type)),
445
+ _default_member_base: ($) =>
446
+ choice(
447
+ $._type_parameter_name,
448
+ alias($._default_member_type, sym('member_type')),
449
+ alias($._default_generic_type, sym('generic_type'))
450
+ ),
443
451
 
444
452
  _type_parameter_expression: ($) => choice($._expression_without_named_expression, prec.dynamic(1, $._default_type)),
445
453
 
446
- _default_type: ($) => choice($._default_type_primary, alias($._default_union_type, $.union_type)),
454
+ _default_type: ($) => choice($._default_type_primary, alias($._default_union_type, sym('union_type'))),
447
455
 
448
456
  _default_type_primary: ($) =>
449
457
  choice(
@@ -451,8 +459,8 @@ module.exports = grammar({
451
459
  $.keyword_identifier,
452
460
  $.none,
453
461
  $.string,
454
- alias($._default_member_type, $.member_type),
455
- alias($._default_generic_type, $.generic_type),
462
+ alias($._default_member_type, sym('member_type')),
463
+ alias($._default_generic_type, sym('generic_type')),
456
464
  alias($._default_type_list, $.list),
457
465
  alias($._default_type_tuple, $.tuple),
458
466
  alias($._default_parenthesized_type, $.parenthesized_expression)
@@ -473,6 +481,7 @@ module.exports = grammar({
473
481
  commaSep1(
474
482
  choice(
475
483
  alias($._type_parameter_expression, $.type),
484
+ alias($._constrained_type_expression, $.type),
476
485
  $.named_expression,
477
486
  alias($._default_splat_argument, $.splat_type),
478
487
  $.slice
@@ -504,16 +513,6 @@ module.exports = grammar({
504
513
 
505
514
  _default_splat_type: ($) => seq('*', choice($.primary_expression, prec.dynamic(1, alias($._default_type, $.type)))),
506
515
 
507
- _generic_type_arguments: ($) =>
508
- seq(
509
- '[',
510
- commaSep1(
511
- choice($.type, alias($._type_parameter_expression, $.type), alias($._default_splat_argument, $.splat_type))
512
- ),
513
- optional(','),
514
- ']'
515
- ),
516
-
517
516
  argument_list: ($) =>
518
517
  seq(
519
518
  '(',
@@ -646,7 +645,7 @@ module.exports = grammar({
646
645
 
647
646
  _expression_within_for_in_clause: ($) => choice($.expression, alias($.lambda_within_for_in_clause, $.lambda)),
648
647
 
649
- expression: ($) => choice($._expression_without_named_expression, $.named_expression, $.as_pattern),
648
+ expression: ($) => choice($._expression_without_named_expression, $.named_expression),
650
649
 
651
650
  _expression_without_named_expression: ($) =>
652
651
  choice(
@@ -858,13 +857,10 @@ module.exports = grammar({
858
857
  )
859
858
  ),
860
859
 
861
- type: ($) => choice(prec(1, $.expression), $.generic_type, $.union_type, $.constrained_type, $.member_type),
860
+ type: ($) => $._type_parameter_expression,
862
861
  splat_type: ($) => prec(1, seq(choice('*', '**'), $.identifier)),
863
- generic_type: ($) =>
864
- prec.dynamic(1, seq($._default_member_base, alias($._generic_type_arguments, $.type_parameter))),
865
- union_type: ($) => prec.left(seq($.type, '|', $.type)),
862
+ _constrained_type_expression: ($) => $.constrained_type,
866
863
  constrained_type: ($) => prec.right(seq($.type, ':', $.type)),
867
- member_type: ($) => seq($.type, '.', $.identifier),
868
864
 
869
865
  keyword_argument: ($) =>
870
866
  seq(field('name', choice($.identifier, $.keyword_identifier)), '=', field('value', $.expression)),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-python",
3
- "version": "6.0.1",
3
+ "version": "8.0.0",
4
4
  "description": "Python grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -50,11 +50,6 @@
50
50
  (identifier) @constructor
51
51
  (tuple (identifier) @constructor)
52
52
  (parenthesized_expression (identifier) @constructor)
53
- (as_pattern [
54
- (identifier) @constructor
55
- (tuple (identifier) @constructor)
56
- (parenthesized_expression (identifier) @constructor)
57
- ])
58
53
  ])
59
54
  (#match? @constructor "^[0-9_]*[A-Z][A-Z_0-9]*$"))
60
55
 
@@ -3,10 +3,6 @@
3
3
  "type": "expression",
4
4
  "named": true,
5
5
  "subtypes": [
6
- {
7
- "type": "as_pattern",
8
- "named": true
9
- },
10
6
  {
11
7
  "type": "boolean_operator",
12
8
  "named": true
@@ -306,10 +302,6 @@
306
302
  "multiple": false,
307
303
  "required": true,
308
304
  "types": [
309
- {
310
- "type": "as_pattern",
311
- "named": true
312
- },
313
305
  {
314
306
  "type": "boolean_operator",
315
307
  "named": true
@@ -1643,7 +1635,7 @@
1643
1635
  "required": false,
1644
1636
  "types": [
1645
1637
  {
1646
- "type": "expression",
1638
+ "type": "identifier",
1647
1639
  "named": true
1648
1640
  }
1649
1641
  ]
@@ -2030,6 +2022,10 @@
2030
2022
  "multiple": true,
2031
2023
  "required": true,
2032
2024
  "types": [
2025
+ {
2026
+ "type": "generic_type",
2027
+ "named": true
2028
+ },
2033
2029
  {
2034
2030
  "type": "identifier",
2035
2031
  "named": true
@@ -2576,15 +2572,15 @@
2576
2572
  "required": true,
2577
2573
  "types": [
2578
2574
  {
2579
- "type": "identifier",
2575
+ "type": "generic_type",
2580
2576
  "named": true
2581
2577
  },
2582
2578
  {
2583
- "type": "member_type",
2579
+ "type": "identifier",
2584
2580
  "named": true
2585
2581
  },
2586
2582
  {
2587
- "type": "type",
2583
+ "type": "member_type",
2588
2584
  "named": true
2589
2585
  }
2590
2586
  ]
@@ -3242,21 +3238,41 @@
3242
3238
  "required": true,
3243
3239
  "types": [
3244
3240
  {
3245
- "type": "constrained_type",
3241
+ "type": "boolean_operator",
3246
3242
  "named": true
3247
3243
  },
3248
3244
  {
3249
- "type": "expression",
3245
+ "type": "comparison_operator",
3246
+ "named": true
3247
+ },
3248
+ {
3249
+ "type": "conditional_expression",
3250
+ "named": true
3251
+ },
3252
+ {
3253
+ "type": "constrained_type",
3250
3254
  "named": true
3251
3255
  },
3252
3256
  {
3253
3257
  "type": "generic_type",
3254
3258
  "named": true
3255
3259
  },
3260
+ {
3261
+ "type": "lambda",
3262
+ "named": true
3263
+ },
3256
3264
  {
3257
3265
  "type": "member_type",
3258
3266
  "named": true
3259
3267
  },
3268
+ {
3269
+ "type": "not_operator",
3270
+ "named": true
3271
+ },
3272
+ {
3273
+ "type": "primary_expression",
3274
+ "named": true
3275
+ },
3260
3276
  {
3261
3277
  "type": "union_type",
3262
3278
  "named": true
@@ -3579,6 +3595,10 @@
3579
3595
  "multiple": false,
3580
3596
  "required": true,
3581
3597
  "types": [
3598
+ {
3599
+ "type": "as_pattern",
3600
+ "named": true
3601
+ },
3582
3602
  {
3583
3603
  "type": "expression",
3584
3604
  "named": true
Binary file
package/tree-sitter.json CHANGED
@@ -19,7 +19,7 @@
19
19
  }
20
20
  ],
21
21
  "metadata": {
22
- "version": "6.0.1",
22
+ "version": "8.0.0",
23
23
  "license": "MIT",
24
24
  "description": "Python grammar for tree-sitter",
25
25
  "authors": [