import {-# SOURCE #-} Name( Name )
-import IO ( Handle, hPutChar, hPutStr, stderr, stdout )
import CmdLineOpts ( opt_PprStyle_Debug, opt_PprUserLength )
import FastString
import qualified Pretty
import Pretty ( Doc, Mode(..), TextDetails(..), fullRender )
import Panic
+
+import Word ( Word32 )
+import IO ( Handle, hPutChar, hPutStr, stderr, stdout )
import Char ( chr, ord, isDigit )
\end{code}
| c == ord '\r' = "\\r" ++ rest
| c == ord '\t' = "\\t" ++ rest
| c == ord '\v' = "\\v" ++ rest
- | otherwise = ('\\':) $ shows c $ case rest of
+ | otherwise = ('\\':) $ shows (fromIntegral c :: Word32) $ case rest of
d:_ | isDigit d -> "\\&" ++ rest
_ -> rest
-- of Char and String.
pprHsChar :: Int -> SDoc
-pprHsChar c = text (show (chr c))
+pprHsChar c | not (inCharRange c) = char '\\' <> show (fromIntegral c :: Word32)
+ | otherwise = text (show (chr c))
pprHsString :: FastString -> SDoc
pprHsString fs = text (show (unpackFS fs))