@@ -49,8 +49,8 @@ pub struct StringReader<'a> {
49
49
/// The current character (which has been read from self.pos)
50
50
pub ch : Option < char > ,
51
51
pub filemap : Lrc < syntax_pos:: FileMap > ,
52
- /// If Some, stop reading the source at this position (inclusive) .
53
- pub terminator : Option < BytePos > ,
52
+ /// Stop reading src at this index .
53
+ pub end_src_index : usize ,
54
54
/// Whether to record new-lines and multibyte chars in filemap.
55
55
/// This is only necessary the first time a filemap is lexed.
56
56
/// If part of a filemap is being re-lexed, this should be set to false.
@@ -113,14 +113,7 @@ impl<'a> StringReader<'a> {
113
113
self . unwrap_or_abort ( res)
114
114
}
115
115
fn is_eof ( & self ) -> bool {
116
- if self . ch . is_none ( ) {
117
- return true ;
118
- }
119
-
120
- match self . terminator {
121
- Some ( t) => self . next_pos > t,
122
- None => false ,
123
- }
116
+ self . ch . is_none ( )
124
117
}
125
118
/// Return the next token. EFFECT: advances the string_reader.
126
119
pub fn try_next_token ( & mut self ) -> Result < TokenAndSpan , ( ) > {
@@ -185,7 +178,7 @@ impl<'a> StringReader<'a> {
185
178
col : CharPos ( 0 ) ,
186
179
ch : Some ( '\n' ) ,
187
180
filemap,
188
- terminator : None ,
181
+ end_src_index : src . len ( ) ,
189
182
save_new_lines_and_multibyte : true ,
190
183
// dummy values; not read
191
184
peek_tok : token:: Eof ,
@@ -222,7 +215,7 @@ impl<'a> StringReader<'a> {
222
215
// Seek the lexer to the right byte range.
223
216
sr. save_new_lines_and_multibyte = false ;
224
217
sr. next_pos = span. lo ( ) ;
225
- sr. terminator = Some ( span. hi ( ) ) ;
218
+ sr. end_src_index = sr . src_index ( span. hi ( ) ) ;
226
219
227
220
sr. bump ( ) ;
228
221
@@ -441,8 +434,7 @@ impl<'a> StringReader<'a> {
441
434
/// discovered, add it to the FileMap's list of line start offsets.
442
435
pub fn bump ( & mut self ) {
443
436
let next_src_index = self . src_index ( self . next_pos ) ;
444
- let end_src_index = self . terminator . map_or ( self . src . len ( ) , |t| self . src_index ( t) ) ;
445
- if next_src_index < end_src_index {
437
+ if next_src_index < self . end_src_index {
446
438
let next_ch = char_at ( & self . src , next_src_index) ;
447
439
let next_ch_len = next_ch. len_utf8 ( ) ;
448
440
@@ -472,7 +464,7 @@ impl<'a> StringReader<'a> {
472
464
473
465
pub fn nextch ( & self ) -> Option < char > {
474
466
let next_src_index = self . src_index ( self . next_pos ) ;
475
- if next_src_index < self . src . len ( ) {
467
+ if next_src_index < self . end_src_index {
476
468
Some ( char_at ( & self . src , next_src_index) )
477
469
} else {
478
470
None
@@ -485,13 +477,12 @@ impl<'a> StringReader<'a> {
485
477
486
478
pub fn nextnextch ( & self ) -> Option < char > {
487
479
let next_src_index = self . src_index ( self . next_pos ) ;
488
- let s = & self . src [ ..] ;
489
- if next_src_index >= s. len ( ) {
480
+ if next_src_index >= self . end_src_index {
490
481
return None ;
491
482
}
492
- let next_next_src_index = next_src_index + char_at ( s , next_src_index) . len_utf8 ( ) ;
493
- if next_next_src_index < s . len ( ) {
494
- Some ( char_at ( s , next_next_src_index) )
483
+ let next_next_src_index = next_src_index + char_at ( & self . src , next_src_index) . len_utf8 ( ) ;
484
+ if next_next_src_index < self . end_src_index {
485
+ Some ( char_at ( & self . src , next_next_src_index) )
495
486
} else {
496
487
None
497
488
}
0 commit comments