diff options
| author | Simon Peyton Jones <simonpj@microsoft.com> | 2014-01-17 10:40:58 +0000 |
|---|---|---|
| committer | Simon Peyton Jones <simonpj@microsoft.com> | 2014-01-17 14:06:26 +0000 |
| commit | 9433f1dae5b782d49d4af52f3aa7574272a10c6f (patch) | |
| tree | d5bfffb7761be7852c6077ee1b9aaf44def5beef /compiler/utils | |
| parent | 45d825bb8ba659696788aca712b6f5d2b15a05cf (diff) | |
| download | haskell-9433f1dae5b782d49d4af52f3aa7574272a10c6f.tar.gz | |
Tidy up Outputable.printDoc, and add printDoc_
The former adds a newline at the end (restoring the previous behaviour)
while the latter does not (which previously happened by turning the
thuing into a string and only then printing it).
Diffstat (limited to 'compiler/utils')
| -rw-r--r-- | compiler/utils/Pretty.lhs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/compiler/utils/Pretty.lhs b/compiler/utils/Pretty.lhs index 0bac66e04e..fb7fe2b7fb 100644 --- a/compiler/utils/Pretty.lhs +++ b/compiler/utils/Pretty.lhs @@ -173,7 +173,7 @@ module Pretty ( hang, punctuate, - fullRender, printDoc, showDoc, + fullRender, printDoc, printDoc_, showDoc, bufLeftRender -- performance hack ) where @@ -985,9 +985,16 @@ spaces n | n <=# _ILIT(0) = "" \begin{code} printDoc :: Mode -> Int -> Handle -> Doc -> IO () -printDoc LeftMode _ hdl doc +-- printDoc adds a newline to the end +printDoc mode cols hdl doc = printDoc_ mode cols hdl (doc $$ text "") + +printDoc_ :: Mode -> Int -> Handle -> Doc -> IO () +-- printDoc_ does not add a newline at the end, so that +-- successive calls can output stuff on the same line +-- Rather like putStr vs putStrLn +printDoc_ LeftMode _ hdl doc = do { printLeftRender hdl doc; hFlush hdl } -printDoc mode pprCols hdl doc +printDoc_ mode pprCols hdl doc = do { fullRender mode pprCols 1.5 put done doc ; hFlush hdl } where @@ -999,7 +1006,7 @@ printDoc mode pprCols hdl doc put (ZStr s) next = hPutFZS hdl s >> next put (LStr s l) next = hPutLitString hdl s l >> next - done = hPutChar hdl '\n' + done = return () -- hPutChar hdl '\n' -- some versions of hPutBuf will barf if the length is zero hPutLitString :: Handle -> Ptr a -> Int# -> IO () |
