From 7969d2b75ce969b985cf08ef159ffdb8f96ee30d Mon Sep 17 00:00:00 2001 From: yhirose Date: Thu, 30 Jul 2015 17:24:28 -0400 Subject: [PATCH] Improved AST printing. --- peglib.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/peglib.h b/peglib.h index f883c76..cc76946 100644 --- a/peglib.h +++ b/peglib.h @@ -2006,15 +2006,23 @@ struct AstPrint level_ += 1; for (auto i = 0; i < level_; i++) { std::cout << " "; } if (ast.is_token) { - std::cout << "- " << ast.name << ": '" << ast.token << "'" << std::endl; + std::cout << "- " << name(ast) << ": '" << ast.token << "'" << std::endl; } else { - std::cout << "+ " << ast.name << std::endl; + std::cout << "+ " << name(ast) << std::endl; } for (auto node : ast.nodes) { print(*node); } level_ -= 1; } 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_; };