Skip to content

Commit

Permalink
Try pop
Browse files Browse the repository at this point in the history
  • Loading branch information
Matts966 committed Apr 24, 2022
1 parent b7ba232 commit d39018d
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions zetasql/parser/unparser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,19 @@ std::string Unparse(const ASTNode* node) {

std::string UnparseWithComments(const ASTNode* node, std::deque<std::pair<std::string,
ParseLocationPoint>>& parse_tokens) {
std::string unparsed_;
parser::Unparser unparser(&unparsed_);
std::string unparsed;
parser::Unparser unparser(&unparsed);
// Print comments by visitors and pop.
node->Accept(&unparser, &parse_tokens);
// Emit left comments in parse_tokens.
bool newline_emitted = false;
for (const auto& parse_token : parse_tokens) {
if (parse_token.first.find("\n") != std::string::npos) {
newline_emitted = true;
}
unparser.print(parse_token.first);
}
if (!newline_emitted) {
unparser.FlushLine();
unparser.FlushLine();
while (unparsed.back() == '\n' && unparsed.at(unparsed.size() - 2) == '\n') {
unparsed.pop_back();
}
return unparsed_;
return unparsed;
}

namespace parser {
Expand Down

0 comments on commit d39018d

Please # to comment.