@willbooster/tree-sitter-python 12.0.0 → 14.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
@@ -5,24 +5,31 @@
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.48.9-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
8
+ [![wbfy](https://img.shields.io/badge/wbfy-20.51.1-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 builds on upstream v0.25.0 with grammar, scanner, and highlighting fixes, including Python 3.15
15
+ This fork builds on upstream v0.25.0 with grammar and scanner 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`) 14.0.0 or later within 14.x,
18
+ it loads only with the WillBooster runtime (`willbooster-tree-sitter` or `@willbooster/web-tree-sitter`) 15.0.0 or later within 15.x,
19
19
  not with upstream's tree-sitter.
20
20
 
21
+ ## Support Scope
22
+
23
+ This fork maintains only full parsing: valid input yields a correct tree, and invalid input yields `ERROR` or `MISSING`
24
+ nodes without crashing, hanging, or taking more than linear time. Incremental parsing works as in upstream tree-sitter
25
+ but is not tested here, and no queries (highlights, locals, injections, tags) are shipped. Node types, field names, and
26
+ the trees that error recovery produces may change; such changes are released as new major versions.
27
+
21
28
  ## Usage
22
29
 
23
30
  The npm package ships `tree-sitter-python.wasm` for
24
31
  [@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 14.0.0 or later within 14.x.
32
+ browsers, and Cloudflare Workers. The parser requires runtime 15.0.0 or later within 15.x.
26
33
 
27
34
  In Node.js and Bun, load the grammar from its path:
28
35
 
@@ -62,18 +69,18 @@ const parser = new Parser();
62
69
  parser.setLanguage(await Language.load(python));
63
70
  ```
64
71
 
65
- The package also ships the queries in `queries/` and the node types in `src/node-types.json`.
72
+ The package also ships the node types in `src/node-types.json`.
66
73
 
67
- Qualified generic bases use `member_type` inside `generic_type`. Generic bases in annotations also recognize the contextual identifier spellings `match`, `print`, `exec` and `lazy`, while ordinary value subscripts retain their expression trees. 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.
74
+ Qualified generic bases use `member_type` inside `generic_type`. Generic bases in annotations also recognize the contextual identifier spellings `match`, `print`, `exec` and `lazy`, while ordinary value subscripts retain their expression trees. Plain qualified generic arguments also expose `member_type` inside their `type` operand. 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.
68
75
 
69
76
  In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-python) and on
70
77
  [willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter), the runtime this package is tested and
71
- fuzzed with. The parser requires runtime 14.0.0 or later within 14.x:
78
+ fuzzed with. The parser requires runtime 15.0.0 or later within 15.x:
72
79
 
73
80
  ```toml
74
81
  [dependencies]
75
- tree-sitter = { package = "willbooster-tree-sitter", version = "14.0.0" }
76
- tree-sitter-python = { package = "willbooster-tree-sitter-python", version = "11" }
82
+ tree-sitter = { package = "willbooster-tree-sitter", version = "15.0.0" }
83
+ tree-sitter-python = { package = "willbooster-tree-sitter-python", version = "13" }
77
84
  ```
78
85
 
79
86
  ```rust
@@ -108,9 +115,6 @@ and the release build regenerate the parsers before compiling them.
108
115
  `bun run test` runs:
109
116
 
110
117
  - the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK);
111
- - an incremental-parsing check (`test/unit/incremental.test.ts`): `script/fuzz-corpus` runs `tree-sitter fuzz`, which
112
- edits each corpus case at random, reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`,
113
- `TREE_SITTER_ITERATIONS`, and `TREE_SITTER_EDITS` run other or more edits;
114
118
  - a check that the real-world Python files in `examples/`, the checked-in ones and those of the cloned repositories,
115
119
  fail to parse exactly as listed in `script/known-failures.txt`. The first run clones the repositories. The example
116
120
  repositories are pinned to commits in `script/parse-examples`. After a grammar change or a moved pin alters that list,
@@ -125,7 +129,7 @@ and the release build regenerate the parsers before compiling them.
125
129
  Node.js compatibility (`test/unit/workerd.test.ts`). Run `bun run test/ci-setup` once to install Chromium.
126
130
 
127
131
  Tests and `script/parse-examples` keep native parser builds under this checkout's `.tmp/` instead of the CLI cache shared by every checkout.
128
- See `test/unit/run.ts`, `test/unit/deepIndentation.test.ts`, `script/fuzz-corpus`, and `script/parse-examples`
132
+ See `test/unit/run.ts`, `test/unit/deepIndentation.test.ts`, and `script/parse-examples`
129
133
  for their build locations and cleanup.
130
134
 
131
135
  CI also runs these tests on Linux arm64 and macOS, where the CLI compiles the parser and the scanner with the platform's
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-python",
3
- "version": "12.0.0",
3
+ "version": "14.0.0",
4
4
  "description": "Python grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -16,7 +16,6 @@
16
16
  },
