Clean debug tree
This commit is contained in:
parent
f5ba6f19b4
commit
6dece0b9d9
@ -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<Token>(node);
|
||||
cout << prefix;
|
||||
_debug_print_token(token);
|
||||
if (holds_alternative<int>(token.data)) {
|
||||
cout << ", Value: " << get<int>(token.data);
|
||||
} else if (holds_alternative<string>(token.data)) {
|
||||
cout << ", Value: " << get<string>(token.data);
|
||||
}
|
||||
cout << "\n";
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user