@@ -46,32 +46,38 @@ SmallStatement: ast::LocatedStatement = {
4646};
4747
4848ExpressionStatement: ast::LocatedStatement = {
49- <loc:@L> <e:TestList> <e2:AssignSuffix*> => {
50- //match e2 {
51- // None => ast::Statement::Expression { expression: e },
52- // Some(e3) => ast::Statement::Expression { expression: e },
53- //}
54- if e2.len() > 0 {
55- // Dealing with assignment here
56- // TODO: for rhs in e2 {
57- let rhs = e2.into_iter().next().unwrap();
58- // ast::Expression::Tuple { elements: e2.into_iter().next().unwrap()
59- let v = rhs.into_iter().next().unwrap();
60- let lhs = ast::LocatedStatement {
61- location: loc.clone(),
62- node: ast::Statement::Assign { targets: e, value: v },
63- };
64- lhs
65- } else {
66- if e.len() > 1 {
67- panic!("Not good?");
68- // ast::Statement::Expression { expression: e[0] }
49+ <loc:@L> <expr:TestList> <suffix:AssignSuffix*> => {
50+ // Just an expression, no assignment:
51+ if suffix.is_empty() {
52+ if expr.len() > 1 {
53+ ast::LocatedStatement {
54+ location: loc.clone(),
55+ node: ast::Statement::Expression { expression: ast::Expression::Tuple { elements: expr } }
56+ }
6957 } else {
7058 ast::LocatedStatement {
7159 location: loc.clone(),
72- node: ast::Statement::Expression { expression: e.into_iter().next().unwrap () },
60+ node: ast::Statement::Expression { expression: expr[0].clone () },
7361 }
7462 }
63+ } else {
64+ let mut targets = vec![if expr.len() > 1 {
65+ ast::Expression::Tuple { elements: expr }
66+ } else {
67+ expr[0].clone()
68+ }];
69+ let mut values : Vec<ast::Expression> = suffix.into_iter().map(|test_list| if test_list.len() > 1 { ast::Expression::Tuple { elements: test_list }} else { test_list[0].clone() }).collect();
70+
71+ while values.len() > 1 {
72+ targets.push(values.remove(0));
73+ }
74+
75+ let value = values[0].clone();
76+
77+ ast::LocatedStatement {
78+ location: loc.clone(),
79+ node: ast::Statement::Assign { targets, value },
80+ }
7581 }
7682 },
7783 <loc:@L> <e1:Test> <op:AugAssign> <e2:TestList> => {
@@ -120,7 +126,7 @@ FlowStatement: ast::LocatedStatement = {
120126 <loc:@L> "return" <t:TestList?> => {
121127 ast::LocatedStatement {
122128 location: loc,
123- node: ast::Statement::Return { value: t},
129+ node: ast::Statement::Return { value: t },
124130 }
125131 },
126132 <loc:@L> "raise" <t:Test?> => {
0 commit comments