Support unicode escapes

This commit is contained in:
Kampfkarren 2022-08-22 15:22:28 -07:00
parent 0c9cfa9570
commit adbe64fffc
4 changed files with 25 additions and 1 deletions

View file

@ -624,6 +624,15 @@ Lexeme Lexer::readInterpolatedStringSection(Position start, Lexeme::Type formatT
return Lexeme(Location(start, position()), Lexeme::BrokenString);
case '\\':
// Allow for \u{}, which would otherwise be consumed by looking for {
if (peekch(1) == 'u' && peekch(2) == '{')
{
consume(); // backslash
consume(); // u
consume(); // {
break;
}
readBackslashInString();
break;

View file

@ -1639,7 +1639,7 @@ struct Compiler
RegScope rs(this);
uint8_t baseReg = allocReg(expr, 2 + expr->expressions.size);
uint8_t baseReg = allocReg(expr, uint8_t(2 + expr->expressions.size));
emitLoadK(baseReg, formatStringIndex);

View file

@ -175,4 +175,17 @@ TEST_CASE("string_interpolation_unmatched_brace")
CHECK_EQ(lexer.next().type, '}');
}
TEST_CASE("string_interpolation_with_unicode_escape")
{
ScopedFastFlag sff{"LuauInterpolatedStringBaseSupport", true};
const std::string testInput = R"(`\u{1F41B}`)";
Luau::Allocator alloc;
AstNameTable table(alloc);
Lexer lexer(testInput.c_str(), testInput.size(), table);
CHECK_EQ(lexer.next().type, Lexeme::InterpStringSimple);
CHECK_EQ(lexer.next().type, Lexeme::Eof);
}
TEST_SUITE_END();

View file

@ -61,4 +61,6 @@ end
assertEq(identity`text`, "text")
assertEq(identity`foo{"bar"}`, "foobar")
assertEq(`\u{0041}\t`, "A\t")
return "OK"