Skip to content

Commit 3c8c4c1

Browse files
committed
Python: Support unpacking in comprehensions in tree-sitter-python
This is the easy part -- we just allow `dictionary_splat` or `list_splat` to appear in the same place as the expression.
1 parent 86020d9 commit 3c8c4c1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

python/extractor/tsg-python/tsp/grammar.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,28 +1031,28 @@ module.exports = grammar({
10311031

10321032
list_comprehension: $ => seq(
10331033
'[',
1034-
field('body', $.expression),
1034+
field('body', choice($.expression, $.list_splat)),
10351035
$._comprehension_clauses,
10361036
']'
10371037
),
10381038

10391039
dictionary_comprehension: $ => seq(
10401040
'{',
1041-
field('body', $.pair),
1041+
field('body', choice($.pair, $.dictionary_splat)),
10421042
$._comprehension_clauses,
10431043
'}'
10441044
),
10451045

10461046
set_comprehension: $ => seq(
10471047
'{',
1048-
field('body', $.expression),
1048+
field('body', choice($.expression, $.list_splat)),
10491049
$._comprehension_clauses,
10501050
'}'
10511051
),
10521052

10531053
generator_expression: $ => seq(
10541054
'(',
1055-
field('body', $.expression),
1055+
field('body', choice($.expression, $.list_splat)),
10561056
$._comprehension_clauses,
10571057
')'
10581058
),

0 commit comments

Comments
 (0)