@@ -18,7 +18,7 @@ macro_rules! call_test {
18
18
named_args ! ( pub statement( indent: usize ) <StrSpan , Vec <Statement >>,
19
19
alt!(
20
20
call!( compound_stmt, indent) => { |stmt| vec![ Statement :: Compound ( Box :: new( stmt) ) ] }
21
- | call!( simple_stmt)
21
+ | preceded! ( count! ( char ! ( ' ' ) , indent ) , call!( simple_stmt) )
22
22
)
23
23
) ;
24
24
@@ -324,7 +324,6 @@ named_args!(pub block(indent: usize) <StrSpan, Vec<Statement>>,
324
324
stmts: fold_many1!(
325
325
do_parse!(
326
326
newline >>
327
- count!( char !( ' ' ) , new_indent) >>
328
327
r: call!( statement, new_indent) >>
329
328
( r)
330
329
) ,
@@ -350,7 +349,7 @@ named_args!(cond_and_block(indent: usize) <StrSpan, (Expression, Vec<Statement>)
350
349
351
350
// compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated | async_stmt
352
351
named_args ! ( compound_stmt( indent: usize ) <StrSpan , CompoundStatement >,
353
- switch!( peek!( first_word) ,
352
+ switch!( peek!( ws2! ( first_word) ) ,
354
353
"if" => call!( if_stmt, indent)
355
354
| "for" => call!( for_stmt, indent)
356
355
| "while" => call!( while_stmt, indent)
@@ -381,6 +380,7 @@ named_args!(else_block(indent: usize) <StrSpan, Option<Vec<Statement>>>,
381
380
// if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
382
381
named_args ! ( if_stmt( indent: usize ) <StrSpan , CompoundStatement >,
383
382
do_parse!(
383
+ count!( char !( ' ' ) , indent) >>
384
384
tag!( "if" ) >>
385
385
if_block: call!( cond_and_block, indent) >>
386
386
elif_blocks: many0!(
@@ -400,6 +400,7 @@ named_args!(if_stmt(indent: usize) <StrSpan, CompoundStatement>,
400
400
// while_stmt: 'while' test ':' suite ['else' ':' suite]
401
401
named_args ! ( while_stmt( indent: usize ) <StrSpan , CompoundStatement >,
402
402
do_parse!(
403
+ count!( char !( ' ' ) , indent) >>
403
404
tag!( "while" ) >>
404
405
while_block: call!( cond_and_block, indent) >>
405
406
else_block: call!( else_block, indent) >> ( {
@@ -412,6 +413,7 @@ named_args!(while_stmt(indent: usize) <StrSpan, CompoundStatement>,
412
413
// for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]
413
414
named_args ! ( for_stmt( indent: usize ) <StrSpan , CompoundStatement >,
414
415
do_parse!(
416
+ count!( char !( ' ' ) , indent) >>
415
417
async : opt!( tuple!( tag!( "async" ) , space_sep2) ) >>
416
418
tag!( "for" ) >>
417
419
space_sep2 >>
@@ -439,6 +441,7 @@ named_args!(for_stmt(indent: usize) <StrSpan, CompoundStatement>,
439
441
// except_clause: 'except' [test ['as' NAME]]
440
442
named_args ! ( try_stmt( indent: usize ) <StrSpan , CompoundStatement >,
441
443
do_parse!(
444
+ count!( char !( ' ' ) , indent) >>
442
445
tag!( "try" ) >>
443
446
ws2!( char !( ':' ) ) >>
444
447
try_block: call!( block, indent) >>
@@ -492,6 +495,7 @@ named_args!(try_stmt(indent: usize) <StrSpan, CompoundStatement>,
492
495
// with_item: test ['as' expr]
493
496
named_args ! ( with_stmt( indent: usize ) <StrSpan , CompoundStatement >,
494
497
do_parse!(
498
+ count!( char !( ' ' ) , indent) >>
495
499
tag!( "with" ) >>
496
500
space_sep2 >>
497
501
contexts: separated_nonempty_list!( ws2!( char !( ',' ) ) , do_parse!(
@@ -526,8 +530,10 @@ mod tests {
526
530
#[ test]
527
531
fn test_statement_indent ( ) {
528
532
assert_parse_eq ( statement ( make_strspan ( "del foo" ) , 0 ) , Ok ( ( make_strspan ( "" ) , vec ! [ Statement :: Del ( vec![ "foo" . to_string( ) ] ) ] ) ) ) ;
533
+ assert_parse_eq ( statement ( make_strspan ( " del foo" ) , 1 ) , Ok ( ( make_strspan ( "" ) , vec ! [ Statement :: Del ( vec![ "foo" . to_string( ) ] ) ] ) ) ) ;
529
534
assert ! ( statement( make_strspan( " del foo" ) , 0 ) . is_err( ) ) ;
530
- assert ! ( statement( make_strspan( " del foo" ) , 1 ) . is_err( ) ) ;
535
+ assert ! ( statement( make_strspan( " del foo" ) , 1 ) . is_err( ) ) ;
536
+ assert ! ( statement( make_strspan( "del foo" ) , 1 ) . is_err( ) ) ;
531
537
}
532
538
533
539
#[ test]
0 commit comments