17
17
  "files": [
18
18
  "grammar.js",
19
- "queries/*.scm",
20
19
  "tree-sitter.json",
21
20
  "src/node-types.json",
22
21
  "*.wasm"
@@ -46,15 +45,15 @@
46
45
  },
47
46
  "devDependencies": {
48
47
  "@tsconfig/bun": "1.0.11",
49
- "@types/bun": "1.4.3",
48
+ "@types/bun": "1.4.4",
50
49
  "@vitest/browser-playwright": "5.0.5",
51
50
  "@willbooster/oxlint-config": "1.4.9",
52
- "@willbooster/wb": "22.29.3",
53
- "@willbooster/web-tree-sitter": "14.0.0",
51
+ "@willbooster/wb": "22.32.3",
52
+ "@willbooster/web-tree-sitter": "15.0.0",
54
53
  "conventional-changelog-conventionalcommits": "10.4.1",
55
54
  "lefthook": "2.2.2",
56
- "oxlint": "1.88.0",
57
- "oxlint-tsgolint": "7.0.2004",
55
+ "oxlint": "1.89.0",
56
+ "oxlint-tsgolint": "7.0.2005",
58
57
  "playwright": "1.64.1",
59
58
  "semantic-release": "25.0.9",
60
59
  "vite": "8.3.4",
@@ -62,7 +61,7 @@
62
61
  "wrangler": "4.151.1"
63
62
  },
64
63
  "peerDependencies": {
65
- "@willbooster/web-tree-sitter": "^14.0.0"
64
+ "@willbooster/web-tree-sitter": "^15.0.0"
66
65
  },
67
66
  "peerDependenciesMeta": {
68
67
  "@willbooster/web-tree-sitter": {
Binary file
package/tree-sitter.json CHANGED
@@ -9,17 +9,11 @@
9
9
  "file-types": [
10
10
  "py"
11
11
  ],
12
- "highlights": [
13
- "queries/highlights.scm"
14
- ],
15
- "tags": [
16
- "queries/tags.scm"
17
- ],
18
12
  "injection-regex": "py"
19
13
  }
20
14
  ],
