Fix wrong indentation from Text.PrettyPrint.HughesPJ fill (fcat and fsep)
This program:
import Text.PrettyPrint.HughesPJ
f z doc = renderStyle
(
Style {
mode = PageMode,
lineLength = z,
ribbonsPerLine = 1.0
}
)
doc
l2 = f 6 $ nest 3 $
fcat [nest 1 $ text "a", nest 2 $ text "b", text "c"]
main = putStr (l2 ++ "\n")
produces this output:
$ runghc pp2.hs | tr ' ' .
....ab
.c
$
The expected output is:
....ab
...c
where the c
is placed below and 1 position to the left of the a
.
As I understand the situation, the problem is that in a fill
(used by fsep
and fcat
), the total indentation of all the documents placed on one line is used to determine the indentation of the next line where only the indentation of the first document should be used. Thus, in the example, the c
is placed 1+2=3 positions to the left of the a
which is 2 too many.
I have attached a patch with a suggested solution. I have also attached a patch that adds a suitable test case.
Note: This problem is also present in GHC's Pretty library and is the reason for the bad formatting reported in #1176 (closed). Once the present problem has been fixed, I intend to go back to #1176 (closed) and fix that in a similar manner.
Trac metadata
Trac field | Value |
---|---|
Version | 6.6.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | libraries/base |
Test case | pp2 |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | Unknown |
Architecture | Unknown |