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

Properly newline expressions in the pretty printer #1581

Merged
merged 20 commits into from
Oct 18, 2022

Conversation

janmasrovira
Copy link
Collaborator

@janmasrovira janmasrovira commented Oct 6, 2022

follow-up to #1577

image

I think it still uses too much horizontal space and it should be improved. Also, it only works for regular application. Infix chains are treated as before.

@janmasrovira janmasrovira self-assigned this Oct 6, 2022
@janmasrovira janmasrovira force-pushed the 1577-properly-newline-expressions-in-the-pretty-printer branch from 19d885c to d28a700 Compare October 6, 2022 23:45
@mariari
Copy link
Member

mariari commented Oct 7, 2022

follow-up to #1577

image

A very easy way is to maybe just newline after the := and indent by 2, so that the space up to the next line isn't 20 spaces off. (A group can be had here to optionally newline if it gets big to preserve the same like := for small expressions

@janmasrovira
Copy link
Collaborator Author

follow-up to #1577
image

A very easy way is to maybe just newline after the := and indent by 2, so that the space up to the next line isn't 20 spaces off. (A group can be had here to optionally newline if it gets big to preserve the same like := for small expressions

I actually tried to do that but I didn't succeed. I'll need to spend some more time with it

@janmasrovira janmasrovira force-pushed the 1577-properly-newline-expressions-in-the-pretty-printer branch from d4ea4cc to 271b565 Compare October 12, 2022 10:35
@janmasrovira
Copy link
Collaborator Author

This pr now includes:

  1. A new data type (Ape) that represents abstract expressions to be pretty printed. They should be generic enough to be used as the backend for Concrete, Abstract and Internal. Currently only Concrete uses them.
  2. A sensible algorithm for pretty printing Apes. This algorithm takes into account chains of applications or infix operators of the same fixity.
  3. This new algorithm is not the default but can be disabled using the global --no-format option.
  4. A new juvix-mode command: juvix-format-buffer that formats the current buffer.

I started to work on an enchancement to the algorithm that supports cycling nesting levels when the nesting level comes too close to the end of the page. However, it required a bigger refactor and it will be merged (in case we want it) in another pr. Some wip is fond in https://github.com/anoma/juvix/tree/anchor-experiment branch

@janmasrovira janmasrovira marked this pull request as ready for review October 17, 2022 20:07
@janmasrovira janmasrovira requested a review from lukaszcz October 18, 2022 08:30
@lukaszcz lukaszcz merged commit 2062d3d into main Oct 18, 2022
@lukaszcz lukaszcz deleted the 1577-properly-newline-expressions-in-the-pretty-printer branch October 18, 2022 15:38
@jonaprieto jonaprieto added this to the 0.2.6 milestone Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants