Skip to content

Conversation

@mateusz834
Copy link
Contributor

This change adds a function to print a visual AST representation.
It makes the experience better while learning/debugging stuff related to the Zig AST.

@mateusz834 mateusz834 changed the title std.zig.Ast: add printAstNode std.zig.Ast: add printNode Nov 7, 2025
@mateusz834
Copy link
Contributor Author

mateusz834 commented Nov 7, 2025

I have developed such utility while looking around and learning the Zig AST. It seems pretty useful, so I sent a PR.

I wonder whether we should wire this thing up in ast-check, just like -t prints the ZIR, we could have some option that prints the AST.

This change adds a function to print a visual AST representation.
}

fn indent(p: *const Printer) Writer.Error!void {
const tab: []const u8 = "\n" ++ (". " ** 256);
Copy link
Contributor Author

@mateusz834 mateusz834 Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might wonder why the tree is indented using ". " (a dot followed by two spaces), which at first glance seems weird.

This comes from Go’s go/ast (see print.go).
The reason is practical: using a visible dot makes it easier to spot the end braces and distinguish indentation levels in the printed tree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant