@willbooster/tree-sitter-python 2.3.2 → 4.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/README.md CHANGED
@@ -15,14 +15,14 @@ to its authors and contributors. This is not an official release of that project
15
15
  This fork builds on upstream v0.25.0 with grammar, scanner, and highlighting fixes, including Python 3.15
16
16
  unpacking comprehensions. It ships a compact parser generated by the parser generator of
17
17
  [WillBooster/tree-sitter](https://github.com/WillBooster/tree-sitter). The parser carries that fork's own ABI number, so
18
- it loads only with the WillBooster runtime (`willbooster-tree-sitter` or `@willbooster/web-tree-sitter`) 2.0.0 or later,
18
+ it loads only with the WillBooster runtime (`willbooster-tree-sitter` or `@willbooster/web-tree-sitter`) 2.x,
19
19
  not with upstream's tree-sitter.
20
20
 
21
21
  ## Usage
22
22
 
23
23
  The npm package ships `tree-sitter-python.wasm` for
24
24
  [@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter), which runs in Node.js, Bun,
25
- browsers, and Cloudflare Workers. The parser requires runtime 2.0.0 or later.
25
+ browsers, and Cloudflare Workers. The parser requires runtime 2.x.
26
26
 
27
27
  In Node.js and Bun, load the grammar from its path:
28
28
 
@@ -63,14 +63,16 @@ parser.setLanguage(await Language.load(python));
63
63
 
64
64
  The package also ships the queries in `queries/` and the node types in `src/node-types.json`.
65
65
 
66
+ Qualified generic bases use `member_type` inside `generic_type`. Plain qualified generic arguments also expose `member_type` inside their `type` operand, so queries can capture the terminal type name while excluding its module qualifiers. Structured unpacked annotations and unpacked generic arguments use a `type` child inside `splat_type`. Expression-valued starred parameter annotations, such as `*args: *factory()`, keep a direct expression child instead. Ordinary value unpacks keep their expression tree.
67
+
66
68
  In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-python) and on
67
69
  [willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter), the runtime this package is tested and
68
- fuzzed with. The parser requires runtime 2.0.0 or later:
70
+ fuzzed with. The parser requires runtime 2.x:
69
71
 
70
72
  ```toml
71
73
  [dependencies]
72
74
  tree-sitter = { package = "willbooster-tree-sitter", version = "2" }
73
- tree-sitter-python = { package = "willbooster-tree-sitter-python", version = "2" }
75
+ tree-sitter-python = { package = "willbooster-tree-sitter-python", version = "4" }
74
76
  ```
75
77
 
76
78
  ```rust
package/grammar.js CHANGED
@@ -46,6 +46,9 @@ module.exports = grammar({
46
46
  [$.default_type_parameter, $.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],
49
52
  [$.primary_expression, $._default_member_type],
50
53
  [$.list, $._default_type_list],
51
54
  [$._type_parameter_expression, $.expression],
@@ -494,7 +497,14 @@ module.exports = grammar({
494
497
  _default_splat_type: ($) => seq('*', choice($.primary_expression, prec.dynamic(1, alias($._default_type, $.type)))),
495
498
 
496
499
  _generic_type_arguments: ($) =>
497
- seq('[', commaSep1(choice($.type, alias($._list_splat_argument, $.splat_type))), optional(','), ']'),
500
+ seq(
501
+ '[',
502
+ commaSep1(
503
+ choice($.type, alias($._type_parameter_expression, $.type), alias($._default_splat_argument, $.splat_type))
504
+ ),
505
+ optional(','),
506
+ ']'
507
+ ),
498
508
 
499
509
  argument_list: ($) =>
500
510
  seq(
@@ -832,7 +842,7 @@ module.exports = grammar({
832
842
  PREC.typed_parameter,
833
843
  choice(
834
844
  seq(choice($.identifier, $.dictionary_splat_pattern), ':', field('type', $.type)),
835
- seq($.list_splat_pattern, ':', field('type', choice($.type, alias($.list_splat, $.splat_type))))
845
+ seq($.list_splat_pattern, ':', field('type', choice($.type, alias($._default_splat_type, $.splat_type))))
836
846
  )
837
847
  ),
838
848
 
@@ -841,7 +851,10 @@ module.exports = grammar({
841
851
  generic_type: ($) =>
842
852
  prec.dynamic(
843
853
  1,
844
- seq(choice($.identifier, alias('type', $.identifier)), alias($._generic_type_arguments, $.type_parameter))
854
+ seq(
855
+ choice($.identifier, alias('type', $.identifier), alias($._default_member_type, $.member_type)),
856
+ alias($._generic_type_arguments, $.type_parameter)
857
+ )
845
858
  ),
846
859
  union_type: ($) => prec.left(seq($.type, '|', $.type)),
847
860
  constrained_type: ($) => prec.right(seq($.type, ':', $.type)),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-python",
3
- "version": "2.3.2",
3
+ "version": "4.0.0",
4
4
  "description": "Python grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -67,7 +67,8 @@
67
67
  (class_definition
68
68
  superclasses: (argument_list
69
69
  (subscript subscript: (list_splat (identifier) @type))))
70
- (member_type (identifier) @type)
70
+ (type (member_type (identifier) @type .))
71
+ (generic_type (member_type (identifier) @type .))
71
72
  (generic_type (identifier) @type)
72
73
  (default_type_parameter name: (identifier) @type)
73
74
 
@@ -3066,26 +3066,6 @@
3066
3066
  "multiple": false,
3067
3067
  "required": true,
3068
3068
  "types": [
3069
- {
3070
- "type": "boolean_operator",
3071
- "named": true
3072
- },
3073
- {
3074
- "type": "comparison_operator",
3075
- "named": true
3076
- },
3077
- {
3078
- "type": "conditional_expression",
3079
- "named": true
3080
- },
3081
- {
3082
- "type": "lambda",
3083
- "named": true
3084
- },
3085
- {
3086
- "type": "not_operator",
3087
- "named": true
3088
- },
3089
3069
  {
3090
3070
  "type": "primary_expression",
3091
3071
  "named": true
Binary file
package/tree-sitter.json CHANGED
@@ -19,7 +19,7 @@
19
19
  }
20
20
  ],
21
21
  "metadata": {
22
- "version": "2.3.2",
22
+ "version": "4.0.0",
23
23
  "license": "MIT",
24
24
  "description": "Python grammar for tree-sitter",
25
25
  "authors": [