@@ -62,7 +62,7 @@ named!(small_stmt<StrSpan, Statement>,
62
62
// annassign: ':' test ['=' test]
63
63
named ! ( expr_stmt<StrSpan , Statement >,
64
64
do_parse!(
65
- lhs: testlist_star_expr >>
65
+ lhs: call! ( ExpressionParser :: < NewlinesAreNotSpaces > :: testlist_star_expr) >>
66
66
r: ws_nonl!( alt!(
67
67
// Case 1: "foo: bar = baz"
68
68
do_parse!(
@@ -89,7 +89,7 @@ named!(expr_stmt<StrSpan, Statement>,
89
89
do_parse!(
90
90
rhs: many0!( ws_nonl!( preceded!( char !( '=' ) , alt!(
91
91
call!( ExpressionParser :: <NewlinesAreNotSpaces >:: yield_expr) => { |e| vec![ e] }
92
- | testlist_star_expr
92
+ | call! ( ExpressionParser :: < NewlinesAreNotSpaces > :: testlist_star_expr)
93
93
) ) ) ) >> (
94
94
Statement :: Assignment ( lhs, rhs)
95
95
)
@@ -99,28 +99,6 @@ named!(expr_stmt<StrSpan, Statement>,
99
99
)
100
100
) ;
101
101
102
- // testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [',']
103
- named ! ( testlist_star_expr<StrSpan , Vec <Expression >>,
104
- do_parse!(
105
- list: separated_nonempty_list!(
106
- ws_nonl!( char !( ',' ) ) ,
107
- map!( alt!(
108
- call!( ExpressionParser :: <NewlinesAreNotSpaces >:: test)
109
- | call!( ExpressionParser :: <NewlinesAreNotSpaces >:: star_expr)
110
- ) , |e| * e)
111
- ) >>
112
- trailing_comma: opt!( ws_nonl!( char !( ',' ) ) ) >> (
113
- if trailing_comma. is_some( ) && list. len( ) < 2 {
114
- // This prevents "foo, =" from being parsed as "foo ="
115
- vec![ Expression :: TupleLiteral ( list. into_iter( ) . map( SetItem :: Unique ) . collect( ) ) ]
116
- }
117
- else {
118
- list
119
- }
120
- )
121
- )
122
- ) ;
123
-
124
102
// augassign: ('+=' | '-=' | '*=' | '@=' | '/=' | '%=' | '&=' | '|=' | '^=' |
125
103
// '<<=' | '>>=' | '**=' | '//=')
126
104
named ! ( augassign<StrSpan , AugAssignOp >,
@@ -159,15 +137,15 @@ named!(pass_stmt<StrSpan, Statement>,
159
137
// flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt
160
138
// break_stmt: 'break'
161
139
// continue_stmt: 'continue'
162
- // return_stmt: 'return' [testlist ]
140
+ // return_stmt: 'return' [testlist_star_expr ]
163
141
// yield_stmt: yield_expr
164
142
named ! ( flow_stmt<StrSpan , Statement >,
165
143
alt!(
166
144
keyword!( "break" ) => { |_| Statement :: Break }
167
145
| keyword!( "continue" ) => { |_| Statement :: Continue }
168
146
| preceded!(
169
147
tuple!( keyword!( "return" ) , spaces_nonl) ,
170
- return_error!( ws_nonl!( call!( ExpressionParser :: <NewlinesAreNotSpaces >:: possibly_empty_testlist ) ) )
148
+ return_error!( ws_nonl!( call!( ExpressionParser :: <NewlinesAreNotSpaces >:: testlist_star_expr ) ) )
171
149
) => { |e| Statement :: Return ( e) }
172
150
| raise_stmt
173
151
| call!( ExpressionParser :: <NewlinesAreNotSpaces >:: yield_expr)
@@ -1192,15 +1170,4 @@ mod tests {
1192
1170
} ) ]
1193
1171
) ) ) ;
1194
1172
}
1195
-
1196
- #[ test]
1197
- fn test_unpack ( ) {
1198
- assert_parse_eq ( testlist_star_expr ( make_strspan ( "foo," ) ) , Ok ( ( make_strspan ( "" ) ,
1199
- vec ! [
1200
- Expression :: TupleLiteral ( vec![
1201
- SetItem :: Unique ( Expression :: Name ( "foo" . to_string( ) ) ) ,
1202
- ] ) ,
1203
- ]
1204
- ) ) ) ;
1205
- }
1206
1173
}
0 commit comments