mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Make {{ a parse error
This commit is contained in:
parent
6cb9054c07
commit
f8be1070c3
4 changed files with 34 additions and 3 deletions
|
@ -84,6 +84,9 @@ struct Lexeme
|
|||
BrokenString,
|
||||
BrokenComment,
|
||||
BrokenUnicode,
|
||||
|
||||
BrokenInterpDoubleBrace,
|
||||
|
||||
Error,
|
||||
|
||||
Reserved_BEGIN,
|
||||
|
|
|
@ -184,6 +184,9 @@ std::string Lexeme::toString() const
|
|||
case BrokenComment:
|
||||
return "unfinished comment";
|
||||
|
||||
case BrokenInterpDoubleBrace:
|
||||
return "'{{', which is invalid (did you mean '\\{'?)";
|
||||
|
||||
case BrokenUnicode:
|
||||
if (codepoint)
|
||||
{
|
||||
|
@ -653,6 +656,11 @@ std::optional<Lexeme> Lexer::readInterpolatedStringSection(Position start, Lexem
|
|||
|
||||
case '{':
|
||||
{
|
||||
if (peekch(1) == '{')
|
||||
{
|
||||
return std::optional(Lexeme(Location(start, position()), Lexeme::BrokenInterpDoubleBrace));
|
||||
}
|
||||
|
||||
incrementInterpolatedStringDepth();
|
||||
auto lexemeOutput = Lexeme(Location(start, position()), Lexeme::InterpStringBegin, &buffer[startOffset], offset - startOffset);
|
||||
consume();
|
||||
|
|
|
@ -2676,9 +2676,13 @@ AstExpr* Parser::parseInterpString()
|
|||
lexer.decrementInterpolatedStringDepth();
|
||||
|
||||
auto next = lexer.nextInterpolatedString();
|
||||
if (next.type == Lexeme::BrokenString)
|
||||
|
||||
switch (next.type)
|
||||
{
|
||||
case Lexeme::BrokenString:
|
||||
return reportExprError(location, {}, "Malformed interpolated string");
|
||||
case Lexeme::BrokenInterpDoubleBrace:
|
||||
return reportExprError(location, {}, "Double braces are not permitted within interpolated strings. Did you mean '\\{'?");
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
|
|
|
@ -1034,7 +1034,7 @@ TEST_CASE_FIXTURE(Fixture, "parse_compound_assignment_error_multiple")
|
|||
}
|
||||
}
|
||||
|
||||
TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_double_brace")
|
||||
TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_double_brace_begin")
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -1045,7 +1045,23 @@ TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_double_brace")
|
|||
}
|
||||
catch (const ParseErrors& e)
|
||||
{
|
||||
CHECK_EQ("INTERP TODO: Message", e.getErrors().front().getMessage());
|
||||
CHECK_EQ("Expected identifier when parsing expression, got '{{', which is invalid (did you mean '\\{'?)", e.getErrors().front().getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_double_brace_mid")
|
||||
{
|
||||
try
|
||||
{
|
||||
parse(R"(
|
||||
_ = `{nice} {{oops}}`
|
||||
)");
|
||||
FAIL("Expected ParseErrors to be thrown");
|
||||
}
|
||||
catch (const ParseErrors& e)
|
||||
{
|
||||
// INTERP CODE REVIEW: It's weird for these two to have separate messages, but the one created by _begin is emergent from something else.
|
||||
CHECK_EQ("Double braces are not permitted within interpolated strings. Did you mean '\\{'?", e.getErrors().front().getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue