diff --git a/zetasql/parser/unparser.cc b/zetasql/parser/unparser.cc index 13ba059c..0eb3cf45 100644 --- a/zetasql/parser/unparser.cc +++ b/zetasql/parser/unparser.cc @@ -1373,6 +1373,8 @@ void Unparser::visitASTQuery(const ASTQuery* node, void* data) { visitASTChildren(node, data); } PrintCloseParenIfNeeded(node); + // ASTQuery always ends parent. + formatter_.FlushCommentsPassedBy(node->parent()->GetParseLocationRange().end(), data); } void Unparser::visitASTSetOperation(const ASTSetOperation* node, void* data) { diff --git a/zetasql/parser/unparser.h b/zetasql/parser/unparser.h index 764fdc17..e9641ab9 100644 --- a/zetasql/parser/unparser.h +++ b/zetasql/parser/unparser.h @@ -130,7 +130,9 @@ class Unparser : public ParseTreeVisitor { } void visitASTChildren(const ASTNode* node, void* data) { + formatter_.FlushCommentsPassedBy(node->GetParseLocationRange().start(), data); node->ChildrenAccept(this, data); + formatter_.FlushCommentsPassedBy(node->GetParseLocationRange().end(), data); } void visit(const ASTNode* node, void* data) override {