-
Notifications
You must be signed in to change notification settings - Fork 52
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
Better indentation & layout for pretty-printing #11
Comments
Some ideas for a nice pretty-printing style:
However, can we make the above somehow optional, so very short lambdas or very short command sequences just go on a single line? Some examples of the kind of thing I have in mind:
|
Thanks for the resources @byorgey. If you plan to work on this please unassign me or I might just pick this up after 6 months. 😉 |
OK! I wasn't necessarily planning to work on this. I just have a goal to "freshen" two github issues per day, which means picking the two least recently updated issues and improving them or moving them along in some (even small) way, like curating the tags, improving the title, adding a comment with additional thoughts or resources, etc. 😄 |
I wonder what the rule should be for binds (
|
@byorgey Yes, we can! I played with it in 503f38b and got from this:
to this:
@byorgey any idea what will break with multiline pretty Term instance? 😅 As an aside, I think those |
Re: |
- improve layout of terms: - break lines on binds, unless it fits on one line - lambdas go on same line, but the body _can_ go to next line - def and let can have long body on next line (indented for def) - parens and braces have body indented if it does not fit on line - closes #11 Example using `--format` from #1459: ``` > cabal run swarm -O0 -- format scenarios/Challenges/_blender/patrol-clockwise.sw def forever = \c. c; force forever c end; def encircle = \lDir. \rDir. turn lDir; b <- blocked; if b {turn rDir} {wait 1}; fwBlocked <- blocked; if fwBlocked {turn rDir} {move} end; def patrolCW = force forever (force encircle right left) end; force patrolCW ```
I kind of threw the pretty-printer together without much regard for how the layout and indentation works. The
prettyprinter
library has lots of nice tools for specifying this kind of thing; someone just needs to sit down and figure out how they work and how to apply them to the Swarm language to get good results.This is very related to #7 , which will depend on this to get nice-looking save files that users can actually edit without tearing their hair out. Another semi-related issue is #644 .
At the moment, we use pretty-printing quite a bit for types, but we only pretty-print terms in certain error messages (e.g. when a command throws an exception).
The text was updated successfully, but these errors were encountered: