@@ -537,26 +537,30 @@ impl Cursor<'_> {
537
537
538
538
fn single_quoted_string ( & mut self ) -> bool {
539
539
debug_assert ! ( self . prev( ) == '\'' ) ;
540
- // Parse `'''` as a single char literal.
541
- if self . nth_char ( 0 ) == '\'' && self . nth_char ( 1 ) == '\' ' {
540
+ // Check if it's a one-symbol literal.
541
+ if self . second ( ) == '\'' && self . first ( ) != '\\ ' {
542
542
self . bump ( ) ;
543
+ self . bump ( ) ;
544
+ return true ;
543
545
}
546
+
547
+ // Literal has more than one symbol.
548
+
544
549
// Parse until either quotes are terminated or error is detected.
545
- let mut first = true ;
546
550
loop {
547
551
match self . first ( ) {
548
- // Probably beginning of the comment, which we don't want to include
549
- // to the error report.
550
- '/' if !first => break ,
551
- // Newline without following '\'' means unclosed quote, stop parsing.
552
- '\n' if self . nth_char ( 1 ) != '\'' => break ,
553
- // End of file, stop parsing.
554
- EOF_CHAR if self . is_eof ( ) => break ,
555
552
// Quotes are terminated, finish parsing.
556
553
'\'' => {
557
554
self . bump ( ) ;
558
555
return true ;
559
556
}
557
+ // Probably beginning of the comment, which we don't want to include
558
+ // to the error report.
559
+ '/' => break ,
560
+ // Newline without following '\'' means unclosed quote, stop parsing.
561
+ '\n' if self . second ( ) != '\'' => break ,
562
+ // End of file, stop parsing.
563
+ EOF_CHAR if self . is_eof ( ) => break ,
560
564
// Escaped slash is considered one character, so bump twice.
561
565
'\\' => {
562
566
self . bump ( ) ;
@@ -567,8 +571,8 @@ impl Cursor<'_> {
567
571
self . bump ( ) ;
568
572
}
569
573
}
570
- first = false ;
571
574
}
575
+ // String was not terminated.
572
576
false
573
577
}
574
578
0 commit comments