ReviewOS

also looking at this

home-lang/home

fix(lexer): leave interpolation mode while scanning string text

#928
Open mkantautas wants to merge fix/lexer-interpolation-invalid-escape into main
2 files +46 -1
packages/lexer/src/lexer.zigmodified+5-1
Changes to packages/lexer/src/lexer.zig
@@ -567,6 +567,10 @@ pub const Lexer = struct {
567567 // The } that closes the interpolation expression was already consumed
568568 // Update start to skip the } for the token lexeme
569569 self.start = self.current;
570 // Scanning string text now, not interpolation code. Only a following
571 // `${` re-enters interpolation, so an invalid escape or unterminated
572 // string cannot leave the lexer counting braces of ordinary code.
573 self.in_interpolation = false;
570574
571575 // Scan until next ${ or closing "
572576 while (!self.isAtEnd()) {
@@ -649,12 +653,12 @@ pub const Lexer = struct {
649653 if (self.peek() == '$' and self.peekNext() == '{') {
650654 _ = self.advance(); // consume $
651655 _ = self.advance(); // consume {
656 self.in_interpolation = true;
652657 self.interpolation_brace_depth = 1;
653658 return self.makeToken(.StringInterpolationMid);
654659 } else {
655660 // Closing "
656661 _ = self.advance();
657 self.in_interpolation = false;
658662 return self.makeToken(.StringInterpolationEnd);
659663 }
660664 }