@@ -727,44 +727,46 @@ where
727727 fn handle_indentations ( & mut self ) -> Result < ( ) , LexicalError > {
728728 let indentation_level = self . eat_indentation ( ) ?;
729729
730- if self . nesting == 0 {
731- // Determine indent or dedent:
732- let current_indentation = self . indentation_stack . last ( ) . unwrap ( ) ;
733- let ordering = indentation_level. compare_strict ( current_indentation, self . get_pos ( ) ) ?;
734- match ordering {
735- Ordering :: Equal => {
736- // Same same
737- }
738- Ordering :: Greater => {
739- // New indentation level:
740- self . indentation_stack . push ( indentation_level) ;
741- let tok_pos = self . get_pos ( ) ;
742- self . emit ( ( tok_pos, Tok :: Indent , tok_pos) ) ;
743- }
744- Ordering :: Less => {
745- // One or more dedentations
746- // Pop off other levels until col is found:
747-
748- loop {
749- let current_indentation = self . indentation_stack . last ( ) . unwrap ( ) ;
750- let ordering = indentation_level
751- . compare_strict ( current_indentation, self . get_pos ( ) ) ?;
752- match ordering {
753- Ordering :: Less => {
754- self . indentation_stack . pop ( ) ;
755- let tok_pos = self . get_pos ( ) ;
756- self . emit ( ( tok_pos, Tok :: Dedent , tok_pos) ) ;
757- }
758- Ordering :: Equal => {
759- // We arrived at proper level of indentation.
760- break ;
761- }
762- Ordering :: Greater => {
763- return Err ( LexicalError {
764- error : LexicalErrorType :: IndentationError ,
765- location : self . get_pos ( ) ,
766- } ) ;
767- }
730+ if self . nesting != 0 {
731+ return Ok ( ( ) ) ;
732+ }
733+
734+ // Determine indent or dedent:
735+ let current_indentation = self . indentation_stack . last ( ) . unwrap ( ) ;
736+ let ordering = indentation_level. compare_strict ( current_indentation, self . get_pos ( ) ) ?;
737+ match ordering {
738+ Ordering :: Equal => {
739+ // Same same
740+ }
741+ Ordering :: Greater => {
742+ // New indentation level:
743+ self . indentation_stack . push ( indentation_level) ;
744+ let tok_pos = self . get_pos ( ) ;
745+ self . emit ( ( tok_pos, Tok :: Indent , tok_pos) ) ;
746+ }
747+ Ordering :: Less => {
748+ // One or more dedentations
749+ // Pop off other levels until col is found:
750+
751+ loop {
752+ let current_indentation = self . indentation_stack . last ( ) . unwrap ( ) ;
753+ let ordering =
754+ indentation_level. compare_strict ( current_indentation, self . get_pos ( ) ) ?;
755+ match ordering {
756+ Ordering :: Less => {
757+ self . indentation_stack . pop ( ) ;
758+ let tok_pos = self . get_pos ( ) ;
759+ self . emit ( ( tok_pos, Tok :: Dedent , tok_pos) ) ;
760+ }
761+ Ordering :: Equal => {
762+ // We arrived at proper level of indentation.
763+ break ;
764+ }
765+ Ordering :: Greater => {
766+ return Err ( LexicalError {
767+ error : LexicalErrorType :: IndentationError ,
768+ location : self . get_pos ( ) ,
769+ } ) ;
768770 }
769771 }
770772 }
0 commit comments