-
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
Missing an empty surround
operator?
#5
Comments
I do agree that the current "high-level API" (beyond the primitive combinators) is rather messy. We never got around to cleaning it up. You are welcome to propose new combinators or new names for existing combinators (in addition to the existing names). |
(Actually I think my idea of One option that is not very exciting but works is
as The core underlying abstraction here is Another way to think of itThe operators that I have in mind could be documented as follows:
(I want This suggests possibly the names Another thing we can notice is that |
Current version: let print_let_in lhs rhs body =
group @@
string "let"
^^ surround 2 1 empty lhs empty
^^ string "="
^^ surround 2 1 empty rhs empty
^^ string "in"
^^ prefix 0 1 empty body
^^ string "end" Without let print_let_in lhs rhs body =
string "let"
^^ group (nest 2 (break 1 ^^ lhs) ^^ break 1)
^^ string "="
^^ group (nest 2 (break 1 ^^ rhs) ^^ break 1)
^^ string "in"
^^ group (nest 0 (break 1 ^^ body)) (I don't know how to easily explain why, for lhs and rhs, there is a break inside the nest and one outside.) With the imaginary let print_let_in lhs rhs body =
group @@
string "let"
^^ nest_inside 2 1 lhs
^^ string "="
^^ nest_inside 2 1 rhs
^^ string "in"
^^ nest_closing 0 1 body It looks nice, but I am not fond of reusing |
@olivier-martinot and myself are writing a pretty-printer for MidML. I got stuck on how to properly pretty-print
let ... in
, and I think that my final iteration suggests that a new combinator could be useful, but I don't know how to name it.Specific question
prefix n b empty doc
has a short form,jump n b
.What is the short form of
surround n b empty doc empty
?Longer story
We want to pretty-print
let <lhs> = <rhs> in <body>
. All of the subexpressions could be long. The printing discipline we want is as follows:<lhs>
or<rhs>
are non-flat, they should be 2-indented on their own lines. (body
is not indented)For example we want to allow all of the following:
(Okay, the second example looks very ugly, but (1) this regular structure makes my story applicable to other constructs that contain a mix of keywords and symbols beyond the simple prefix/surround scenarios, and (2) it never occurs in practice, and actually the fact that we never see it probably explains why we find it ugly. I don't want to make the rules or code more complex to forbid it.)
After trying many things, I ended up with the following approach where the code looks simple enough
The
prefix 0 1 empty body
form can be simplified intojump 0 1 body
.For
lhs
andrhs
, I would need a version ofjump
that adds a break on both sides of the main document, not just on the left. Could we have this? What would be a good name for it?(I don't understand what
jump
is trying to evoke as a name, how it was chosen.)Maybe an option would be to add a new parameter to
jump
for a break on the right:jump n b doc
would becomejump n b_left doc b_right
. The oldjump n b doc
can be expressed withjump n b doc 0
, and my use-case becomesjump 2 1 doc 1
.The text was updated successfully, but these errors were encountered: