@@ -222,12 +222,12 @@ enum InterpolationState {
222
222
/// We are not inside curly braces.
223
223
Outside ,
224
224
/// We are currently scanning the inner part of an interpolation.
225
- Inside ,
225
+ Inside ( u32 ) ,
226
226
}
227
227
228
228
impl InterpolationState {
229
229
fn is_inside ( & self ) -> bool {
230
- matches ! ( self , InterpolationState :: Inside )
230
+ matches ! ( self , InterpolationState :: Inside ( _ ) )
231
231
}
232
232
}
233
233
@@ -595,29 +595,41 @@ impl Tokenizer {
595
595
if self . match_char ( input, '"' ) {
596
596
TokenKind :: StringFixed
597
597
} else if self . match_char ( input, '{' ) {
598
- self . interpolation_state = InterpolationState :: Inside ;
598
+ self . interpolation_state = InterpolationState :: Inside ( 0 ) ;
599
599
self . interpolation_start = self . last ;
600
600
TokenKind :: StringInterpolationStart
601
601
} else {
602
602
return Err ( TokenizerError {
603
603
kind : TokenizerErrorKind :: UnterminatedString ,
604
604
span : Span {
605
- start : self . token_start ,
605
+ start : self . string_start ,
606
606
end : self . current ,
607
607
code_source_id : self . code_source_id ,
608
608
} ,
609
609
} ) ;
610
610
}
611
611
}
612
- InterpolationState :: Inside => {
613
- return Err ( TokenizerError {
614
- kind : TokenizerErrorKind :: UnterminatedStringInterpolation ,
615
- span : Span {
616
- start : self . interpolation_start ,
617
- end : self . last ,
618
- code_source_id : self . code_source_id ,
619
- } ,
620
- } ) ;
612
+ InterpolationState :: Inside ( i) => {
613
+ self . string_start = self . token_start ;
614
+
615
+ self . consume_string ( input) ?;
616
+
617
+ if self . match_char ( input, '"' ) {
618
+ TokenKind :: StringFixed
619
+ } else if self . match_char ( input, '{' ) {
620
+ self . interpolation_state = InterpolationState :: Inside ( i + 1 ) ;
621
+ self . interpolation_start = self . last ;
622
+ TokenKind :: StringInterpolationStart
623
+ } else {
624
+ return Err ( TokenizerError {
625
+ kind : TokenizerErrorKind :: UnterminatedStringInterpolation ,
626
+ span : Span {
627
+ start : self . interpolation_start ,
628
+ end : self . last ,
629
+ code_source_id : self . code_source_id ,
630
+ } ,
631
+ } ) ;
632
+ }
621
633
}
622
634
} ,
623
635
':' if self . interpolation_state . is_inside ( ) => {
@@ -656,7 +668,12 @@ impl Tokenizer {
656
668
self . consume_string ( input) ?;
657
669
658
670
if self . match_char ( input, '"' ) {
659
- self . interpolation_state = InterpolationState :: Outside ;
671
+ match self . interpolation_state {
672
+ InterpolationState :: Inside ( i) if i > 0 => {
673
+ self . interpolation_state = InterpolationState :: Inside ( i - 1 )
674
+ }
675
+ _ => self . interpolation_state = InterpolationState :: Outside ,
676
+ }
660
677
TokenKind :: StringInterpolationEnd
661
678
} else if self . match_char ( input, '{' ) {
662
679
self . interpolation_start = self . last ;
0 commit comments