-
Notifications
You must be signed in to change notification settings - Fork 11
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
hardlines at the end of nest blocks #11
Comments
Hello Alasdair. Thanks for this suggestion. I definitely do not want to change the semantics of the existing Currently the semantics of Thinking out loud, perhaps one could propose an |
I have solved this issue by change the semantic of the
to
This issue is elegantly solved. |
Oh, I rather got distracted by other things and forgot a bit about this issue - apologies. I came up with my own solution where I used the range combinator to track the output location of each hardline, then I used a postprocessing step to 'fix' the line breaks in a separate pass. It feels like a bit of a hack, but this let me implement a few more useful newline combinators like a newline that disappears when followed by another newline (which I use after line comments, to ensure they are followed by a line break, but never introduce more than strictly required). |
@hackwaly, this sounds like an interesting suggestion. I suppose you mean: "every time a nonblank character is emitted at the begining of a line, it is immediately preceded by I would be interested in seeing your code, if possible. This is a global change in the semantics, so, in order to not to break existing code, it would have to be a new mode, which users would have to explicitly request. |
Hi,
I've been working on a formatter for a language with C style line comments, and I've ran into an issue with the behavior of hardline and nest that is quite tricky to work around, the problem is if you have:
then the hardline immediately outputs spaces to the
nest n
level causing the indentation to 'leak' out of the nest block and indent the first line ofy
. Obviously in the simple case this can be worked around by writingnest n x ^^ hardline ^^ y
instead, but the problem is if the hardline is generated by some other function like:and it occurs in a situation like
nest n (x ^^ y) ^^ z
, wherey
eventually ends in a line comment after potentially many calls to other formatting functions. Trying to avoid this would require re-writing my formatter in a rather contorted way.It would be more useful to me if there was a linebreak combinator that satisfies the property:
I was able to achieve this by modifying PPrintEngine like so: Alasdair@bac7464 such that continue takes a pending hardline parameter and only prints the spaces when it encounters KCons. Modifying the behavior of hardline itself might be a breaking change for other users (and I am not sure if there are unintended consequences of that change), so perhaps a separate combinator would be better?
Best,
Alasdair
The text was updated successfully, but these errors were encountered: