1 | #pragma once |
---|---|
2 | |
3 | #include <Parsers/IAST.h> |
4 | #include <Common/quoteString.h> |
5 | |
6 | |
7 | namespace DB |
8 | { |
9 | |
10 | /** A pair of the name and type. For example, browser FixedString(2). |
11 | */ |
12 | class ASTNameTypePair : public IAST |
13 | { |
14 | public: |
15 | /// name |
16 | String name; |
17 | /// type |
18 | ASTPtr type; |
19 | |
20 | /** Get the text that identifies this element. */ |
21 | String getID(char delim) const override { return "NameTypePair"+ (delim + name); } |
22 | |
23 | ASTPtr clone() const override |
24 | { |
25 | auto res = std::make_shared<ASTNameTypePair>(*this); |
26 | res->children.clear(); |
27 | |
28 | if (type) |
29 | { |
30 | res->type = type; |
31 | res->children.push_back(res->type); |
32 | } |
33 | |
34 | return res; |
35 | } |
36 | |
37 | protected: |
38 | void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override |
39 | { |
40 | std::string indent_str = settings.one_line ? "": std::string(4 * frame.indent, ' '); |
41 | |
42 | settings.ostr << settings.nl_or_ws << indent_str << backQuoteIfNeed(name) << " "; |
43 | type->formatImpl(settings, state, frame); |
44 | } |
45 | }; |
46 | |
47 | |
48 | } |
49 | |
50 |