mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Support unicode escapes
This commit is contained in:
parent
0c9cfa9570
commit
adbe64fffc
4 changed files with 25 additions and 1 deletions
|
@ -624,6 +624,15 @@ Lexeme Lexer::readInterpolatedStringSection(Position start, Lexeme::Type formatT
|
||||||
return Lexeme(Location(start, position()), Lexeme::BrokenString);
|
return Lexeme(Location(start, position()), Lexeme::BrokenString);
|
||||||
|
|
||||||
case '\\':
|
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();
|
readBackslashInString();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -1639,7 +1639,7 @@ struct Compiler
|
||||||
|
|
||||||
RegScope rs(this);
|
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);
|
emitLoadK(baseReg, formatStringIndex);
|
||||||
|
|
||||||
|
|
|
@ -175,4 +175,17 @@ TEST_CASE("string_interpolation_unmatched_brace")
|
||||||
CHECK_EQ(lexer.next().type, '}');
|
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();
|
TEST_SUITE_END();
|
||||||
|
|
|
@ -61,4 +61,6 @@ end
|
||||||
assertEq(identity`text`, "text")
|
assertEq(identity`text`, "text")
|
||||||
assertEq(identity`foo{"bar"}`, "foobar")
|
assertEq(identity`foo{"bar"}`, "foobar")
|
||||||
|
|
||||||
|
assertEq(`\u{0041}\t`, "A\t")
|
||||||
|
|
||||||
return "OK"
|
return "OK"
|
||||||
|
|
Loading…
Add table
Reference in a new issue