Improved AST printing.

This commit is contained in:
yhirose 2015-07-30 17:24:28 -04:00
parent 552c7012f4
commit 7969d2b75c

View File

@ -2006,15 +2006,23 @@ struct AstPrint
level_ += 1; level_ += 1;
for (auto i = 0; i < level_; i++) { std::cout << " "; } for (auto i = 0; i < level_; i++) { std::cout << " "; }
if (ast.is_token) { if (ast.is_token) {
std::cout << "- " << ast.name << ": '" << ast.token << "'" << std::endl; std::cout << "- " << name(ast) << ": '" << ast.token << "'" << std::endl;
} else { } else {
std::cout << "+ " << ast.name << std::endl; std::cout << "+ " << name(ast) << std::endl;
} }
for (auto node : ast.nodes) { print(*node); } for (auto node : ast.nodes) { print(*node); }
level_ -= 1; level_ -= 1;
} }
private: private:
std::string name(const Ast& ast) {
if (ast.name == ast.original_name) {
return ast.name;
} else {
return ast.original_name + " (" + ast.name + ")";
}
}
int level_; int level_;
}; };