-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathprinter.h
75 lines (65 loc) · 1.95 KB
/
printer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Use and distribution licensed under the Apache license version 2.
*
* See the COPYING file in the root project directory for full text.
*/
#ifndef SQLTOASTER_PRINTER_H
#define SQLTOASTER_PRINTER_H
#include <iostream>
#include <sqltoast/sqltoast.h>
#include "node.h"
namespace sqltoaster {
typedef enum output_format {
OUTPUT_FORMAT_DEFAULT,
OUTPUT_FORMAT_YAML
} output_format_t;
typedef struct printer {
int iomanip_indexes[1];
sqltoast::parse_result_t& res;
output_format_t output_format;
size_t indent_level;
bool list_item;
std::unique_ptr<node_t> statements;
printer(
sqltoast::parse_result_t& res,
std::ostream& out) :
res(res),
output_format(OUTPUT_FORMAT_DEFAULT),
indent_level(0),
list_item(false),
statements(std::make_unique<sequence_t>())
{}
inline void indent_push(std::ostream& out) {
indent_level++;
}
inline void indent_pop(std::ostream& out) {
indent_level--;
}
inline std::ostream& indent(std::ostream& out) {
out << std::endl;
if (indent_level > 0)
out << std::string(indent_level * 2, ' ');
return out;
}
inline void start_list(std::ostream& out) {
list_item = true;
}
inline void end_list(std::ostream& out) {
list_item = false;
}
inline bool in_list(std::ostream& out) const {
return list_item;
}
inline void add_statement_node(std::unique_ptr<node_t>& node) {
sequence_t& stmt_seq = static_cast<sequence_t&>(*statements);
stmt_seq.elements.emplace_back(std::move(node));
}
inline size_t statement_node_count() const {
sequence_t& stmt_seq = static_cast<sequence_t&>(*statements);
return stmt_seq.elements.size();
}
void process_statements();
} printer_t;
std::ostream& operator<< (std::ostream& out, printer_t& ptr);
} // namespace sqltoaster
#endif /* SQLTOASTER_PRINTER_H */