Line data Source code
1 : #include "../../../inc/visitors/printTree/printTree.h"
2 : #include "../../../inc/parsingAnalysis/ast/vector/ast_index.h"
3 : #include "../../../inc/parsingAnalysis/ast/vector/ast_vector.h"
4 : #include <ostream>
5 :
6 : namespace nicole {
7 :
8 : std::expected<std::string, Error>
9 0 : PrintTree::visit(const AST_VECTOR *node) const noexcept {
10 0 : if (!node) {
11 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_VECTOR");
12 0 : }
13 0 : std::ostringstream result;
14 0 : result << indent_ << "vector:\n";
15 0 : increaseIndent();
16 0 : for (const auto &statement : node->values()) {
17 0 : const auto val{statement->accept(*this)};
18 0 : if (!val) {
19 0 : return createError(val.error());
20 0 : }
21 0 : result << *val;
22 0 : }
23 0 : decreaseIndent();
24 0 : return result.str();
25 0 : }
26 :
27 : std::expected<std::string, Error>
28 0 : PrintTree::visit(const AST_INDEX *node) const noexcept {
29 0 : if (!node) {
30 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_INDEX");
31 0 : }
32 0 : std::ostringstream result;
33 0 : result << indent_ << "index:\n";
34 0 : increaseIndent();
35 0 : const auto val{node->index()->accept(*this)};
36 0 : if (!val) {
37 0 : return createError(val.error());
38 0 : }
39 0 : result << *val;
40 0 : decreaseIndent();
41 0 : return result.str();
42 0 : }
43 :
44 : }
|