Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ parser.setLanguage(await Language.load(python));

The package also ships the queries in `queries/` and the node types in `src/node-types.json`.

Qualified generic bases use `member_type` inside `generic_type`. 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.
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.

In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-python) and on
[willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter), the runtime this package is tested and
Expand All @@ -72,7 +72,7 @@ fuzzed with. The parser requires runtime 2.x:
```toml
[dependencies]
tree-sitter = { package = "willbooster-tree-sitter", version = "2" }
tree-sitter-python = { package = "willbooster-tree-sitter-python", version = "3" }
tree-sitter-python = { package = "willbooster-tree-sitter-python", version = "4" }
```

```rust
Expand Down
12 changes: 11 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ module.exports = grammar({
[$.default_type_parameter, $.primary_expression],
[$.primary_expression, $._default_type_primary],
[$.primary_expression, $._default_generic_type],
[$._default_generic_type, $.primary_expression, $.generic_type],
[$._default_type_arguments, $.expression],
[$._default_type_arguments, $._generic_type_arguments],
[$.primary_expression, $._default_member_type],
[$.list, $._default_type_list],
[$._type_parameter_expression, $.expression],
Expand Down Expand Up @@ -494,7 +497,14 @@ module.exports = grammar({
_default_splat_type: ($) => seq('*', choice($.primary_expression, prec.dynamic(1, alias($._default_type, $.type)))),

_generic_type_arguments: ($) =>
seq('[', commaSep1(choice($.type, alias($._default_splat_argument, $.splat_type))), optional(','), ']'),
seq(
'[',
commaSep1(
choice($.type, alias($._type_parameter_expression, $.type), alias($._default_splat_argument, $.splat_type))
),
optional(','),
']'
),

argument_list: ($) =>
seq(
Expand Down
31 changes: 31 additions & 0 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -2860,6 +2860,15 @@
"type": "SYMBOL",
"name": "type"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_type_parameter_expression"
},
"named": true,
"value": "type"
},
{
"type": "ALIAS",
"content": {
Expand Down Expand Up @@ -2887,6 +2896,15 @@
"type": "SYMBOL",
"name": "type"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_type_parameter_expression"
},
"named": true,
"value": "type"
},
{
"type": "ALIAS",
"content": {
Expand Down Expand Up @@ -7260,6 +7278,19 @@
"primary_expression",
"_default_generic_type"
],
[
"_default_generic_type",
"primary_expression",
"generic_type"
],
[
"_default_type_arguments",
"expression"
],
[
"_default_type_arguments",
"_generic_type_arguments"
],
[
"primary_expression",
"_default_member_type"
Expand Down
Loading
Loading