Skip to content

Commit 127bdab

Browse files
committed
Python: Update tree-sitter dependency
Updates the Python extractor to depend on version 0.24.7 of tree-sitter (and 0.12.0 of tree-sitter-graph). A few changes were needed in order to make the code build and run after updating the dependencies: - In `main.rs`, the `Language` parameter is now passed as a reference. - In `python.tsg`, many queries had captures that were not actually used in the body of the stanza. This is no longer allowed (unless the captures start with an underscore), as it may indicate an error. To fix this, I added underscores in the appropriate places (and verified that none of these unused captures were in fact bugs).
1 parent cd0e463 commit 127bdab

File tree

5 files changed

+37
-53
lines changed

5 files changed

+37
-53
lines changed

python/extractor/tsg-python/Cargo.lock

Lines changed: 18 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/extractor/tsg-python/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ edition = "2024"
1010
[dependencies]
1111
anyhow = "1.0"
1212
regex = "1"
13-
tree-sitter = "=0.20.4"
14-
tree-sitter-graph = "0.7.0"
13+
tree-sitter = "=0.24.7"
14+
tree-sitter-graph = "0.12.0"
1515
tsp = {path = "tsp"}
1616
clap = "4.5"

python/extractor/tsg-python/python.tsg

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -416,13 +416,13 @@
416416
attr (@if.node) _location_end = (location-end @expr)
417417
}
418418

419-
(generator_expression . "(" . (comment)* . (expression) @start (for_in_clause) @child [(for_in_clause) (if_clause)] @end . (comment)* . ")" .) @genexpr
419+
(generator_expression . "(" . (comment)* . (expression) @start (for_in_clause) @child [(for_in_clause) (if_clause)] @end . (comment)* . ")" .) @_genexpr
420420
{
421421
attr (@child.node) _location_start = (location-start @start)
422422
attr (@child.node) _location_end = (location-end @end)
423423
}
424424

425-
(generator_expression . "(" . (comment)* . (expression) @start (for_in_clause) @end . (comment)* . ")" .) @genexpr
425+
(generator_expression . "(" . (comment)* . (expression) @start (for_in_clause) @end . (comment)* . ")" .) @_genexpr
426426
{
427427
attr (@end.node) _location_start = (location-start @start)
428428
attr (@end.node) _location_end = (location-end @end)
@@ -524,7 +524,7 @@
524524
attr (@del.node -> @target.node) targets = (named-child-index @target)
525525
}
526526

527-
(delete_statement target: (_) @target) @del
527+
(delete_statement target: (_) @target) @_del
528528
{
529529
attr (@target.node) ctx = "del"
530530
}
@@ -798,8 +798,8 @@
798798

799799
(dictionary_comprehension
800800
body: (pair
801-
key: (_) @key
802-
value: (_) @value
801+
key: (_) @_key
802+
value: (_) @_value
803803
)
804804
) @genexpr
805805
{
@@ -1299,7 +1299,7 @@
12991299
; the index of the left-hand side of the current assignment.
13001300

13011301
; Base case, for the outermost assignment we set the outermost node to this node, and the index to zero.
1302-
(expression_statement (assignment !type) @assign) @expr
1302+
(expression_statement (assignment !type) @assign) @_expr
13031303
{
13041304
let @assign.outermost_assignment = @assign.node
13051305
let @assign.target_index = 0
@@ -1358,7 +1358,7 @@
13581358
}
13591359

13601360
(assignment
1361-
left: (_) @target
1361+
left: (_) @_target
13621362
type: (_)
13631363
right: (_) @value
13641364
) @assign
@@ -2330,7 +2330,7 @@
23302330
attr (@operand.node) ctx = "load"
23312331
}
23322332

2333-
(unary_operator "~" @op) @unaryop
2333+
(unary_operator "~" @_op) @unaryop
23342334
{
23352335
attr (@unaryop.node) op = "~"
23362336
}
@@ -2614,7 +2614,7 @@
26142614
; Async status
26152615
; NOTE: We only set the `is_async` field on the _first_ clause of the `with` statement,
26162616
; as this is the behaviour of the old parser.
2617-
(with_statement "async" "with" @with_keyword (with_clause . (with_item) @with))
2617+
(with_statement "async" "with" @_with_keyword (with_clause . (with_item) @with))
26182618
{
26192619
attr (@with.node) is_async = #true
26202620
}
@@ -2800,7 +2800,7 @@
28002800
(identifier) @obj
28012801
.
28022802
(identifier) @attr
2803-
) @match_value_pattern
2803+
) @_match_value_pattern
28042804
{
28052805
let attribute = (ast-node @attr "Attribute")
28062806
attr (@attr.node) _skip_to = attribute
@@ -2814,7 +2814,7 @@
28142814
(match_value_pattern
28152815
.
28162816
(identifier) @id
2817-
) @match_value_pattern
2817+
) @_match_value_pattern
28182818
{
28192819
attr (@id.node) ctx = "load"
28202820
}
@@ -3267,8 +3267,8 @@
32673267
(decorated_definition
32683268
(decorator (expression) @exp1) @dec1
32693269
. (comment)* .
3270-
(decorator (expression) @exp2) @dec2
3271-
) @decorator
3270+
(decorator (expression) @_exp2) @dec2
3271+
) @_decorator
32723272
{
32733273
attr (@dec1.node) func = @exp1.node
32743274
edge @dec1.node -> @dec2.node
@@ -3279,7 +3279,7 @@
32793279
(decorator (expression) @exp) @last
32803280
. (comment)* .
32813281
definition: (function_definition) @funcdef
3282-
) @decorator
3282+
) @_decorator
32833283
{
32843284
attr (@last.node) func = @exp.node
32853285
edge @last.node -> @funcdef.funcexpr
@@ -3291,7 +3291,7 @@
32913291
(decorator (expression) @exp) @last
32923292
. (comment)* .
32933293
definition: (class_definition) @class
3294-
) @decorator
3294+
) @_decorator
32953295
{
32963296
attr (@last.node) func = @exp.node
32973297
edge @last.node -> @class.class_expr

python/extractor/tsg-python/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ fn main() -> Result<()> {
502502
let source_path = Path::new(matches.get_one::<String>("source").unwrap());
503503
let language = tsp::language();
504504
let mut parser = Parser::new();
505-
parser.set_language(language)?;
505+
parser.set_language(&language)?;
506506
// Statically include `python.tsg`:
507507
let tsg = if matches.contains_id("tsg") {
508508
std::fs::read(&tsg_path).with_context(|| format!("Error reading TSG file {}", tsg_path))?

python/extractor/tsg-python/tsp/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ path = "bindings/rust/lib.rs"
2626

2727
## When updating these dependencies, run `misc/bazel/3rdparty/update_cargo_deps.sh`
2828
[dependencies]
29-
tree-sitter = ">= 0.20, < 0.21"
29+
tree-sitter = "=0.24.7"
3030

3131
[build-dependencies]
3232
cc = "1.2"

0 commit comments

Comments
 (0)