mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 20:05:31 +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;
|
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_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user