diff --git a/src/parser.cpp b/src/parser.cpp index af03a9b..f1838a2 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -14,20 +14,28 @@ void _debug_print_tree(const Node& node, int depth, const string& prefix = "") { cout << prefix << _node_names[int(innerNode.type)] << "\n"; + string new_prefix = prefix; + size_t pos = new_prefix.find("└──"); + while (pos != std::string::npos) { + new_prefix.replace(pos, 9, " "); + pos = new_prefix.find("└──", pos + 4); + } + + pos = new_prefix.find("├──"); + while (pos != std::string::npos) { + new_prefix.replace(pos, 9, "│ "); + pos = new_prefix.find("├──", pos + 6); + } + for (size_t i = 0; i < innerNode.children.size(); ++i) { string childPrefix = (i == innerNode.children.size() - 1) ? "└── " : "├── "; - _debug_print_tree(innerNode.children[i], depth + 1, prefix + childPrefix); + _debug_print_tree(innerNode.children[i], depth + 1, new_prefix + childPrefix); } } else { const Token& token = get(node); cout << prefix; _debug_print_token(token); - if (holds_alternative(token.data)) { - cout << ", Value: " << get(token.data); - } else if (holds_alternative(token.data)) { - cout << ", Value: " << get(token.data); - } - cout << "\n"; + cout << endl; } }