ClickHouse/src/Parsers/formatAST.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
983 B
C++
Raw Normal View History

2011-09-04 05:14:52 +00:00
#pragma once
2010-06-28 13:44:42 +00:00
#include <Parsers/IAST.h>
2010-06-28 13:44:42 +00:00
namespace DB
{
2020-11-09 16:05:40 +00:00
class WriteBuffer;
2017-05-27 17:29:55 +00:00
/** Takes a syntax tree and turns it back into text.
* In case of INSERT query, the data will be missing.
2010-06-28 13:44:42 +00:00
*/
2020-11-09 16:05:40 +00:00
void formatAST(const IAST & ast, WriteBuffer & buf, bool hilite = true, bool one_line = false);
2010-06-28 13:44:42 +00:00
String serializeAST(const IAST & ast, bool one_line = true);
2020-11-10 18:22:26 +00:00
inline WriteBuffer & operator<<(WriteBuffer & buf, const IAST & ast)
{
formatAST(ast, buf, false, true);
return buf;
}
inline WriteBuffer & operator<<(WriteBuffer & buf, const ASTPtr & ast)
{
formatAST(*ast, buf, false, true);
return buf;
}
2014-10-01 16:38:04 +00:00
2010-06-28 13:44:42 +00:00
}
2020-11-22 17:13:40 +00:00
template<>
struct fmt::formatter<DB::ASTPtr>
{
template<typename ParseContext>
constexpr auto parse(ParseContext & context)
{
return context.begin();
}
template<typename FormatContext>
auto format(const DB::ASTPtr & ast, FormatContext & context)
{
return fmt::format_to(context.out(), "{}", DB::serializeAST(*ast));
}
};