mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Remove copy paste (though I'm not sure it's much better), start work on {{ parse failure
This commit is contained in:
parent
5a9de6ba0a
commit
6cb9054c07
4 changed files with 39 additions and 36 deletions
|
@ -218,6 +218,7 @@ private:
|
|||
Lexeme readQuotedString();
|
||||
|
||||
Lexeme readInterpolatedStringBegin();
|
||||
std::optional<Lexeme> readInterpolatedStringSection(Position start, Lexeme::Type formatType);
|
||||
|
||||
void readBackslashInString();
|
||||
|
||||
|
|
|
@ -602,35 +602,15 @@ Lexeme Lexer::readQuotedString()
|
|||
|
||||
const Lexeme Lexer::nextInterpolatedString()
|
||||
{
|
||||
// INTERP TODO: This is a copy-paste
|
||||
Position start = position();
|
||||
|
||||
unsigned int startOffset = offset;
|
||||
|
||||
while (peekch() != '`')
|
||||
std::optional<Lexeme> readSectionOpt = readInterpolatedStringSection(start, Lexeme::InterpStringMid);
|
||||
|
||||
if (auto readSection = readSectionOpt)
|
||||
{
|
||||
switch (peekch())
|
||||
{
|
||||
case 0:
|
||||
case '\r':
|
||||
case '\n':
|
||||
lexeme = Lexeme(Location(start, position()), Lexeme::BrokenString);
|
||||
return lexeme;
|
||||
|
||||
case '\\':
|
||||
readBackslashInString();
|
||||
break;
|
||||
|
||||
case '{':
|
||||
incrementInterpolatedStringDepth();
|
||||
|
||||
lexeme = Lexeme(Location(start, position()), Lexeme::InterpStringMid, &buffer[startOffset], offset - startOffset);
|
||||
consume();
|
||||
return lexeme;
|
||||
|
||||
default:
|
||||
consume();
|
||||
}
|
||||
lexeme = *readSection;
|
||||
return lexeme;
|
||||
}
|
||||
|
||||
consume();
|
||||
|
@ -642,9 +622,20 @@ const Lexeme Lexer::nextInterpolatedString()
|
|||
Lexeme Lexer::readInterpolatedStringBegin()
|
||||
{
|
||||
Position start = position();
|
||||
|
||||
consume();
|
||||
|
||||
std::optional<Lexeme> readSectionOpt = readInterpolatedStringSection(start, Lexeme::InterpStringBegin);
|
||||
|
||||
if (!readSectionOpt)
|
||||
{
|
||||
LUAU_ASSERT(!"INTERP TODO: Error if there was no interpolated expression");
|
||||
}
|
||||
|
||||
return *readSectionOpt;
|
||||
}
|
||||
|
||||
std::optional<Lexeme> Lexer::readInterpolatedStringSection(Position start, Lexeme::Type formatType)
|
||||
{
|
||||
unsigned int startOffset = offset;
|
||||
|
||||
while (peekch() != '`')
|
||||
|
@ -654,27 +645,26 @@ Lexeme Lexer::readInterpolatedStringBegin()
|
|||
case 0:
|
||||
case '\r':
|
||||
case '\n':
|
||||
return Lexeme(Location(start, position()), Lexeme::BrokenString);
|
||||
return std::optional(Lexeme(Location(start, position()), Lexeme::BrokenString));
|
||||
|
||||
case '\\':
|
||||
readBackslashInString();
|
||||
break;
|
||||
|
||||
case '{':
|
||||
{
|
||||
incrementInterpolatedStringDepth();
|
||||
lexeme = Lexeme(Location(start, position()), Lexeme::InterpStringBegin, &buffer[startOffset], offset - startOffset);
|
||||
auto lexemeOutput = Lexeme(Location(start, position()), Lexeme::InterpStringBegin, &buffer[startOffset], offset - startOffset);
|
||||
consume();
|
||||
return lexeme;
|
||||
return std::optional(lexemeOutput);
|
||||
}
|
||||
|
||||
default:
|
||||
consume();
|
||||
}
|
||||
}
|
||||
|
||||
consume();
|
||||
|
||||
// INTERP TODO: Error if there was no interpolated expression
|
||||
LUAU_ASSERT(!"INTERP TODO: interpolated string without ending");
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
Lexeme Lexer::readNumber(const Position& start, unsigned int startOffset)
|
||||
|
|
|
@ -1034,6 +1034,21 @@ TEST_CASE_FIXTURE(Fixture, "parse_compound_assignment_error_multiple")
|
|||
}
|
||||
}
|
||||
|
||||
TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_double_brace")
|
||||
{
|
||||
try
|
||||
{
|
||||
parse(R"(
|
||||
_ = `{{oops}}`
|
||||
)");
|
||||
FAIL("Expected ParseErrors to be thrown");
|
||||
}
|
||||
catch (const ParseErrors& e)
|
||||
{
|
||||
CHECK_EQ("INTERP TODO: Message", e.getErrors().front().getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE_FIXTURE(Fixture, "parse_nesting_based_end_detection")
|
||||
{
|
||||
try
|
||||
|
|
|
@ -18,9 +18,6 @@ assertEq(`The lock combinations are: {table.concat(combo, ", ")}`, "The lock com
|
|||
|
||||
assertEq(`true = {true}`, "true = true")
|
||||
|
||||
-- -- INTERP TODO: Syntax error
|
||||
-- -- assert(string.find(`{{ "nested braces!" }}`, "table"))
|
||||
|
||||
local name = "Luau"
|
||||
assertEq(`Welcome to {
|
||||
name
|
||||
|
|
Loading…
Add table
Reference in a new issue