@@ -636,6 +636,22 @@ where
636
636
}
637
637
}
638
638
639
+ /// This is the main entry point. Call this function to retrieve the next token.
640
+ /// This function is used by the iterator implementation.
641
+ fn inner_next ( & mut self ) -> LexResult {
642
+ // top loop, keep on processing, until we have something pending.
643
+ while self . pending . is_empty ( ) {
644
+ // Detect indentation levels
645
+ if self . at_begin_of_line {
646
+ self . handle_indentations ( ) ?;
647
+ }
648
+
649
+ self . consume_normal ( ) ?;
650
+ }
651
+
652
+ Ok ( self . pending . remove ( 0 ) )
653
+ }
654
+
639
655
/// Given we are at the start of a line, count the number of spaces and/or tabs until the first character.
640
656
fn eat_indentation ( & mut self ) -> Result < IndentationLevel , LexicalError > {
641
657
// Determine indentation:
@@ -684,7 +700,11 @@ where
684
700
spaces = 0 ;
685
701
tabs = 0 ;
686
702
}
703
+ None => {
704
+ break ;
705
+ }
687
706
_ => {
707
+ self . at_begin_of_line = false ;
688
708
break ;
689
709
}
690
710
}
@@ -693,23 +713,6 @@ where
693
713
Ok ( IndentationLevel { spaces, tabs } )
694
714
}
695
715
696
- /// This is the main entry point. Call this function to retrieve the next token.
697
- /// This function is used by the iterator implementation.
698
- fn inner_next ( & mut self ) -> LexResult {
699
- // top loop, keep on processing, until we have something pending.
700
- while self . pending . is_empty ( ) {
701
- // Detect indentation levels
702
- if self . at_begin_of_line {
703
- self . at_begin_of_line = false ;
704
- self . handle_indentations ( ) ?;
705
- }
706
-
707
- self . consume_normal ( ) ?;
708
- }
709
-
710
- Ok ( self . pending . remove ( 0 ) )
711
- }
712
-
713
716
fn handle_indentations ( & mut self ) -> Result < ( ) , LexicalError > {
714
717
let indentation_level = self . eat_indentation ( ) ?;
715
718
@@ -756,7 +759,7 @@ where
756
759
location : self . get_pos ( ) ,
757
760
} ) ;
758
761
}
759
- } ;
762
+ }
760
763
}
761
764
}
762
765
}
@@ -1456,7 +1459,6 @@ mod tests {
1456
1459
Tok :: Int { value: BigInt :: from( 99 ) } ,
1457
1460
Tok :: Newline ,
1458
1461
Tok :: Dedent ,
1459
- Tok :: Newline ,
1460
1462
]
1461
1463
) ;
1462
1464
}
@@ -1501,7 +1503,6 @@ mod tests {
1501
1503
Tok :: Newline ,
1502
1504
Tok :: Dedent ,
1503
1505
Tok :: Dedent ,
1504
- Tok :: Newline ,
1505
1506
]
1506
1507
) ;
1507
1508
}
@@ -1540,7 +1541,6 @@ mod tests {
1540
1541
Tok :: Newline ,
1541
1542
Tok :: Dedent ,
1542
1543
Tok :: Dedent ,
1543
- Tok :: Newline ,
1544
1544
]
1545
1545
) ;
1546
1546
}
@@ -1580,7 +1580,6 @@ mod tests {
1580
1580
Tok :: Int { value: BigInt :: from( 2 ) } ,
1581
1581
Tok :: Rsqb ,
1582
1582
Tok :: Newline ,
1583
- Tok :: Newline ,
1584
1583
]
1585
1584
) ;
1586
1585
}
0 commit comments