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 keyword(std::string_view) = 0;
|
||||||
virtual void symbol(std::string_view) = 0;
|
virtual void symbol(std::string_view) = 0;
|
||||||
virtual void literal(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
|
struct StringWriter : Writer
|
||||||
|
@ -151,7 +151,9 @@ struct StringWriter : Writer
|
||||||
write(s);
|
write(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void string(std::string_view s) override
|
void string(std::string_view s, bool quoted) override
|
||||||
|
{
|
||||||
|
if (quoted)
|
||||||
{
|
{
|
||||||
char quote = '\'';
|
char quote = '\'';
|
||||||
if (std::string::npos != s.find(quote))
|
if (std::string::npos != s.find(quote))
|
||||||
|
@ -160,6 +162,9 @@ struct StringWriter : Writer
|
||||||
write(quote);
|
write(quote);
|
||||||
write(escape(s));
|
write(escape(s));
|
||||||
write(quote);
|
write(quote);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
write(escape(s));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -337,7 +342,7 @@ struct Printer
|
||||||
}
|
}
|
||||||
else if (const auto& a = expr.as<AstExprConstantString>())
|
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>())
|
else if (const auto& a = expr.as<AstExprLocal>())
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue