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
Improve ASTNode#to_s output of parenthesized expression #9637
base: master
Are you sure you want to change the base?
Conversation
This fix does not have to be needed. However, it benefits to reduce user surprise in many cases (e.g. `p!` macro output).
What's the output of: show((1
2)) ? |
@asterite |
Sorry, I didn't understand what yo mean. But my point is, expressions separates by newline or comma are equivalent. We don't know what the user wrote because the AST doesn't fully capture this. So I don't think this is very important to have. More importantly, we can never get it right unless we add information about whether semicolons were used or not. But if it's only for this, then in my mind it's not worth it. |
Current output is parsable by machine, but it looks very weird: the output has many useless spaces and indentation is almost broken. Fortunately this problem can be fixed easily. Minimal lines diff gets surely improvement, so I think this can be acceptable. |
Isn't this modest improvement really acceptable? |
The example looks nice, but the expression separator is a questionable improvement. It just shifts from one unexpected output to another (in the opposite case). Perhaps semicolon-separated expressions are more common for this so it might be a slight improvement to do it this way. But when expressions happen to be longer (and separated by newlines in the original code) it's really not a great ide to put them in a single line. I'm totally in for the indentation fix, though. But the current output actually strips the parenthesis, so there's no error in the visual output: begin
1 + 2
end |
@straight-shoota It seems buggy. |
But that's not possible currently, because the information is lost at the parser. We could consider adding data on whether expressions are separated by newline or semi colon to the AST node. That would fix it. Not sure it's worth it, though. |
This fix does not have to be needed. However, it benefits to reduce user surprise in many cases (e.g.
p!
macro output).Thank you.