mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 11:55:30 +00:00
Improved AST printing.
This commit is contained in:
parent
552c7012f4
commit
7969d2b75c
12
peglib.h
12
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_;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user