Make the tree structure more explicit in parse dumps (#7591)

It's hard to track 2-space indent levels across large vertical gaps, and
it can be hard to suppress the instinct to read the dump as if it were
preorder. This change introduces a new dump mode that addresses both
problems by using box-drawing characters to explicitly represent the
parent-child edges of the tree. This new mode is the default, but the
old behavior remains available with
`--parse-dump-format=yaml-postorder`.
This commit is contained in:
Geoff Romer
2026-07-31 16:44:18 +00:00
committed by GitHub
parent 2c91e5f5de
commit 6429c1655c
343 changed files with 11839 additions and 12185 deletions
+10 -4
View File
@@ -56,10 +56,16 @@ auto Parse(Lex::TokenizedBuffer& tokens, ParseOptions options) -> Tree {
CARBON_VLOG_TO(options.vlog_stream, "*** Parse::Tree ***\n{0}", tree);
if (options.dump_stream) {
Parse::TreeAndSubtrees tree_and_subtrees(tokens, tree);
if (options.dump_preorder_parse_tree) {
tree_and_subtrees.PrintPreorder(*options.dump_stream);
} else {
tree_and_subtrees.Print(*options.dump_stream);
switch (options.dump_format) {
case ParseOptions::DumpFormat::PrettyPostorder:
tree_and_subtrees.PrettyPrint(*options.dump_stream);
break;
case ParseOptions::DumpFormat::YamlPostorder:
tree_and_subtrees.PrintYamlPostorder(*options.dump_stream);
break;
case ParseOptions::DumpFormat::YamlPreorder:
tree_and_subtrees.PrintYamlPreorder(*options.dump_stream);
break;
}
}