mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Interpolated strings as args
This commit is contained in:
parent
90f7bf6f72
commit
08494dc57a
3 changed files with 23 additions and 25 deletions
|
@ -2010,16 +2010,16 @@ AstExpr* Parser::parsePrimaryExpr(bool asStatement)
|
|||
|
||||
expr = parseFunctionArgs(expr, false, Location());
|
||||
}
|
||||
else if (lexer.current().type == '{' || lexer.current().type == Lexeme::RawString || lexer.current().type == Lexeme::QuotedString)
|
||||
else if (
|
||||
lexer.current().type == '{'
|
||||
|| lexer.current().type == Lexeme::RawString
|
||||
|| lexer.current().type == Lexeme::QuotedString
|
||||
|| lexer.current().type == Lexeme::InterpStringBegin
|
||||
|| lexer.current().type == Lexeme::InterpStringEnd
|
||||
)
|
||||
{
|
||||
expr = parseFunctionArgs(expr, false, Location());
|
||||
}
|
||||
else if (lexer.current().type == Lexeme::InterpStringBegin)
|
||||
{
|
||||
report(lexer.current().location, "Interpolated strings cannot be used alone to call a function. Wrap this in parentheses.");
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
|
@ -2256,7 +2256,7 @@ AstExpr* Parser::parseSimpleExpr()
|
|||
}
|
||||
}
|
||||
|
||||
// args ::= `(' [explist] `)' | tableconstructor | String
|
||||
// args ::= `(' [explist] `)' | tableconstructor | String | InterpString
|
||||
AstExpr* Parser::parseFunctionArgs(AstExpr* func, bool self, const Location& selfLocation)
|
||||
{
|
||||
if (lexer.current().type == '(')
|
||||
|
@ -2298,6 +2298,14 @@ AstExpr* Parser::parseFunctionArgs(AstExpr* func, bool self, const Location& sel
|
|||
|
||||
return allocator.alloc<AstExprCall>(Location(func->location, expr->location), func, copy(&expr, 1), self, argLocation);
|
||||
}
|
||||
else if (FFlag::LuauInterpolatedStringBaseSupport && (lexer.current().type == Lexeme::InterpStringBegin || lexer.current().type == Lexeme::InterpStringEnd))
|
||||
{
|
||||
Position argStart = lexer.current().location.end;
|
||||
AstExpr* expr = parseInterpString();
|
||||
Position argEnd = lexer.previousLocation().end;
|
||||
|
||||
return allocator.alloc<AstExprCall>(Location(func->location, expr->location), func, copy(&expr, 1), self, Location(argStart, argEnd));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (self && lexer.current().location.begin.line != func->location.end.line)
|
||||
|
|
|
@ -1093,23 +1093,6 @@ TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_without_end_brace")
|
|||
CHECK_NE(columnOfEndBraceError("_ = `{a`"), columnOfEndBraceError("_ = `{a`"));
|
||||
}
|
||||
|
||||
TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_after_prefixexp")
|
||||
{
|
||||
ScopedFastFlag sff{"LuauInterpolatedStringBaseSupport", true};
|
||||
|
||||
try
|
||||
{
|
||||
parse(R"(
|
||||
print`Hello {name}`
|
||||
)");
|
||||
FAIL("Expected ParseErrors to be thrown");
|
||||
}
|
||||
catch (const ParseErrors& e)
|
||||
{
|
||||
CHECK_EQ("Interpolated strings cannot be used alone to call a function. Wrap this in parentheses.", e.getErrors().front().getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_as_type_fail")
|
||||
{
|
||||
ScopedFastFlag sff{"LuauInterpolatedStringBaseSupport", true};
|
||||
|
|
|
@ -54,4 +54,11 @@ end
|
|||
assertEq(shadowsString("hello"), "Value is hello")
|
||||
assertEq(shadowsString(1), "Value is 1")
|
||||
|
||||
local function identity(x)
|
||||
return x
|
||||
end
|
||||
|
||||
assertEq(identity`text`, "text")
|
||||
-- assertEq(identity`foo{"bar"}`, "foobar")
|
||||
|
||||
return "OK"
|
||||
|
|
Loading…
Add table
Reference in a new issue