Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Ast/include/Luau/PrettyPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ void dump(AstNode* node);

// Never fails on a well-formed AST
std::string prettyPrint(AstStatBlock& ast);
std::string prettyPrint(AstStatBlock& block, const CstNodeMap& cstNodeMap);
std::string prettyPrintWithTypes(AstStatBlock& block);
std::string prettyPrintWithTypes(AstStatBlock& block, const CstNodeMap& cstNodeMap);

Expand Down
5 changes: 5 additions & 0 deletions Ast/src/PrettyPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1966,6 +1966,11 @@ std::string prettyPrint(AstStatBlock& block, const CstNodeMap& cstNodeMap)
return writer.str();
}

std::string prettyPrint(AstStatBlock& block)
{
return prettyPrint(block, CstNodeMap{nullptr});
}

std::string prettyPrintWithTypes(AstStatBlock& block, const CstNodeMap& cstNodeMap)
{
StringWriter writer;
Expand Down
13 changes: 13 additions & 0 deletions tests/PrettyPrinter.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ end
CHECK_EQ(example, prettyPrint(example).code);
}

TEST_CASE("prettyPrint_AstStatBlock_overload")
{
const std::string code = "local a = 1";
ParseOptions options;
Allocator allocator;
AstNameTable names(allocator);
ParseResult result = Parser::parse(code.c_str(), code.size(), names, allocator, options);
REQUIRE(result.root != nullptr);

std::string printed = prettyPrint(*result.root);
CHECK_EQ("local a = 1", printed);
}

TEST_CASE("string_literals")
{
const std::string code = R"( local S='abcdef\n\f\a\020' )";
Expand Down