21
15
  "metadata": {
22
- "version": "12.0.0",
16
+ "version": "14.0.0",
23
17
  "license": "MIT",
24
18
  "description": "Python grammar for tree-sitter",
25
19
  "authors": [
@@ -1,171 +0,0 @@
1
- ; Identifier naming conventions
2
-
3
- (identifier) @variable
4
-
5
- ((identifier) @constructor
6
- (#match? @constructor "^[A-Z]"))
7
-
8
- ((identifier) @constant
9
- (#match? @constant "^[0-9_]*[A-Z][A-Z_0-9]*$"))
10
-
11
- ; Function calls
12
-
13
- (decorator) @function
14
- (decorator
15
- (identifier) @function)
16
-
17
- (call
18
- function: (attribute attribute: (identifier) @function.method))
19
- (call
20
- function: (identifier) @function)
21
-
22
- ; Builtin functions
23
-
24
- ((call
25
- function: (identifier) @function.builtin)
26
- (#match?
27
- @function.builtin
28
- "^(abs|all|any|ascii|bin|bool|breakpoint|bytearray|bytes|callable|chr|classmethod|compile|complex|delattr|dict|dir|divmod|enumerate|eval|exec|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|isinstance|issubclass|iter|len|list|locals|map|max|memoryview|min|next|object|oct|open|ord|pow|print|property|range|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|vars|zip|__import__)$"))
29
-
30
- ; Function definitions
31
-
32
- (function_definition
33
- name: (identifier) @function)
34
-
35
- ; Later patterns override naming heuristics in syntactically known class positions.
36
-
37
- ((class_definition
38
- name: (identifier) @constructor)
39
- (#match? @constructor "^[0-9_]*[A-Z][A-Z_0-9]*$"))
40
-
41
- ((class_definition
42
- superclasses: (argument_list (identifier) @constructor))
43
- (#match? @constructor "^[0-9_]*[A-Z][A-Z_0-9]*$"))
44
-
45
- ((class_definition
46
- superclasses: (argument_list (subscript value: (identifier) @constructor)))
47
- (#match? @constructor "^[0-9_]*[A-Z][A-Z_0-9]*$"))
48
-
49
- ((except_clause value: [
50
- (identifier) @constructor
51
- (tuple (identifier) @constructor)
52
- (parenthesized_expression (identifier) @constructor)
53
- ])
54
- (#match? @constructor "^[0-9_]*[A-Z][A-Z_0-9]*$"))
55
-
56
- ((class_pattern (dotted_name (identifier) @constructor .))
57
- (#match? @constructor "^[0-9_]*[A-Z][A-Z_0-9]*$"))
58
-
59
- (attribute attribute: (identifier) @property)
60
- (type (identifier) @type)
61
- (splat_type (identifier) @type)
62
- (class_definition
63
- superclasses: (argument_list
64
- (subscript subscript: (list_splat (identifier) @type))))
65
- (type (member_type (identifier) @type .))
66
- (generic_type (member_type (identifier) @type .))
67
- (generic_type (identifier) @type)
68
- (default_type_parameter name: (identifier) @type)
69
-
70
- ; Literals
71
-
72
- [
73
- (none)
74
- (true)
75
- (false)
76
- ] @constant.builtin
77
-
78
- [
79
- (integer)
80
- (float)
81
- ] @number
82
-
83
- (comment) @comment
84
- (string) @string
85
- (escape_sequence) @escape
86
-
87
- (interpolation
88
- "{" @punctuation.special
89
- "}" @punctuation.special) @embedded
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
- "~"
127
- "@="
128
- "and"
129
- "in"
130
- "is"
131
- "not"
132
- "or"
133
- "is not"
134
- "not in"
135
- ] @operator
136
-
137
- [
138
- "as"
139
- "assert"
140
- "async"
141
- "await"
142
- "break"
143
- "class"
144
- "continue"
145
- "def"
146
- "del"
147
- "elif"
148
- "else"
149
- "except"
150
- "exec"
151
- "finally"
152
- "for"
153
- "from"
154
- "global"
155
- "if"
156
- "import"
157
- "lambda"
158
- "nonlocal"
159
- "pass"
160
- "print"
161
- "raise"
162
- "return"
163
- "try"
164
- "while"
165
- "with"
166
- "yield"
167
- "match"
168
- "case"
169
- ] @keyword
170
-
171
- (lazy_import_statement "lazy" @keyword)
package/queries/tags.scm DELETED
@@ -1,14 +0,0 @@
1
- (module (expression_statement (assignment left: (identifier) @name) @definition.constant))
2
-
3
- (class_definition
4
- name: (identifier) @name) @definition.class
5
-
6
- (function_definition
7
- name: (identifier) @name) @definition.function
8
-
9
- (call
10
- function: [
11
- (identifier) @name
12
- (attribute
13
- attribute: (identifier) @name)
14
- ]) @reference.call