Skip to content

Commit

Permalink
parser: for_stmt: fix typo preventing parsing non-trivial expressions…
Browse files Browse the repository at this point in the history
… in the iterator side.
  • Loading branch information
progval committed Sep 8, 2020
1 parent af0eee6 commit 81c4ef8
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/statements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ named_args!(for_stmt(indent: usize) <StrSpan, CompoundStatement>,
spaces_nonl >>
item: call!(ExpressionParser::<NewlinesAreNotSpaces>::exprlist) >>
ws_nonl!(keyword!("in")) >>
iterator: call!(ExpressionParser::<NewlinesAreNotSpaces>::exprlist) >>
iterator: call!(ExpressionParser::<NewlinesAreNotSpaces>::testlist) >>
spaces_nonl >>
ws_nonl!(char!(':')) >>
for_block: call!(block, indent) >>
Expand Down Expand Up @@ -965,6 +965,27 @@ mod tests {
);
}

#[test]
fn test_for_in_ternary() {
assert_parse_eq(
compound_stmt(make_strspan("for foo in bar if baz else qux:\n pass"), 0),
Ok((
make_strspan(""),
CompoundStatement::For {
async: false,
item: vec![Expression::Name("foo".to_string())],
iterator: vec![Expression::Ternary(
Box::new(Expression::Name("bar".to_string())),
Box::new(Expression::Name("baz".to_string())),
Box::new(Expression::Name("qux".to_string())),
)],
for_block: vec![Statement::Pass],
else_block: None,
},
)),
);
}

#[test]
fn test_for_else() {
assert_parse_eq(
Expand Down

0 comments on commit 81c4ef8

Please sign in to comment.