4
4
pub use super :: token:: Tok ;
5
5
use num_bigint:: BigInt ;
6
6
use num_traits:: Num ;
7
+ use std:: cmp:: Ordering ;
7
8
use std:: collections:: HashMap ;
8
9
use std:: str:: FromStr ;
9
- use std:: cmp:: Ordering ;
10
10
11
11
#[ derive( Clone , Copy , PartialEq , Debug ) ]
12
12
struct IndentationLevel {
@@ -16,10 +16,7 @@ struct IndentationLevel {
16
16
17
17
impl IndentationLevel {
18
18
fn new ( ) -> IndentationLevel {
19
- IndentationLevel {
20
- tabs : 0 ,
21
- spaces : 0 ,
22
- }
19
+ IndentationLevel { tabs : 0 , spaces : 0 }
23
20
}
24
21
fn compare_strict ( & self , other : & IndentationLevel ) -> Option < Ordering > {
25
22
// We only know for sure that we're smaller or bigger if tabs
@@ -37,7 +34,6 @@ impl IndentationLevel {
37
34
} else {
38
35
None
39
36
}
40
-
41
37
} else {
42
38
Some ( self . spaces . cmp ( & other. spaces ) )
43
39
}
@@ -620,7 +616,7 @@ where
620
616
Some ( ' ' ) => {
621
617
self . next_char ( ) ;
622
618
spaces += 1 ;
623
- } ,
619
+ }
624
620
Some ( '\t' ) => {
625
621
if spaces != 0 {
626
622
// Don't allow tabs after spaces as part of indentation.
@@ -630,7 +626,7 @@ where
630
626
}
631
627
self . next_char ( ) ;
632
628
tabs += 1 ;
633
- } ,
629
+ }
634
630
Some ( '#' ) => {
635
631
self . lex_comment ( ) ;
636
632
self . at_begin_of_line = true ;
@@ -649,10 +645,7 @@ where
649
645
}
650
646
}
651
647
652
- let indentation_level = IndentationLevel {
653
- spaces,
654
- tabs,
655
- } ;
648
+ let indentation_level = IndentationLevel { spaces, tabs } ;
656
649
657
650
if self . nesting == 0 {
658
651
// Determine indent or dedent:
@@ -661,7 +654,7 @@ where
661
654
match ordering {
662
655
Some ( Ordering :: Equal ) => {
663
656
// Same same
664
- } ,
657
+ }
665
658
Some ( Ordering :: Greater ) => {
666
659
// New indentation level:
667
660
self . indentation_stack . push ( indentation_level) ;
@@ -674,18 +667,21 @@ where
674
667
// Pop off other levels until col is found:
675
668
676
669
loop {
677
- let ordering = indentation_level. compare_strict ( self . indentation_stack . last ( ) . unwrap ( ) ) ;
670
+ let ordering = indentation_level
671
+ . compare_strict ( self . indentation_stack . last ( ) . unwrap ( ) ) ;
678
672
match ordering {
679
673
Some ( Ordering :: Less ) => {
680
674
self . indentation_stack . pop ( ) ;
681
675
let tok_start = self . get_pos ( ) ;
682
676
let tok_end = tok_start. clone ( ) ;
683
677
self . pending . push ( Ok ( ( tok_start, Tok :: Dedent , tok_end) ) ) ;
684
- } ,
685
- None => panic ! ( "inconsistent use of tabs and spaces in indentation" ) ,
678
+ }
679
+ None => {
680
+ panic ! ( "inconsistent use of tabs and spaces in indentation" )
681
+ }
686
682
_ => {
687
683
break ;
688
- } ,
684
+ }
689
685
} ;
690
686
}
691
687
0 commit comments