mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Update Transpiler string method to respect AST
This commit is contained in:
parent
1cda8304bf
commit
faee3f0b6e
1 changed files with 13 additions and 8 deletions
|
@ -49,7 +49,7 @@ struct Writer
|
|||
virtual void keyword(std::string_view) = 0;
|
||||
virtual void symbol(std::string_view) = 0;
|
||||
virtual void literal(std::string_view) = 0;
|
||||
virtual void string(std::string_view) = 0;
|
||||
virtual void string(std::string_view, bool quoted = true) = 0;
|
||||
};
|
||||
|
||||
struct StringWriter : Writer
|
||||
|
@ -151,15 +151,20 @@ struct StringWriter : Writer
|
|||
write(s);
|
||||
}
|
||||
|
||||
void string(std::string_view s) override
|
||||
void string(std::string_view s, bool quoted) override
|
||||
{
|
||||
char quote = '\'';
|
||||
if (std::string::npos != s.find(quote))
|
||||
quote = '\"';
|
||||
if (quoted)
|
||||
{
|
||||
char quote = '\'';
|
||||
if (std::string::npos != s.find(quote))
|
||||
quote = '\"';
|
||||
|
||||
write(quote);
|
||||
write(quote);
|
||||
write(escape(s));
|
||||
write(quote);
|
||||
return;
|
||||
}
|
||||
write(escape(s));
|
||||
write(quote);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -337,7 +342,7 @@ struct Printer
|
|||
}
|
||||
else if (const auto& a = expr.as<AstExprConstantString>())
|
||||
{
|
||||
writer.string(std::string_view(a->value.data, a->value.size));
|
||||
writer.string(std::string_view(a->value.data, a->value.size), a->quoteStyle == AstExprConstantString::Quoted);
|
||||
}
|
||||
else if (const auto& a = expr.as<AstExprLocal>())
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue