File tree 1 file changed +21
-21
lines changed
1 file changed +21
-21
lines changed Original file line number Diff line number Diff line change @@ -561,40 +561,40 @@ impl Parser {
561
561
562
562
/// Return first non-whitespace token that has not yet been processed
563
563
pub fn peek_token ( & self ) -> Option < Token > {
564
- if let Some ( n) = self . til_non_whitespace ( ) {
565
- self . token_at ( n)
566
- } else {
567
- None
568
- }
564
+ self . peek_nth_token ( 0 )
569
565
}
570
566
571
- /// Get the next token skipping whitespace and increment the token index
572
- pub fn next_token ( & mut self ) -> Option < Token > {
567
+ /// Return nth non-whitespace token that has not yet been processed
568
+ pub fn peek_nth_token ( & self , mut n : usize ) -> Option < Token > {
569
+ let mut index = self . index ;
573
570
loop {
574
- match self . next_token_no_skip ( ) {
571
+ match self . token_at ( index ) {
575
572
Some ( Token :: Whitespace ( _) ) => {
576
- continue ;
573
+ index += 1 ;
577
574
}
578
- token => {
579
- return token;
575
+ Some ( token) => {
576
+ if n == 0 {
577
+ return Some ( token) ;
578
+ }
579
+ index += 1 ;
580
+ n -= 1 ;
581
+ }
582
+ None => {
583
+ return None ;
580
584
}
581
585
}
582
586
}
583
587
}
584
588
585
- /// get the index for non whitepsace token
586
- fn til_non_whitespace ( & self ) -> Option < usize > {
587
- let mut index = self . index ;
589
+ /// Get the next token skipping whitespace and increment the token index
590
+ pub fn next_token ( & mut self ) -> Option < Token > {
588
591
loop {
589
- match self . token_at ( index ) {
592
+ match self . next_token_no_skip ( ) {
590
593
Some ( Token :: Whitespace ( _) ) => {
591
- index += 1 ;
592
- }
593
- Some ( _) => {
594
- return Some ( index) ;
594
+ continue ;
595
595
}
596
- None => {
597
- return None ;
596
+ token => {
597
+ return token ;
598
598
}
599
599
}
600
600
}
You can’t perform that action at this time.
0 commit comments