Line data Source code
1 : #include "../../../inc/visitors/printTree/printTree.h"
2 : #include "../../../inc/parsingAnalysis/ast/literals/ast_bool.h"
3 : #include "../../../inc/parsingAnalysis/ast/literals/ast_char.h"
4 : #include "../../../inc/parsingAnalysis/ast/literals/ast_double.h"
5 : #include "../../../inc/parsingAnalysis/ast/literals/ast_float.h"
6 : #include "../../../inc/parsingAnalysis/ast/literals/ast_int.h"
7 : #include "../../../inc/parsingAnalysis/ast/literals/ast_null.h"
8 : #include "../../../inc/parsingAnalysis/ast/literals/ast_string.h"
9 :
10 : namespace nicole {
11 :
12 : std::expected<std::string, Error>
13 0 : PrintTree::visit(const AST_BOOL *node) const noexcept {
14 0 : if (!node) {
15 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_BOOL");
16 0 : }
17 0 : return indent_ + "Bool: " + (node->value() ? "true" : "false") + "\n";
18 0 : }
19 :
20 : std::expected<std::string, Error>
21 0 : PrintTree::visit(const AST_CHAR *node) const noexcept {
22 0 : if (!node) {
23 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_CHAR");
24 0 : }
25 0 : return indent_ + "Char: '" + node->value() + "'\n";
26 0 : }
27 :
28 : std::expected<std::string, Error>
29 0 : PrintTree::visit(const AST_DOUBLE *node) const noexcept {
30 0 : if (!node) {
31 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_DOUBLE");
32 0 : }
33 0 : return indent_ + "Double: " + std::to_string(node->value()) + "\n";
34 0 : }
35 :
36 : std::expected<std::string, Error>
37 0 : PrintTree::visit(const AST_FLOAT *node) const noexcept {
38 0 : if (!node) {
39 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_FLOAT");
40 0 : }
41 0 : return indent_ + "Float: " + std::to_string(node->value()) + "\n";
42 0 : }
43 :
44 : std::expected<std::string, Error>
45 0 : PrintTree::visit(const AST_INT *node) const noexcept {
46 0 : if (!node) {
47 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_INT");
48 0 : }
49 0 : return indent_ + "Integer: " + std::to_string(node->value()) + "\n";
50 0 : }
51 :
52 : std::expected<std::string, Error>
53 0 : PrintTree::visit(const AST_NULL *node) const noexcept {
54 0 : if (!node) {
55 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_NULL");
56 0 : }
57 0 : return indent_ + "null\n";
58 0 : }
59 :
60 : std::expected<std::string, Error>
61 0 : PrintTree::visit(const AST_STRING *node) const noexcept {
62 0 : if (!node) {
63 0 : return createError(ERROR_TYPE::NULL_NODE, "invalid AST_STRING");
64 0 : }
65 0 : return indent_ + "String: \"" + node->value() + "\"\n";
66 0 : }
67 :
68 : }
|