-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathnode.cc
65 lines (59 loc) · 2.25 KB
/
node.cc
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
/*
* Use and distribution licensed under the Apache license version 2.
*
* See the COPYING file in the root project directory for full text.
*/
#include <iostream>
#include "node.h"
#include "printer.h"
namespace sqltoaster {
void print_map(std::ostream& out, const mapping_t& mapping, size_t indent_level, bool is_list_item) {
for (const std::unique_ptr<const mapping_value_t>& el : mapping.elements) {
if (! is_list_item) {
if (indent_level > 0)
out << std::endl;
out << std::string(indent_level * 2, ' ');
}
else {
out << std::endl << std::string((indent_level - 1) * 2, ' ') << "- ";
is_list_item = false;
}
switch (el->value->type) {
case SCALAR:
{
const scalar_t& sub =
static_cast<const scalar_t&>(*el->value);
out << el->key << ": " << sub.value;
}
break;
case MAPPING:
{
const mapping_t& sub =
static_cast<const mapping_t&>(*el->value);
out << el->key << ":";
print_map(out, sub, indent_level + 1, false);
}
break;
case SEQUENCE:
{
const sequence_t& sub =
static_cast<const sequence_t&>(*el->value);
out << el->key << ":";
for (const std::unique_ptr<node_t>& list_el : sub.elements) {
if (list_el->type == SCALAR) {
const scalar_t& sub =
static_cast<const scalar_t&>(*list_el);
out << std::endl << std::string((indent_level + 1) * 2, ' ') << "- ";
out << sub.value;
} else if (list_el->type == MAPPING) {
const mapping_t& sub =
static_cast<const mapping_t&>(*list_el);
print_map(out, sub, indent_level + 2, true);
}
}
}
break;
}
}
}
} // namespace sqltoaster