@@ -56,7 +56,7 @@ pub(crate) fn number(cursor: &mut Cursor, first_digit: char) -> LiteralKind {
56
56
let mut base = Base :: Decimal ;
57
57
if first_digit == '0' {
58
58
// Attempt to parse encoding base.
59
- let has_digits = match cursor. first ( ) {
59
+ let has_digits = match cursor. peek ( ) {
60
60
'b' => {
61
61
base = Base :: Binary ;
62
62
cursor. bump ( ) ;
@@ -90,18 +90,18 @@ pub(crate) fn number(cursor: &mut Cursor, first_digit: char) -> LiteralKind {
90
90
eat_decimal_digits ( cursor) ;
91
91
} ;
92
92
93
- match cursor. first ( ) {
93
+ match cursor. peek ( ) {
94
94
// Don't be greedy if this is actually an
95
95
// integer literal followed by field/method access or a range pattern
96
96
// (`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 ( ) ) => {
98
98
// might have stuff after the ., and if it does, it needs to start
99
99
// with a number
100
100
cursor. bump ( ) ;
101
101
let mut empty_exponent = false ;
102
- if cursor. first ( ) . is_digit ( 10 ) {
102
+ if cursor. peek ( ) . is_digit ( 10 ) {
103
103
eat_decimal_digits ( cursor) ;
104
- match cursor. first ( ) {
104
+ match cursor. peek ( ) {
105
105
'e' | 'E' => {
106
106
cursor. bump ( ) ;
107
107
empty_exponent = !eat_float_exponent ( cursor) ;
@@ -123,7 +123,7 @@ pub(crate) fn number(cursor: &mut Cursor, first_digit: char) -> LiteralKind {
123
123
pub ( crate ) fn eat_decimal_digits ( cursor : & mut Cursor ) -> bool {
124
124
let mut has_digits = false ;
125
125
loop {
126
- match cursor. first ( ) {
126
+ match cursor. peek ( ) {
127
127
'_' => {
128
128
cursor. bump ( ) ;
129
129
}
@@ -140,7 +140,7 @@ pub(crate) fn eat_decimal_digits(cursor: &mut Cursor) -> bool {
140
140
pub ( crate ) fn eat_hexadecimal_digits ( cursor : & mut Cursor ) -> bool {
141
141
let mut has_digits = false ;
142
142
loop {
143
- match cursor. first ( ) {
143
+ match cursor. peek ( ) {
144
144
'_' => {
145
145
cursor. bump ( ) ;
146
146
}
@@ -158,7 +158,7 @@ pub(crate) fn eat_hexadecimal_digits(cursor: &mut Cursor) -> bool {
158
158
/// and returns false otherwise.
159
159
fn eat_float_exponent ( cursor : & mut Cursor ) -> bool {
160
160
debug_assert ! ( cursor. prev( ) == 'e' || cursor. prev( ) == 'E' ) ;
161
- if cursor. first ( ) == '-' || cursor. first ( ) == '+' {
161
+ if cursor. peek ( ) == '-' || cursor. peek ( ) == '+' {
162
162
cursor. bump ( ) ;
163
163
}
164
164
eat_decimal_digits ( cursor)
@@ -167,14 +167,14 @@ fn eat_float_exponent(cursor: &mut Cursor) -> bool {
167
167
pub ( crate ) fn lifetime_or_char ( cursor : & mut Cursor ) -> TokenKind {
168
168
debug_assert ! ( cursor. prev( ) == '\'' ) ;
169
169
170
- let can_be_a_lifetime = if cursor. second ( ) == '\'' {
170
+ let can_be_a_lifetime = if cursor. peek_second ( ) == '\'' {
171
171
// It's surely not a lifetime.
172
172
false
173
173
} else {
174
174
// If the first symbol is valid for identifier, it can be a lifetime.
175
175
// Also check if it's a number for a better error reporting (so '0 will
176
176
// 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 )
178
178
} ;
179
179
180
180
if !can_be_a_lifetime {
@@ -190,18 +190,18 @@ pub(crate) fn lifetime_or_char(cursor: &mut Cursor) -> TokenKind {
190
190
// Either a lifetime or a character literal with
191
191
// length greater than 1.
192
192
193
- let starts_with_number = cursor. first ( ) . is_digit ( 10 ) ;
193
+ let starts_with_number = cursor. peek ( ) . is_digit ( 10 ) ;
194
194
195
195
// Skip the literal contents.
196
196
// First symbol can be a number (which isn't a valid identifier start),
197
197
// so skip it without any checks.
198
198
cursor. bump ( ) ;
199
- cursor. eat_while ( is_id_continue) ;
199
+ cursor. bump_while ( is_id_continue) ;
200
200
201
201
// Check if after skipping literal contents we've met a closing
202
202
// single quote (which means that user attempted to create a
203
203
// string with single quotes).
204
- if cursor. first ( ) == '\'' {
204
+ if cursor. peek ( ) == '\'' {
205
205
cursor. bump ( ) ;
206
206
let kind = LiteralKind :: Char { terminated : true } ;
207
207
TokenKind :: Literal { kind, suffix_start : cursor. len_consumed ( ) }
@@ -213,7 +213,7 @@ pub(crate) fn lifetime_or_char(cursor: &mut Cursor) -> TokenKind {
213
213
pub ( crate ) fn single_quoted_string ( cursor : & mut Cursor ) -> bool {
214
214
debug_assert ! ( cursor. prev( ) == '\'' ) ;
215
215
// Check if it's a one-symbol literal.
216
- if cursor. second ( ) == '\'' && cursor. first ( ) != '\\' {
216
+ if cursor. peek_second ( ) == '\'' && cursor. peek ( ) != '\\' {
217
217
cursor. bump ( ) ;
218
218
cursor. bump ( ) ;
219
219
return true ;
@@ -223,7 +223,7 @@ pub(crate) fn single_quoted_string(cursor: &mut Cursor) -> bool {
223
223
224
224
// Parse until either quotes are terminated or error is detected.
225
225
loop {
226
- match cursor. first ( ) {
226
+ match cursor. peek ( ) {
227
227
// Quotes are terminated, finish parsing.
228
228
'\'' => {
229
229
cursor. bump ( ) ;
@@ -233,7 +233,7 @@ pub(crate) fn single_quoted_string(cursor: &mut Cursor) -> bool {
233
233
// to the error report.
234
234
'/' => break ,
235
235
// Newline without following '\'' means unclosed quote, stop parsing.
236
- '\n' if cursor. second ( ) != '\'' => break ,
236
+ '\n' if cursor. peek_second ( ) != '\'' => break ,
237
237
// End of file, stop parsing.
238
238
EOF_CHAR if cursor. is_eof ( ) => break ,
239
239
// Escaped slash is considered one character, so bump twice.
@@ -260,7 +260,7 @@ pub(crate) fn double_quoted_string(cursor: &mut Cursor) -> bool {
260
260
'"' => {
261
261
return true ;
262
262
}
263
- '\\' if cursor. first ( ) == '\\' || cursor. first ( ) == '"' => {
263
+ '\\' if cursor. peek ( ) == '\\' || cursor. peek ( ) == '"' => {
264
264
// Bump again to skip escaped character.
265
265
cursor. bump ( ) ;
266
266
}
@@ -295,7 +295,7 @@ fn raw_string_unvalidated(cursor: &mut Cursor, prefix_len: usize) -> (usize, Opt
295
295
296
296
// Count opening '#' symbols.
297
297
let mut eaten = 0 ;
298
- while cursor. first ( ) == '#' {
298
+ while cursor. peek ( ) == '#' {
299
299
eaten += 1 ;
300
300
cursor. bump ( ) ;
301
301
}
@@ -313,7 +313,7 @@ fn raw_string_unvalidated(cursor: &mut Cursor, prefix_len: usize) -> (usize, Opt
313
313
// Skip the string contents and on each '#' character met, check if this is
314
314
// a raw string termination.
315
315
loop {
316
- cursor. eat_while ( |c| c != '"' ) ;
316
+ cursor. bump_while ( |c| c != '"' ) ;
317
317
318
318
if cursor. is_eof ( ) {
319
319
return (
@@ -335,7 +335,7 @@ fn raw_string_unvalidated(cursor: &mut Cursor, prefix_len: usize) -> (usize, Opt
335
335
// `r###"abcde"####` is lexed as a `RawStr { n_hashes: 3 }`
336
336
// followed by a `#` token.
337
337
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 {
339
339
n_end_hashes += 1 ;
340
340
cursor. bump ( ) ;
341
341
}
0 commit comments