Skip to content

Commit 43e3fd9

Browse files
committed
Allow starred expressions in subscripts
1 parent e0a2948 commit 43e3fd9

File tree

3 files changed

+654
-1
lines changed

3 files changed

+654
-1
lines changed

compiler/parser/python.lalrpop

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ SubscriptList: ast::Expr = {
10371037
};
10381038

10391039
Subscript: ast::Expr = {
1040-
NamedExpressionTest,
1040+
TestOrStarNamedExpr,
10411041
<location:@L> <e1:Test<"all">?> ":" <e2:Test<"all">?> <e3:SliceOp?> <end_location:@R> => {
10421042
let lower = e1.map(Box::new);
10431043
let upper = e2.map(Box::new);

compiler/parser/src/parser.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,18 @@ with (0 as a, 1 as b,): pass
392392
}
393393
}
394394

395+
#[test]
396+
fn test_star_index() {
397+
let source = "\
398+
array_slice = array[0, *idxs, -1]
399+
array[0, *idxs, -1] = array_slice
400+
array[*idxs_to_select, *idxs_to_select]
401+
array[3:5, *idxs_to_select]
402+
";
403+
let parse_ast = parse_program(source, "<test>").unwrap();
404+
insta::assert_debug_snapshot!(parse_ast);
405+
}
406+
395407
#[test]
396408
fn test_generator_expression_argument() {
397409
let source = r#"' '.join(

0 commit comments

Comments
 (0)