@@ -56,7 +56,7 @@ pub(crate) fn number(cursor: &mut Cursor, first_digit: char) -> LiteralKind {
5656 let mut base = Base :: Decimal ;
5757 if first_digit == '0' {
5858 // Attempt to parse encoding base.
59- let has_digits = match cursor. first ( ) {
59+ let has_digits = match cursor. peek ( ) {
6060 'b' => {
6161 base = Base :: Binary ;
6262 cursor. bump ( ) ;
@@ -90,18 +90,18 @@ pub(crate) fn number(cursor: &mut Cursor, first_digit: char) -> LiteralKind {
9090 eat_decimal_digits ( cursor) ;
9191 } ;
9292
93- match cursor. first ( ) {
93+ match cursor. peek ( ) {
9494 // Don't be greedy if this is actually an
9595 // integer literal followed by field/method access or a range pattern
9696 // (`0..2` and `12.foo()`)
97- '.' if cursor. second ( ) != '.' && !is_id_start ( cursor. second ( ) ) => {
97+ '.' if cursor. peek_second ( ) != '.' && !is_id_start ( cursor. peek_second ( ) ) => {
9898 // might have stuff after the ., and if it does, it needs to start
9999 // with a number
100100 cursor. bump ( ) ;
101101 let mut empty_exponent = false ;
102- if cursor. first ( ) . is_digit ( 10 ) {
102+ if cursor. peek ( ) . is_digit ( 10 ) {
103103 eat_decimal_digits ( cursor) ;
104- match cursor. first ( ) {
104+ match cursor. peek ( ) {
105105 'e' | 'E' => {
106106 cursor. bump ( ) ;
107107 empty_exponent = !eat_float_exponent ( cursor) ;
@@ -123,7 +123,7 @@ pub(crate) fn number(cursor: &mut Cursor, first_digit: char) -> LiteralKind {
123123pub ( crate ) fn eat_decimal_digits ( cursor : & mut Cursor ) -> bool {
124124 let mut has_digits = false ;
125125 loop {
126- match cursor. first ( ) {
126+ match cursor. peek ( ) {
127127 '_' => {
128128 cursor. bump ( ) ;
129129 }
@@ -140,7 +140,7 @@ pub(crate) fn eat_decimal_digits(cursor: &mut Cursor) -> bool {
140140pub ( crate ) fn eat_hexadecimal_digits ( cursor : & mut Cursor ) -> bool {
141141 let mut has_digits = false ;
142142 loop {
143- match cursor. first ( ) {
143+ match cursor. peek ( ) {
144144 '_' => {
145145 cursor. bump ( ) ;
146146 }
@@ -158,7 +158,7 @@ pub(crate) fn eat_hexadecimal_digits(cursor: &mut Cursor) -> bool {
158158/// and returns false otherwise.
159159fn eat_float_exponent ( cursor : & mut Cursor ) -> bool {
160160 debug_assert ! ( cursor. prev( ) == 'e' || cursor. prev( ) == 'E' ) ;
161- if cursor. first ( ) == '-' || cursor. first ( ) == '+' {
161+ if cursor. peek ( ) == '-' || cursor. peek ( ) == '+' {
162162 cursor. bump ( ) ;
163163 }
164164 eat_decimal_digits ( cursor)
@@ -167,14 +167,14 @@ fn eat_float_exponent(cursor: &mut Cursor) -> bool {
167167pub ( crate ) fn lifetime_or_char ( cursor : & mut Cursor ) -> TokenKind {
168168 debug_assert ! ( cursor. prev( ) == '\'' ) ;
169169
170- let can_be_a_lifetime = if cursor. second ( ) == '\'' {
170+ let can_be_a_lifetime = if cursor. peek_second ( ) == '\'' {
171171 // It's surely not a lifetime.
172172 false
173173 } else {
174174 // If the first symbol is valid for identifier, it can be a lifetime.
175175 // Also check if it's a number for a better error reporting (so '0 will
176176 // be reported as invalid lifetime and not as unterminated char literal).
177- is_id_start ( cursor. first ( ) ) || cursor. first ( ) . is_digit ( 10 )
177+ is_id_start ( cursor. peek ( ) ) || cursor. peek ( ) . is_digit ( 10 )
178178 } ;
179179
180180 if !can_be_a_lifetime {
@@ -190,18 +190,18 @@ pub(crate) fn lifetime_or_char(cursor: &mut Cursor) -> TokenKind {
190190 // Either a lifetime or a character literal with
191191 // length greater than 1.
192192
193- let starts_with_number = cursor. first ( ) . is_digit ( 10 ) ;
193+ let starts_with_number = cursor. peek ( ) . is_digit ( 10 ) ;
194194
195195 // Skip the literal contents.
196196 // First symbol can be a number (which isn't a valid identifier start),
197197 // so skip it without any checks.
198198 cursor. bump ( ) ;
199- cursor. eat_while ( is_id_continue) ;
199+ cursor. bump_while ( is_id_continue) ;
200200
201201 // Check if after skipping literal contents we've met a closing
202202 // single quote (which means that user attempted to create a
203203 // string with single quotes).
204- if cursor. first ( ) == '\'' {
204+ if cursor. peek ( ) == '\'' {
205205 cursor. bump ( ) ;
206206 let kind = LiteralKind :: Char { terminated : true } ;
207207 TokenKind :: Literal { kind, suffix_start : cursor. len_consumed ( ) }
@@ -213,7 +213,7 @@ pub(crate) fn lifetime_or_char(cursor: &mut Cursor) -> TokenKind {
213213pub ( crate ) fn single_quoted_string ( cursor : & mut Cursor ) -> bool {
214214 debug_assert ! ( cursor. prev( ) == '\'' ) ;
215215 // Check if it's a one-symbol literal.
216- if cursor. second ( ) == '\'' && cursor. first ( ) != '\\' {
216+ if cursor. peek_second ( ) == '\'' && cursor. peek ( ) != '\\' {
217217 cursor. bump ( ) ;
218218 cursor. bump ( ) ;
219219 return true ;
@@ -223,7 +223,7 @@ pub(crate) fn single_quoted_string(cursor: &mut Cursor) -> bool {
223223
224224 // Parse until either quotes are terminated or error is detected.
225225 loop {
226- match cursor. first ( ) {
226+ match cursor. peek ( ) {
227227 // Quotes are terminated, finish parsing.
228228 '\'' => {
229229 cursor. bump ( ) ;
@@ -233,7 +233,7 @@ pub(crate) fn single_quoted_string(cursor: &mut Cursor) -> bool {
233233 // to the error report.
234234 '/' => break ,
235235 // Newline without following '\'' means unclosed quote, stop parsing.
236- '\n' if cursor. second ( ) != '\'' => break ,
236+ '\n' if cursor. peek_second ( ) != '\'' => break ,
237237 // End of file, stop parsing.
238238 EOF_CHAR if cursor. is_eof ( ) => break ,
239239 // Escaped slash is considered one character, so bump twice.
@@ -260,7 +260,7 @@ pub(crate) fn double_quoted_string(cursor: &mut Cursor) -> bool {
260260 '"' => {
261261 return true ;
262262 }
263- '\\' if cursor. first ( ) == '\\' || cursor. first ( ) == '"' => {
263+ '\\' if cursor. peek ( ) == '\\' || cursor. peek ( ) == '"' => {
264264 // Bump again to skip escaped character.
265265 cursor. bump ( ) ;
266266 }
@@ -295,7 +295,7 @@ fn raw_string_unvalidated(cursor: &mut Cursor, prefix_len: usize) -> (usize, Opt
295295
296296 // Count opening '#' symbols.
297297 let mut eaten = 0 ;
298- while cursor. first ( ) == '#' {
298+ while cursor. peek ( ) == '#' {
299299 eaten += 1 ;
300300 cursor. bump ( ) ;
301301 }
@@ -313,7 +313,7 @@ fn raw_string_unvalidated(cursor: &mut Cursor, prefix_len: usize) -> (usize, Opt
313313 // Skip the string contents and on each '#' character met, check if this is
314314 // a raw string termination.
315315 loop {
316- cursor. eat_while ( |c| c != '"' ) ;
316+ cursor. bump_while ( |c| c != '"' ) ;
317317
318318 if cursor. is_eof ( ) {
319319 return (
@@ -335,7 +335,7 @@ fn raw_string_unvalidated(cursor: &mut Cursor, prefix_len: usize) -> (usize, Opt
335335 // `r###"abcde"####` is lexed as a `RawStr { n_hashes: 3 }`
336336 // followed by a `#` token.
337337 let mut n_end_hashes = 0 ;
338- while cursor. first ( ) == '#' && n_end_hashes < n_start_hashes {
338+ while cursor. peek ( ) == '#' && n_end_hashes < n_start_hashes {
339339 n_end_hashes += 1 ;
340340 cursor. bump ( ) ;
341341 }
0 commit comments