ClickHouse/src/Parsers/ASTExpressionList.cpp

62 lines
1.7 KiB
C++
Raw Normal View History

2017-06-18 05:44:09 +00:00
#include <Parsers/ASTExpressionList.h>
2020-11-09 16:05:40 +00:00
#include <IO/Operators.h>
2017-06-18 05:44:09 +00:00
namespace DB
{
ASTPtr ASTExpressionList::clone() const
{
auto clone = std::make_shared<ASTExpressionList>(*this);
clone->cloneChildren();
return clone;
2017-06-18 05:44:09 +00:00
}
void ASTExpressionList::formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
{
if (frame.expression_list_prepend_whitespace)
settings.ostr << ' ';
2021-12-07 13:44:09 +00:00
for (ASTs::const_iterator it = children.begin(); it != children.end(); ++it)
2017-06-18 05:44:09 +00:00
{
2021-12-07 13:44:09 +00:00
if (it != children.begin())
2019-10-07 16:23:16 +00:00
{
2021-12-07 13:44:09 +00:00
if (separator)
settings.ostr << separator;
settings.ostr << ' ';
}
2017-06-18 05:44:09 +00:00
2021-12-25 17:30:31 +00:00
(*it)->formatImpl(settings, state, frame);
2017-06-18 05:44:09 +00:00
}
}
void ASTExpressionList::formatImplMultiline(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
{
std::string indent_str = "\n" + std::string(4 * (frame.indent + 1), ' ');
if (frame.expression_list_prepend_whitespace)
{
if (!(children.size() > 1 || frame.expression_list_always_start_on_new_line))
settings.ostr << ' ';
}
2017-06-18 05:44:09 +00:00
++frame.indent;
2021-12-07 13:44:09 +00:00
for (ASTs::const_iterator it = children.begin(); it != children.end(); ++it)
2017-06-18 05:44:09 +00:00
{
2021-12-07 13:44:09 +00:00
if (it != children.begin())
2019-10-07 16:23:16 +00:00
{
2021-12-07 13:44:09 +00:00
if (separator)
settings.ostr << separator;
2019-10-07 16:23:16 +00:00
}
2021-12-07 13:44:09 +00:00
if (children.size() > 1 || frame.expression_list_always_start_on_new_line)
settings.ostr << indent_str;
2017-06-18 05:44:09 +00:00
2021-12-07 13:44:09 +00:00
FormatStateStacked frame_nested = frame;
frame_nested.expression_list_always_start_on_new_line = false;
(*it)->formatImpl(settings, state, frame_nested);
2017-06-18 05:44:09 +00:00
}
}
}