@ -52,6 +52,8 @@ impl Iterator for Lexer {
c if c . is_ascii_whitespace ( ) = > {
self . cursor . skip_whitespace ( ) ;
self . cursor . chop ( ) ;
self . token_line = self . cursor . line ( ) ;
self . token_col = self . cursor . col ( ) ;
self . next ( ) ?
}
',' = > self . token_ok ( token ::Kind ::Comma ) ,
@ -114,9 +116,6 @@ impl Iterator for Lexer {
c = > self . syntax_error ( format! ( "Unexpected character '{}'" , c ) ) ,
} ;
if let Ok ( token ) = & result {
self . history . push ( token . clone ( ) ) ;
}
Some ( result )
}
}
@ -148,9 +147,13 @@ impl Lexer {
}
pub fn prev ( & mut self ) -> Option < & Token > {
self . offset + = 1 ;
let prev = & self . history [ self . history . len ( ) - self . offset ] ;
Some ( prev )
if self . offset < self . history . len ( ) - 1 {
self . offset + = 1 ;
let prev = & self . history [ self . history . len ( ) - self . offset ] ;
Some ( prev )
} else {
None
}
}
pub fn expect_kind ( & mut self , kind : token ::Kind ) -> Result < Token , Error > {
@ -261,6 +264,7 @@ impl Lexer {
} ;
self . token_line = self . cursor . line ( ) ;
self . token_col = self . cursor . col ( ) ;
self . history . push ( t . clone ( ) ) ;
t
}