File tree Expand file tree Collapse file tree 1 file changed +3
-10
lines changed Expand file tree Collapse file tree 1 file changed +3
-10
lines changed Original file line number Diff line number Diff line change @@ -34,24 +34,17 @@ impl Parser {
34
34
}
35
35
36
36
fn peek ( & self ) -> char {
37
- if !self . at_end ( ) {
38
- return self . input . chars ( ) . nth ( self . pos + 1 ) . expect ( "couldn't peek" ) ;
39
- }
40
- '\0'
37
+ self . input . chars ( ) . nth ( self . pos + 1 ) . unwrap_or ( '\0' )
41
38
}
42
39
43
40
fn peek_equals ( & self , character : char ) -> bool {
44
41
self . peek ( ) == character
45
42
}
46
43
47
44
fn advance ( & mut self ) {
48
- if !self . at_end ( ) || self . pos + 1 <= self . input . len ( ) {
45
+ if !self . at_end ( ) && self . pos + 1 <= self . input . len ( ) {
49
46
self . pos += 1 ;
50
- self . current_char = self
51
- . input
52
- . chars ( )
53
- . nth ( self . pos )
54
- . expect ( "could not get next character" ) ;
47
+ self . current_char = self . input . chars ( ) . nth ( self . pos ) . unwrap_or ( '\0' ) ;
55
48
self . line_pos += 1 ;
56
49
}
57
50
}
You can’t perform that action at this time.
0 commit comments