@@ -241,59 +241,23 @@ where
241
241
242
242
// Lexer helper functions:
243
243
fn lex_identifier ( & mut self ) -> LexResult {
244
- let mut name = String :: new ( ) ;
245
- let start_pos = self . get_pos ( ) ;
246
-
247
244
// Detect potential string like rb'' b'' f'' u'' r''
248
- let mut saw_b = false ;
249
- let mut saw_r = false ;
250
- let mut saw_u = false ;
251
- let mut saw_f = false ;
252
- loop {
253
- // Detect r"", f"", b"" and u""
254
- if !( saw_b || saw_u || saw_f) && matches ! ( self . window[ 0 ] , Some ( 'b' | 'B' ) ) {
255
- saw_b = true ;
256
- } else if !( saw_b || saw_r || saw_u || saw_f)
257
- && matches ! ( self . window[ 0 ] , Some ( 'u' | 'U' ) )
258
- {
259
- saw_u = true ;
260
- } else if !( saw_r || saw_u) && matches ! ( self . window[ 0 ] , Some ( 'r' | 'R' ) ) {
261
- saw_r = true ;
262
- } else if !( saw_b || saw_u || saw_f) && matches ! ( self . window[ 0 ] , Some ( 'f' | 'F' ) ) {
263
- saw_f = true ;
264
- } else {
265
- break ;
245
+ match self . window [ ..3 ] {
246
+ [ Some ( c) , Some ( '"' | '\'' ) , ..] => {
247
+ if let Ok ( kind) = c. to_string ( ) . try_into ( ) {
248
+ return self . lex_string ( kind) ;
249
+ }
266
250
}
267
-
268
- // Take up char into name:
269
- name. push ( self . next_char ( ) . unwrap ( ) ) ;
270
-
271
- // Check if we have a string:
272
- if matches ! ( self . window[ 0 ] , Some ( '"' | '\'' ) ) {
273
- let kind = if saw_r {
274
- if saw_b {
275
- StringKind :: RawBytes
276
- } else if saw_f {
277
- StringKind :: RawFString
278
- } else {
279
- StringKind :: RawString
280
- }
281
- } else if saw_b {
282
- StringKind :: Bytes
283
- } else if saw_u {
284
- StringKind :: Unicode
285
- } else if saw_f {
286
- StringKind :: FString
287
- } else {
288
- StringKind :: String
289
- } ;
290
-
291
- return self
292
- . lex_string ( kind)
293
- . map ( |( _, tok, end_pos) | ( start_pos, tok, end_pos) ) ;
251
+ [ Some ( c1) , Some ( c2) , Some ( '"' | '\'' ) ] => {
252
+ if let Ok ( kind) = format ! ( "{c1}{c2}" ) . try_into ( ) {
253
+ return self . lex_string ( kind) ;
254
+ }
294
255
}
295
- }
256
+ _ => { }
257
+ } ;
296
258
259
+ let start_pos = self . get_pos ( ) ;
260
+ let mut name = String :: new ( ) ;
297
261
while self . is_identifier_continuation ( ) {
298
262
name. push ( self . next_char ( ) . unwrap ( ) ) ;
299
263
}
@@ -495,6 +459,9 @@ where
495
459
496
460
fn lex_string ( & mut self , kind : StringKind ) -> LexResult {
497
461
let start_pos = self . get_pos ( ) ;
462
+ for _ in 0 ..kind. to_string ( ) . len ( ) {
463
+ self . next_char ( ) ;
464
+ }
498
465
let quote_char = self . next_char ( ) . unwrap ( ) ;
499
466
let mut string_content = String :: new ( ) ;
500
467
0 commit comments