Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust api: recursivly print tree via Debug trait if alternate flag is set #3367

Open
lolbinarycat opened this issue May 17, 2024 · 7 comments
Labels
enhancement Feature request rust

Comments

@lolbinarycat
Copy link

Problem

the Debug trait only shows the root node of a tree, which is frequently unhelpful.

Expected behavior

when printing Tree or Node with {:#?}, the implementation of Debug would recurse into child nodes and print the full AST. this would allow easier debugging.

@lolbinarycat lolbinarycat added the enhancement Feature request label May 17, 2024
@ObserverOfTime
Copy link
Member

Debug printing a node does recursively print the S-exp.

@lolbinarycat
Copy link
Author

do you mean printing with Display? i didn't check that, but it seems unintuitive that using Debug would give less info than Display.

@ObserverOfTime
Copy link
Member

Oh yeah, it's Display.

What would recursively printing a node in the Debug format look like?

"{{Node {} {} - {}}}",
self.kind(),
self.start_position(),
self.end_position()

@lolbinarycat
Copy link
Author

hmm.. i feel like i would want to use newlines and indentation to align things honestly... also it should print field names ideally.

@ObserverOfTime
Copy link
Member

Well, you can submit a PR if you want. Maybe make it tree-like.

@lolbinarycat
Copy link
Author

what about also making the alternate form of Display print in an indented way?

@ObserverOfTime
Copy link
Member

Already done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request rust
Projects
None yet
Development

No branches or pull requests

2 participants