Python: Fix generator expression locations

Our logic for detecting the first and last item in a generator
expression was faulty, sometimes matching comments as well. Because
attributes (like `_location_start`) can only be written once, this
caused `tree-sitter-graph` to get unhappy.

To fix this, we now require the first item to be an `expression`, and
the last one to be either a `for_in_clause` or an `if_clause`.
Crucially, `comment` is neither of these, and this prevents the
unfortunate overlap.
This commit is contained in:
Taus
2024-10-28 14:53:09 +00:00
parent ef60b730ea
commit 5d6600e61f
2 changed files with 11 additions and 4 deletions

View File

@@ -65,3 +65,10 @@ t = tuple(x for y in z)
d for e in f if g # comment
# comment
] # comment
# Generator expression with comments
(# comment
alpha # comment
for beta in gamma # comment
# comment
)