@willbooster/tree-sitter-python 2.0.2 → 2.1.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/README.md CHANGED
@@ -5,14 +5,15 @@
5
5
  [![Test](https://github.com/WillBooster/tree-sitter-python/actions/workflows/test.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-python/actions/workflows/test.yml)
6
6
  [![Test rust](https://github.com/WillBooster/tree-sitter-python/actions/workflows/test-rust.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-python/actions/workflows/test-rust.yml)
7
7
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
8
- [![wbfy](https://img.shields.io/badge/wbfy-20.36.11-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
8
+ [![wbfy](https://img.shields.io/badge/wbfy-20.41.8-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
9
9
  [![crates.io](https://img.shields.io/crates/v/willbooster-tree-sitter-python.svg)](https://crates.io/crates/willbooster-tree-sitter-python)
10
10
 
11
11
  Python grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
12
12
  [tree-sitter/tree-sitter-python](https://github.com/tree-sitter/tree-sitter-python). We are grateful
13
13
  to its authors and contributors. This is not an official release of that project.
14
14
 
15
- This fork ships the unmodified grammar of upstream v0.25.0 as a compact parser, generated by the parser generator of
15
+ This fork builds on upstream v0.25.0 with grammar, scanner, and highlighting fixes, including Python 3.15
16
+ unpacking comprehensions. It ships a compact parser generated by the parser generator of
16
17
  [WillBooster/tree-sitter](https://github.com/WillBooster/tree-sitter). The parser carries that fork's own ABI number, so
17
18
  it loads only with the WillBooster runtime (`willbooster-tree-sitter` or `@willbooster/web-tree-sitter`) 2.0.0 or later,
18
19
  not with upstream's tree-sitter.
package/grammar.js CHANGED
@@ -6,9 +6,11 @@
6
6
  * @see {@link https://docs.python.org/3/reference/grammar.html|Python 3 grammar}
7
7
  */
8
8
 
9
- /// <reference types="tree-sitter-cli/dsl" />
10
9
  // @ts-check
11
10
 
11
+ const { grammar, seq, choice, repeat, repeat1, optional, token, prec, alias, field, sym } =
12
+ /** @type {typeof globalThis & import('@willbooster/web-tree-sitter/dsl').DSL} */ (globalThis);
13
+
12
14
  const PREC = {
13
15
  // this resolves a conflict between the usage of ':' in a lambda vs in a
14
16
  // typed parameter. In the case of a lambda, we don't allow typed parameters.
@@ -17,7 +19,6 @@ const PREC = {
17
19
  conditional: -1,
18
20
 
19
21
  parenthesized_expression: 1,
20
- parenthesized_list_splat: 1,
21
22
  or: 10,
22
23
  and: 11,
23
24
  not: 12,
@@ -46,10 +47,9 @@ module.exports = grammar({
46
47
  [$.primary_expression, $.list_splat_pattern],
47
48
  [$.tuple, $.tuple_pattern],
48
49
  [$.list, $.list_pattern],
49
- [$.with_item, $._collection_elements],
50
+ [$.with_item, $.tuple],
50
51
  [$.named_expression, $.as_pattern],
51
52
  [$.print_statement, $.primary_expression],
52
- [$.type_alias_statement, $.primary_expression],
53
53
  [$.match_statement, $.primary_expression],
54
54
  ],
55
55
 
@@ -62,21 +62,21 @@ module.exports = grammar({
62
62
  $.parameter,
63
63
  ],
64
64
 
65
- externals: ($) => [
66
- $._newline,
67
- $._indent,
68
- $._dedent,
69
- $.string_start,
70
- $._string_content,
71
- $.escape_interpolation,
72
- $.string_end,
65
+ externals: () => [
66
+ sym('_newline'),
67
+ sym('_indent'),
68
+ sym('_dedent'),
69
+ sym('string_start'),
70
+ sym('_string_content'),
71
+ sym('escape_interpolation'),
72
+ sym('string_end'),
73
73
 
74
74
  // Mark comments as external tokens so that the external scanner is always
75
75
  // invoked, even if no external token is expected. This allows for better
76
76
  // error recovery, because the external scanner can maintain the overall
77
77
  // structure by returning dedent tokens whenever a dedent occurs, even
78
78
  // if no dedent is expected.
79
- $.comment,
79
+ sym('comment'),
80
80
 
81
81
  // Allow the external scanner to check for the validity of closing brackets
82
82
  // so that it can avoid returning dedent tokens between brackets.
@@ -87,6 +87,7 @@ module.exports = grammar({
87
87
  ],
88
88
 
89
89
  inline: ($) => [
90
+ $._expression_without_named_expression,
90
91
  $._simple_statement,
91
92
  $._compound_statement,
92
93
  $._suite,
@@ -145,7 +146,7 @@ module.exports = grammar({
145
146
 
146
147
  // Simple statements
147
148
 
148
- _simple_statements: ($) => seq(sep1($._simple_statement, SEMICOLON), optional(SEMICOLON), $._newline),
149
+ _simple_statements: ($) => seq(sep1($._simple_statement, SEMICOLON), optional(SEMICOLON), sym('_newline')),
149
150
 
150
151
  _simple_statement: ($) =>
151
152
  choice(
@@ -192,8 +193,23 @@ module.exports = grammar({
192
193
 
193
194
  print_statement: ($) =>
194
195
  choice(
195
- prec(1, seq('print', $.chevron, repeat(seq(',', field('argument', $.expression))), optional(','))),
196
- prec(-3, prec.dynamic(-1, seq('print', commaSep1(field('argument', $.expression)), optional(','))))
196
+ // Python 3 reads these statements as expression lists, which can unpack their elements.
197
+ prec(
198
+ 1,
199
+ seq(
200
+ 'print',
201
+ $.chevron,
202
+ repeat(seq(',', field('argument', choice($.expression, $.list_splat)))),
203
+ optional(',')
204
+ )
205
+ ),
206
+ prec(
207
+ -3,
208
+ prec.dynamic(
209
+ -1,
210
+ seq('print', commaSep1(field('argument', choice($.expression, $.list_splat))), optional(','))
211
+ )
212
+ )
197
213
  ),
198
214
 
199
215
  chevron: ($) => seq('>>', $.expression),
@@ -201,7 +217,13 @@ module.exports = grammar({
201
217
  assert_statement: ($) => seq('assert', commaSep1($.expression)),
202
218
 
203
219
  expression_statement: ($) =>
204
- choice($.expression, seq(commaSep1($.expression), optional(',')), $.assignment, $.augmented_assignment, $.yield),
220
+ choice(
221
+ $.expression,
222
+ seq(choice($.expression, $.list_splat), ',', optional($._collection_elements)),
223
+ $.assignment,
224
+ $.augmented_assignment,
225
+ $.yield
226
+ ),
205
227
 
206
228
  named_expression: ($) => seq(field('name', $._named_expression_lhs), ':=', field('value', $.expression)),
207
229
 
@@ -248,16 +270,18 @@ module.exports = grammar({
248
270
 
249
271
  else_clause: ($) => seq('else', ':', field('body', $._suite)),
250
272
 
251
- match_statement: ($) =>
252
- seq(
273
+ match_statement: ($) => {
274
+ const subject = field('subject', choice($.expression, $.list_splat));
275
+ return seq(
253
276
  'match',
254
- commaSep1(field('subject', $.expression)),
255
- optional(','),
277
+ choice(field('subject', $.expression), seq(subject, ',', optional(seq(commaSep1(subject), optional(','))))),
256
278
  ':',
257
279
  field('body', alias($._match_block, $.block))
258
- ),
280
+ );
281
+ },
259
282
 
260
- _match_block: ($) => choice(seq($._indent, repeat(field('alternative', $.case_clause)), $._dedent), $._newline),
283
+ _match_block: ($) =>
284
+ choice(seq(sym('_indent'), repeat(field('alternative', $.case_clause)), sym('_dedent')), sym('_newline')),
261
285
 
262
286
  case_clause: ($) =>
263
287
  seq(
@@ -339,9 +363,9 @@ module.exports = grammar({
339
363
 
340
364
  lambda_parameters: ($) => $._parameters,
341
365
 
342
- list_splat: ($) => seq('*', $.expression),
366
+ list_splat: ($) => seq('*', $.primary_expression),
343
367
 
344
- dictionary_splat: ($) => seq('**', $.expression),
368
+ dictionary_splat: ($) => seq('**', $.primary_expression),
345
369
 
346
370
  global_statement: ($) => seq('global', commaSep1($.identifier)),
347
371
 
@@ -350,7 +374,12 @@ module.exports = grammar({
350
374
  exec_statement: ($) =>
351
375
  seq('exec', field('code', choice($.string, $.identifier)), optional(seq('in', commaSep1($.expression)))),
352
376
 
353
- type_alias_statement: ($) => prec.dynamic(1, seq('type', field('left', $.type), '=', field('right', $.type))),
377
+ type_alias_statement: ($) =>
378
+ seq('type', field('left', alias($._type_alias_name, $.type)), '=', field('right', $.type)),
379
+
380
+ _type_alias_name: ($) => choice($.identifier, alias($._generic_type_definition, $.generic_type)),
381
+
382
+ _generic_type_definition: ($) => seq($.identifier, $.type_parameter),
354
383
 
355
384
  class_definition: ($) =>
356
385
  seq(
@@ -361,13 +390,10 @@ module.exports = grammar({
361
390
  ':',
362
391
  field('body', $._suite)
363
392
  ),
364
- type_parameter: ($) => seq('[', commaSep1($.type), optional(','), ']'),
393
+ type_parameter: ($) => seq('[', commaSep1(choice($.type, $.splat_type)), optional(','), ']'),
365
394
 
366
- parenthesized_list_splat: ($) =>
367
- prec(
368
- PREC.parenthesized_list_splat,
369
- seq('(', choice(alias($.parenthesized_list_splat, $.parenthesized_expression), $.list_splat), ')')
370
- ),
395
+ _generic_type_arguments: ($) =>
396
+ seq('[', commaSep1(choice($.type, alias($._list_splat_argument, $.splat_type))), optional(','), ']'),
371
397
 
372
398
  argument_list: ($) =>
373
399
  seq(
@@ -376,9 +402,8 @@ module.exports = grammar({
376
402
  commaSep1(
377
403
  choice(
378
404
  $.expression,
379
- $.list_splat,
380
- $.dictionary_splat,
381
- alias($.parenthesized_list_splat, $.parenthesized_expression),
405
+ alias($._list_splat_argument, $.list_splat),
406
+ alias($._dictionary_splat_argument, $.dictionary_splat),
382
407
  $.keyword_argument
383
408
  )
384
409
  )
@@ -387,17 +412,22 @@ module.exports = grammar({
387
412
  ')'
388
413
  ),
389
414
 
415
+ _list_splat_argument: ($) => seq('*', $._expression_without_named_expression),
416
+
417
+ _dictionary_splat_argument: ($) => seq('**', $._expression_without_named_expression),
418
+
390
419
  decorated_definition: ($) =>
391
420
  seq(repeat1($.decorator), field('definition', choice($.class_definition, $.function_definition))),
392
421
 
393
- decorator: ($) => seq('@', $.expression, $._newline),
422
+ decorator: ($) => seq('@', $.expression, sym('_newline')),
394
423
 
395
- _suite: ($) => choice(alias($._simple_statements, $.block), seq($._indent, $.block), alias($._newline, $.block)),
424
+ _suite: ($) =>
425
+ choice(alias($._simple_statements, $.block), seq(sym('_indent'), $.block), alias(sym('_newline'), $.block)),
396
426
 
397
- block: ($) => seq(repeat($._statement), $._dedent),
427
+ block: ($) => seq(repeat($._statement), sym('_dedent')),
398
428
 
399
429
  expression_list: ($) =>
400
- prec.right(seq($.expression, choice(',', seq(repeat1(seq(',', $.expression)), optional(','))))),
430
+ prec.dynamic(1, prec.right(seq(choice($.expression, $.list_splat), ',', optional($._collection_elements)))),
401
431
 
402
432
  dotted_name: ($) => prec(1, sep1($.identifier, '.')),
403
433
 
@@ -498,22 +528,23 @@ module.exports = grammar({
498
528
 
499
529
  // Extended patterns (patterns allowed in match statement are far more flexible than simple patterns though still a subset of "expression")
500
530
 
501
- as_pattern: ($) => prec.left(seq($.expression, 'as', field('alias', alias($.expression, $.as_pattern_target)))),
531
+ as_pattern: ($) =>
532
+ prec.left(seq($.expression, 'as', field('alias', alias($.expression, sym('as_pattern_target'))))),
502
533
 
503
534
  // Expressions
504
535
 
505
536
  _expression_within_for_in_clause: ($) => choice($.expression, alias($.lambda_within_for_in_clause, $.lambda)),
506
537
 
507
- expression: ($) =>
538
+ expression: ($) => choice($._expression_without_named_expression, $.named_expression, $.as_pattern),
539
+
540
+ _expression_without_named_expression: ($) =>
508
541
  choice(
509
542
  $.comparison_operator,
510
543
  $.not_operator,
511
544
  $.boolean_operator,
512
545
  $.lambda,
513
546
  $.primary_expression,
514
- $.conditional_expression,
515
- $.named_expression,
516
- $.as_pattern
547
+ $.conditional_expression
517
548
  ),
518
549
 
519
550
  primary_expression: ($) =>
@@ -542,21 +573,33 @@ module.exports = grammar({
542
573
  $.tuple,
543
574
  $.parenthesized_expression,
544
575
  $.generator_expression,
545
- $.ellipsis,
546
- alias($.list_splat_pattern, $.list_splat)
576
+ $.ellipsis
547
577
  ),
548
578
 
549
- not_operator: ($) => prec(PREC.not, seq('not', field('argument', $.expression))),
579
+ not_operator: ($) => prec(PREC.not, seq('not', field('argument', $._expression_without_named_expression))),
550
580
 
551
581
  boolean_operator: ($) =>
552
582
  choice(
553
- prec.left(PREC.and, seq(field('left', $.expression), field('operator', 'and'), field('right', $.expression))),
554
- prec.left(PREC.or, seq(field('left', $.expression), field('operator', 'or'), field('right', $.expression)))
583
+ prec.left(
584
+ PREC.and,
585
+ seq(
586
+ field('left', $._expression_without_named_expression),
587
+ field('operator', 'and'),
588
+ field('right', $._expression_without_named_expression)
589
+ )
590
+ ),
591
+ prec.left(
592
+ PREC.or,
593
+ seq(
594
+ field('left', $._expression_without_named_expression),
595
+ field('operator', 'or'),
596
+ field('right', $._expression_without_named_expression)
597
+ )
598
+ )
555
599
  ),
556
600
 
557
601
  binary_operator: ($) => {
558
- /* oxlint-disable typescript/unbound-method -- prec.left and prec.right do not use `this`. */
559
- /** @type {[typeof prec.left | typeof prec.right, string, number][]} */
602
+ /** @type {[import('@willbooster/web-tree-sitter/dsl').DSL['prec']['left' | 'right'], string, number][]} */
560
603
  const table = [
561
604
  [prec.left, '+', PREC.plus],
562
605
  [prec.left, '-', PREC.plus],
@@ -572,7 +615,6 @@ module.exports = grammar({
572
615
  [prec.left, '<<', PREC.shift],
573
616
  [prec.left, '>>', PREC.shift],
574
617
  ];
575
- /* oxlint-enable typescript/unbound-method */
576
618
 
577
619
  return choice(
578
620
  ...table.map(([fn, operator, precedence]) =>
@@ -623,7 +665,12 @@ module.exports = grammar({
623
665
  lambda: ($) =>
624
666
  prec(
625
667
  PREC.lambda,
626
- seq('lambda', field('parameters', optional($.lambda_parameters)), ':', field('body', $.expression))
668
+ seq(
669
+ 'lambda',
670
+ field('parameters', optional($.lambda_parameters)),
671
+ ':',
672
+ field('body', $._expression_without_named_expression)
673
+ )
627
674
  ),
628
675
 
629
676
  lambda_within_for_in_clause: ($) =>
@@ -655,8 +702,7 @@ module.exports = grammar({
655
702
 
656
703
  pattern_list: ($) => seq($.pattern, choice(',', seq(repeat1(seq(',', $.pattern)), optional(',')))),
657
704
 
658
- _right_hand_side: ($) =>
659
- choice($.expression, $.expression_list, $.assignment, $.augmented_assignment, $.pattern_list, $.yield),
705
+ _right_hand_side: ($) => choice($.expression, $.expression_list, $.assignment, $.augmented_assignment, $.yield),
660
706
 
661
707
  yield: ($) => prec.right(seq('yield', choice(seq('from', $.expression), optional($._expressions)))),
662
708
 
@@ -669,7 +715,7 @@ module.exports = grammar({
669
715
  seq(
670
716
  field('value', $.primary_expression),
671
717
  '[',
672
- commaSep1(field('subscript', choice($.expression, $.slice))),
718
+ commaSep1(field('subscript', choice($.expression, alias($._list_splat_argument, $.list_splat), $.slice))),
673
719
  optional(','),
674
720
  ']'
675
721
  )
@@ -691,13 +737,19 @@ module.exports = grammar({
691
737
  typed_parameter: ($) =>
692
738
  prec(
693
739
  PREC.typed_parameter,
694
- seq(choice($.identifier, $.list_splat_pattern, $.dictionary_splat_pattern), ':', field('type', $.type))
740
+ choice(
741
+ seq(choice($.identifier, $.dictionary_splat_pattern), ':', field('type', $.type)),
742
+ seq($.list_splat_pattern, ':', field('type', choice($.type, alias($.list_splat, $.splat_type))))
743
+ )
695
744
  ),
696
745
 
697
- type: ($) =>
698
- choice(prec(1, $.expression), $.splat_type, $.generic_type, $.union_type, $.constrained_type, $.member_type),
746
+ type: ($) => choice(prec(1, $.expression), $.generic_type, $.union_type, $.constrained_type, $.member_type),
699
747
  splat_type: ($) => prec(1, seq(choice('*', '**'), $.identifier)),
700
- generic_type: ($) => prec(1, seq(choice($.identifier, alias('type', $.identifier)), $.type_parameter)),
748
+ generic_type: ($) =>
749
+ prec(
750
+ 1,
751
+ seq(choice($.identifier, alias('type', $.identifier)), alias($._generic_type_arguments, $.type_parameter))
752
+ ),
701
753
  union_type: ($) => prec.left(seq($.type, '|', $.type)),
702
754
  constrained_type: ($) => prec.right(seq($.type, ':', $.type)),
703
755
  member_type: ($) => seq($.type, '.', $.identifier),
@@ -711,26 +763,40 @@ module.exports = grammar({
711
763
 
712
764
  set: ($) => seq('{', $._collection_elements, '}'),
713
765
 
714
- tuple: ($) => seq('(', optional($._collection_elements), ')'),
766
+ tuple: ($) =>
767
+ seq('(', optional(seq(choice($.expression, $.list_splat), ',', optional($._collection_elements))), ')'),
715
768
 
716
769
  dictionary: ($) => seq('{', optional(commaSep1(choice($.pair, $.dictionary_splat))), optional(','), '}'),
717
770
 
718
771
  pair: ($) => seq(field('key', $.expression), ':', field('value', $.expression)),
719
772
 
720
- list_comprehension: ($) => seq('[', field('body', $.expression), $._comprehension_clauses, ']'),
773
+ list_comprehension: ($) =>
774
+ seq('[', field('body', choice($.expression, $.list_splat)), $._comprehension_clauses, ']'),
721
775
 
722
- dictionary_comprehension: ($) => seq('{', field('body', $.pair), $._comprehension_clauses, '}'),
776
+ dictionary_comprehension: ($) =>
777
+ seq(
778
+ '{',
779
+ field('body', choice($.pair, alias($._dictionary_splat_argument, $.dictionary_splat))),
780
+ $._comprehension_clauses,
781
+ '}'
782
+ ),
723
783
 
724
- set_comprehension: ($) => seq('{', field('body', $.expression), $._comprehension_clauses, '}'),
784
+ set_comprehension: ($) =>
785
+ seq('{', field('body', choice($.expression, $.list_splat)), $._comprehension_clauses, '}'),
725
786
 
726
- generator_expression: ($) => seq('(', field('body', $.expression), $._comprehension_clauses, ')'),
787
+ generator_expression: ($) =>
788
+ seq(
789
+ '(',
790
+ field('body', choice($.expression, alias($._list_splat_argument, $.list_splat))),
791
+ $._comprehension_clauses,
792
+ ')'
793
+ ),
727
794
 
728
795
  _comprehension_clauses: ($) => seq($.for_in_clause, repeat(choice($.for_in_clause, $.if_clause))),
729
796
 
730
797
  parenthesized_expression: ($) => prec(PREC.parenthesized_expression, seq('(', choice($.expression, $.yield), ')')),
731
798
 
732
- _collection_elements: ($) =>
733
- seq(commaSep1(choice($.expression, $.yield, $.list_splat, $.parenthesized_list_splat)), optional(',')),
799
+ _collection_elements: ($) => seq(commaSep1(choice($.expression, $.list_splat)), optional(',')),
734
800
 
735
801
  for_in_clause: ($) =>
736
802
  prec.left(
@@ -747,14 +813,25 @@ module.exports = grammar({
747
813
  if_clause: ($) => seq('if', $.expression),
748
814
 
749
815
  conditional_expression: ($) =>
750
- prec.right(PREC.conditional, seq($.expression, 'if', $.expression, 'else', $.expression)),
816
+ prec.right(
817
+ PREC.conditional,
818
+ seq(
819
+ $._expression_without_named_expression,
820
+ 'if',
821
+ $._expression_without_named_expression,
822
+ 'else',
823
+ $._expression_without_named_expression
824
+ )
825
+ ),
751
826
 
752
827
  concatenated_string: ($) => seq($.string, repeat1($.string)),
753
828
 
754
- string: ($) => seq($.string_start, repeat(choice($.interpolation, $.string_content)), $.string_end),
829
+ string: ($) => seq(sym('string_start'), repeat(choice($.interpolation, $.string_content)), sym('string_end')),
755
830
 
756
831
  string_content: ($) =>
757
- prec.right(repeat1(choice($.escape_interpolation, $.escape_sequence, $._not_escape_sequence, $._string_content))),
832
+ prec.right(
833
+ repeat1(choice(sym('escape_interpolation'), $.escape_sequence, $._not_escape_sequence, sym('_string_content')))
834
+ ),
758
835
 
759
836
  interpolation: ($) =>
760
837
  seq(
@@ -766,7 +843,7 @@ module.exports = grammar({
766
843
  '}'
767
844
  ),
768
845
 
769
- _f_expression: ($) => choice($.expression, $.expression_list, $.pattern_list, $.yield),
846
+ _f_expression: ($) => choice($.expression, $.expression_list, $.yield),
770
847
 
771
848
  escape_sequence: () =>
772
849
  token.immediate(
@@ -790,7 +867,7 @@ module.exports = grammar({
790
867
  _not_escape_sequence: () => token.immediate('\\'),
791
868
 
792
869
  format_specifier: ($) =>
793
- seq(':', repeat(choice(token(prec(1, /[^{}\n]+/)), alias($.interpolation, $.format_expression)))),
870
+ seq(':', repeat(choice(token(prec(1, /[^{}\n]+/)), alias($.interpolation, sym('format_expression'))))),
794
871
 
795
872
  type_conversion: () => /![a-z]/,
796
873
 
@@ -859,9 +936,9 @@ Object.assign(module.exports, { PREC });
859
936
  /**
860
937
  * Creates a rule to match one or more of the rules separated by a comma
861
938
  *
862
- * @param {RuleOrLiteral} rule
939
+ * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} rule
863
940
  *
864
- * @returns {SeqRule}
941
+ * @returns {import('@willbooster/web-tree-sitter/dsl').SeqRule}
865
942
  */
866
943
  function commaSep1(rule) {
867
944
  return sep1(rule, ',');
@@ -870,11 +947,11 @@ function commaSep1(rule) {
870
947
  /**
871
948
  * Creates a rule to match one or more occurrences of `rule` separated by `sep`
872
949
  *
873
- * @param {RuleOrLiteral} rule
950
+ * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} rule
874
951
  *
875
- * @param {RuleOrLiteral} separator
952
+ * @param {import('@willbooster/web-tree-sitter/dsl').RuleOrLiteral} separator
876
953
  *
877
- * @returns {SeqRule}
954
+ * @returns {import('@willbooster/web-tree-sitter/dsl').SeqRule}
878
955
  */
879
956
  function sep1(rule, separator) {
880
957
  return seq(rule, repeat(seq(separator, rule)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-python",
3
- "version": "2.0.2",
3
+ "version": "2.1.1",
4
4
  "description": "Python grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -46,21 +46,19 @@
46
46
  "@vitest/browser-playwright": "5.0.3",
47
47
  "@willbooster/oxfmt-config": "1.2.2",
48
48
  "@willbooster/oxlint-config": "1.4.8",
49
- "@willbooster/wb": "22.24.0",
50
- "@willbooster/web-tree-sitter": "2.0.1",
51
- "conventional-changelog-conventionalcommits": "10.4.0",
52
- "lefthook": "2.1.16",
53
- "oxfmt": "0.71.0",
54
- "oxlint": "1.86.0",
55
- "oxlint-tsgolint": "7.0.2003",
56
- "playwright": "1.63.0",
49
+ "@willbooster/wb": "22.26.1",
50
+ "@willbooster/web-tree-sitter": "2.0.27",
51
+ "conventional-changelog-conventionalcommits": "10.4.1",
52
+ "lefthook": "2.2.1",
53
+ "oxfmt": "0.72.0",
54
+ "oxlint": "1.87.0",
55
+ "oxlint-tsgolint": "7.0.2004",
56
+ "playwright": "1.64.0",
57
57
  "semantic-release": "25.0.9",
58
58
  "sort-package-json": "4.0.0",
59
- "tree-sitter-cli": "0.27.0",
60
- "typescript": "7.0.2",
61
- "vite": "8.3.2",
59
+ "vite": "8.3.4",
62
60
  "vitest": "5.0.3",
63
- "wrangler": "4.147.0"
61
+ "wrangler": "4.149.0"
64
62
  },
65
63
  "peerDependencies": {
66
64
  "@willbooster/web-tree-sitter": "^2.0.0"
@@ -173,10 +173,6 @@
173
173
  "type": "list_comprehension",
174
174
  "named": true
175
175
  },
176
- {
177
- "type": "list_splat",
178
- "named": true
179
- },
180
176
  {
181
177
  "type": "none",
182
178
  "named": true
@@ -264,10 +260,6 @@
264
260
  {
265
261
  "type": "list_splat",
266
262
  "named": true
267
- },
268
- {
269
- "type": "parenthesized_expression",
270
- "named": true
271
263
  }
272
264
  ]
273
265
  }
@@ -402,10 +394,6 @@
402
394
  "type": "expression_list",
403
395
  "named": true
404
396
  },
405
- {
406
- "type": "pattern_list",
407
- "named": true
408
- },
409
397
  {
410
398
  "type": "yield",
411
399
  "named": true
@@ -546,10 +534,6 @@
546
534
  "type": "expression_list",
547
535
  "named": true
548
536
  },
549
- {
550
- "type": "pattern_list",
551
- "named": true
552
- },
553
537
  {
554
538
  "type": "yield",
555
539
  "named": true
@@ -788,7 +772,27 @@
788
772
  "required": true,
789
773
  "types": [
790
774
  {
791
- "type": "expression",
775
+ "type": "boolean_operator",
776
+ "named": true
777
+ },
778
+ {
779
+ "type": "comparison_operator",
780
+ "named": true
781
+ },
782
+ {
783
+ "type": "conditional_expression",
784
+ "named": true
785
+ },
786
+ {
787
+ "type": "lambda",
788
+ "named": true
789
+ },
790
+ {
791
+ "type": "not_operator",
792
+ "named": true
793
+ },
794
+ {
795
+ "type": "primary_expression",
792
796
  "named": true
793
797
  }
794
798
  ]
@@ -812,7 +816,27 @@
812
816
  "required": true,
813
817
  "types": [
814
818
  {
815
- "type": "expression",
819
+ "type": "boolean_operator",
820
+ "named": true
821
+ },
822
+ {
823
+ "type": "comparison_operator",
824
+ "named": true
825
+ },
826
+ {
827
+ "type": "conditional_expression",
828
+ "named": true
829
+ },
830
+ {
831
+ "type": "lambda",
832
+ "named": true
833
+ },
834
+ {
835
+ "type": "not_operator",
836
+ "named": true
837
+ },
838
+ {
839
+ "type": "primary_expression",
816
840
  "named": true
817
841
  }
818
842
  ]
@@ -1158,7 +1182,27 @@
1158
1182
  "required": true,
1159
1183
  "types": [
1160
1184
  {
1161
- "type": "expression",
1185
+ "type": "boolean_operator",
1186
+ "named": true
1187
+ },
1188
+ {
1189
+ "type": "comparison_operator",
1190
+ "named": true
1191
+ },
1192
+ {
1193
+ "type": "conditional_expression",
1194
+ "named": true
1195
+ },
1196
+ {
1197
+ "type": "lambda",
1198
+ "named": true
1199
+ },
1200
+ {
1201
+ "type": "not_operator",
1202
+ "named": true
1203
+ },
1204
+ {
1205
+ "type": "primary_expression",
1162
1206
  "named": true
1163
1207
  }
1164
1208
  ]
@@ -1405,6 +1449,10 @@
1405
1449
  "multiple": false,
1406
1450
  "required": true,
1407
1451
  "types": [
1452
+ {
1453
+ "type": "dictionary_splat",
1454
+ "named": true
1455
+ },
1408
1456
  {
1409
1457
  "type": "pair",
1410
1458
  "named": true
@@ -1436,7 +1484,27 @@
1436
1484
  "required": true,
1437
1485
  "types": [
1438
1486
  {
1439
- "type": "expression",
1487
+ "type": "boolean_operator",
1488
+ "named": true
1489
+ },
1490
+ {
1491
+ "type": "comparison_operator",
1492
+ "named": true
1493
+ },
1494
+ {
1495
+ "type": "conditional_expression",
1496
+ "named": true
1497
+ },
1498
+ {
1499
+ "type": "lambda",
1500
+ "named": true
1501
+ },
1502
+ {
1503
+ "type": "not_operator",
1504
+ "named": true
1505
+ },
1506
+ {
1507
+ "type": "primary_expression",
1440
1508
  "named": true
1441
1509
  }
1442
1510
  ]
@@ -1599,6 +1667,10 @@
1599
1667
  {
1600
1668
  "type": "expression",
1601
1669
  "named": true
1670
+ },
1671
+ {
1672
+ "type": "list_splat",
1673
+ "named": true
1602
1674
  }
1603
1675
  ]
1604
1676
  }
@@ -1623,6 +1695,10 @@
1623
1695
  "type": "expression",
1624
1696
  "named": true
1625
1697
  },
1698
+ {
1699
+ "type": "list_splat",
1700
+ "named": true
1701
+ },
1626
1702
  {
1627
1703
  "type": "yield",
1628
1704
  "named": true
@@ -1749,10 +1825,6 @@
1749
1825
  "type": "expression_list",
1750
1826
  "named": true
1751
1827
  },
1752
- {
1753
- "type": "pattern_list",
1754
- "named": true
1755
- },
1756
1828
  {
1757
1829
  "type": "yield",
1758
1830
  "named": true
@@ -1883,6 +1955,10 @@
1883
1955
  {
1884
1956
  "type": "expression",
1885
1957
  "named": true
1958
+ },
1959
+ {
1960
+ "type": "list_splat",
1961
+ "named": true
1886
1962
  }
1887
1963
  ]
1888
1964
  }
@@ -2076,10 +2152,6 @@
2076
2152
  "type": "expression_list",
2077
2153
  "named": true
2078
2154
  },
2079
- {
2080
- "type": "pattern_list",
2081
- "named": true
2082
- },
2083
2155
  {
2084
2156
  "type": "yield",
2085
2157
  "named": true
@@ -2275,14 +2347,6 @@
2275
2347
  {
2276
2348
  "type": "list_splat",
2277
2349
  "named": true
2278
- },
2279
- {
2280
- "type": "parenthesized_list_splat",
2281
- "named": true
2282
- },
2283
- {
2284
- "type": "yield",
2285
- "named": true
2286
2350
  }
2287
2351
  ]
2288
2352
  }
@@ -2298,6 +2362,10 @@
2298
2362
  {
2299
2363
  "type": "expression",
2300
2364
  "named": true
2365
+ },
2366
+ {
2367
+ "type": "list_splat",
2368
+ "named": true
2301
2369
  }
2302
2370
  ]
2303
2371
  }
@@ -2345,19 +2413,27 @@
2345
2413
  "required": true,
2346
2414
  "types": [
2347
2415
  {
2348
- "type": "attribute",
2416
+ "type": "boolean_operator",
2349
2417
  "named": true
2350
2418
  },
2351
2419
  {
2352
- "type": "expression",
2420
+ "type": "comparison_operator",
2353
2421
  "named": true
2354
2422
  },
2355
2423
  {
2356
- "type": "identifier",
2424
+ "type": "conditional_expression",
2357
2425
  "named": true
2358
2426
  },
2359
2427
  {
2360
- "type": "subscript",
2428
+ "type": "lambda",
2429
+ "named": true
2430
+ },
2431
+ {
2432
+ "type": "not_operator",
2433
+ "named": true
2434
+ },
2435
+ {
2436
+ "type": "primary_expression",
2361
2437
  "named": true
2362
2438
  }
2363
2439
  ]
@@ -2407,6 +2483,10 @@
2407
2483
  {
2408
2484
  "type": "expression",
2409
2485
  "named": true
2486
+ },
2487
+ {
2488
+ "type": "list_splat",
2489
+ "named": true
2410
2490
  }
2411
2491
  ]
2412
2492
  }
@@ -2598,7 +2678,27 @@
2598
2678
  "required": true,
2599
2679
  "types": [
2600
2680
  {
2601
- "type": "expression",
2681
+ "type": "boolean_operator",
2682
+ "named": true
2683
+ },
2684
+ {
2685
+ "type": "comparison_operator",
2686
+ "named": true
2687
+ },
2688
+ {
2689
+ "type": "conditional_expression",
2690
+ "named": true
2691
+ },
2692
+ {
2693
+ "type": "lambda",
2694
+ "named": true
2695
+ },
2696
+ {
2697
+ "type": "not_operator",
2698
+ "named": true
2699
+ },
2700
+ {
2701
+ "type": "primary_expression",
2602
2702
  "named": true
2603
2703
  }
2604
2704
  ]
@@ -2658,14 +2758,6 @@
2658
2758
  "type": "expression",
2659
2759
  "named": true
2660
2760
  },
2661
- {
2662
- "type": "list_splat",
2663
- "named": true
2664
- },
2665
- {
2666
- "type": "parenthesized_expression",
2667
- "named": true
2668
- },
2669
2761
  {
2670
2762
  "type": "yield",
2671
2763
  "named": true
@@ -2673,25 +2765,6 @@
2673
2765
  ]
2674
2766
  }
2675
2767
  },
2676
- {
2677
- "type": "parenthesized_list_splat",
2678
- "named": true,
2679
- "fields": {},
2680
- "children": {
2681
- "multiple": false,
2682
- "required": true,
2683
- "types": [
2684
- {
2685
- "type": "list_splat",
2686
- "named": true
2687
- },
2688
- {
2689
- "type": "parenthesized_expression",
2690
- "named": true
2691
- }
2692
- ]
2693
- }
2694
- },
2695
2768
  {
2696
2769
  "type": "pass_statement",
2697
2770
  "named": true,
@@ -2728,6 +2801,10 @@
2728
2801
  {
2729
2802
  "type": "expression",
2730
2803
  "named": true
2804
+ },
2805
+ {
2806
+ "type": "list_splat",
2807
+ "named": true
2731
2808
  }
2732
2809
  ]
2733
2810
  }
@@ -2826,14 +2903,6 @@
2826
2903
  {
2827
2904
  "type": "list_splat",
2828
2905
  "named": true
2829
- },
2830
- {
2831
- "type": "parenthesized_list_splat",
2832
- "named": true
2833
- },
2834
- {
2835
- "type": "yield",
2836
- "named": true
2837
2906
  }
2838
2907
  ]
2839
2908
  }
@@ -2849,6 +2918,10 @@
2849
2918
  {
2850
2919
  "type": "expression",
2851
2920
  "named": true
2921
+ },
2922
+ {
2923
+ "type": "list_splat",
2924
+ "named": true
2852
2925
  }
2853
2926
  ]
2854
2927
  }
@@ -2907,7 +2980,27 @@
2907
2980
  "required": true,
2908
2981
  "types": [
2909
2982
  {
2910
- "type": "identifier",
2983
+ "type": "boolean_operator",
2984
+ "named": true
2985
+ },
2986
+ {
2987
+ "type": "comparison_operator",
2988
+ "named": true
2989
+ },
2990
+ {
2991
+ "type": "conditional_expression",
2992
+ "named": true
2993
+ },
2994
+ {
2995
+ "type": "lambda",
2996
+ "named": true
2997
+ },
2998
+ {
2999
+ "type": "not_operator",
3000
+ "named": true
3001
+ },
3002
+ {
3003
+ "type": "primary_expression",
2911
3004
  "named": true
2912
3005
  }
2913
3006
  ]
@@ -2971,6 +3064,10 @@
2971
3064
  "type": "expression",
2972
3065
  "named": true
2973
3066
  },
3067
+ {
3068
+ "type": "list_splat",
3069
+ "named": true
3070
+ },
2974
3071
  {
2975
3072
  "type": "slice",
2976
3073
  "named": true
@@ -3038,14 +3135,6 @@
3038
3135
  {
3039
3136
  "type": "list_splat",
3040
3137
  "named": true
3041
- },
3042
- {
3043
- "type": "parenthesized_list_splat",
3044
- "named": true
3045
- },
3046
- {
3047
- "type": "yield",
3048
- "named": true
3049
3138
  }
3050
3139
  ]
3051
3140
  }
@@ -3090,11 +3179,11 @@
3090
3179
  "named": true
3091
3180
  },
3092
3181
  {
3093
- "type": "member_type",
3182
+ "type": "identifier",
3094
3183
  "named": true
3095
3184
  },
3096
3185
  {
3097
- "type": "splat_type",
3186
+ "type": "member_type",
3098
3187
  "named": true
3099
3188
  },
3100
3189
  {
@@ -3138,6 +3227,10 @@
3138
3227
  "multiple": true,
3139
3228
  "required": true,
3140
3229
  "types": [
3230
+ {
3231
+ "type": "splat_type",
3232
+ "named": true
3233
+ },
3141
3234
  {
3142
3235
  "type": "type",
3143
3236
  "named": true
@@ -3189,6 +3282,10 @@
3189
3282
  "multiple": false,
3190
3283
  "required": true,
3191
3284
  "types": [
3285
+ {
3286
+ "type": "splat_type",
3287
+ "named": true
3288
+ },
3192
3289
  {
3193
3290
  "type": "type",
3194
3291
  "named": true
Binary file
package/tree-sitter.json CHANGED
@@ -19,7 +19,7 @@
19
19
  }
20
20
  ],
21
21
  "metadata": {
22
- "version": "2.0.2",
22
+ "version": "2.1.1",
23
23
  "license": "MIT",
24
24
  "description": "Python grammar for tree-sitter",
25
25
  "authors": [