[m-dev.] Contribution: Pretty Printing Library
Ralph Becket
rbeck at microsoft.com
Wed Apr 12 19:23:41 AEST 2000
> From: Fergus Henderson [mailto:fjh at cs.mu.OZ.AU]
>
> A good exercise to see whether the interface to this pretty printing
> library is general enough to be widely useful would be to try
> reimplementing compiler/error_util.m using it.
>
> I think the answer will be that it is not quite general enough,
> because it only provides indentation by N spaces (`nest(int, doc)'),
> rather than allowing the programmer to specify that something
> should be indented by inserting some given string in the left
> hand column.
>
> I think there are a lot of cases where it would be useful to
> allow indentation by an arbitrary string. For example,
> suppose you are generating program code, and consider
> formatting text which will appear in comments.
Good idea.
The current definition caters for `nest's and `line's like this:
(a) if the pretty printer *has* decided to flatten a group
then all `nest's and `line's in that group are ignored - it's
as if they weren't there;
(b) if the pretty printer has decided *not* to flatten a group
then `line's become line-breaks followed by the amount of
whitespace dictated by the sum of the `nest's in scope.
We could add a second kind of nest taking a string as its first
argument rather than an indentation amount, e.g.
pprint__write(N,
nest(
"my label: ",
line `<>` group(text("this is ") `</>` text("some text"))
)
)
would produce the following, depending upon N:
my label: this is some text { N > 24 }
or
my label: this is
my label: some text { N < 24 }
The question is what semantics do we want for nested string `nest's?
Should we have
nest("my ", nest("label: ", Doc)) = nest("my label: ", Doc)
or
nest("my ", nest("label: ", Doc)) = nest("label: ", Doc)
?
What should we do for `nest(2, nest("my label: ", Doc))' ?
Perhaps all this stuff should just add up without any clever
semantics? Yes, the more I think about it, the more this seems to be
the right thing to do.
Any opinions?
Ralph
--
Ralph Becket | MSR Cambridge | rbeck at microsoft.com
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list