Safe Haskell | Safe-Infered |
---|
This module defines classes and functions for pretty-printing. It also
exports a number of helpful debugging and other utilities such as trace
and panic
.
The interface to this module is very similar to the standard Hughes-PJ pretty printing
module, except that it exports a number of additional functions that are rarely used,
and works over the SDoc
type.
- class Outputable a where
- class Outputable a => OutputableBndr a where
- pprBndr :: BindingSite -> a -> SDoc
- pprPrefixOcc, pprInfixOcc :: a -> SDoc
- class PlatformOutputable a where
- pprPlatform :: Platform -> a -> SDoc
- pprPlatformPrec :: Platform -> Rational -> a -> SDoc
- data SDoc
- runSDoc :: SDoc -> SDocContext -> Doc
- initSDocContext :: PprStyle -> SDocContext
- docToSDoc :: Doc -> SDoc
- interppSP :: Outputable a => [a] -> SDoc
- interpp'SP :: Outputable a => [a] -> SDoc
- pprQuotedList :: Outputable a => [a] -> SDoc
- pprWithCommas :: (a -> SDoc) -> [a] -> SDoc
- quotedListWithOr :: [SDoc] -> SDoc
- empty :: SDoc
- nest :: Int -> SDoc -> SDoc
- char :: Char -> SDoc
- text :: String -> SDoc
- ftext :: FastString -> SDoc
- ptext :: LitString -> SDoc
- int :: Int -> SDoc
- integer :: Integer -> SDoc
- float :: Float -> SDoc
- double :: Double -> SDoc
- rational :: Rational -> SDoc
- parens, angleBrackets, doubleQuotes, quote, quotes, brackets, braces :: SDoc -> SDoc
- cparen :: Bool -> SDoc -> SDoc
- semi, dot, underscore, arrow, dcolon, space, equals, colon, comma :: SDoc
- darrow, blankLine, rbrace, lbrace, rbrack, lbrack, rparen, lparen :: SDoc
- (<>) :: SDoc -> SDoc -> SDoc
- (<+>) :: SDoc -> SDoc -> SDoc
- hcat :: [SDoc] -> SDoc
- hsep :: [SDoc] -> SDoc
- ($$) :: SDoc -> SDoc -> SDoc
- ($+$) :: SDoc -> SDoc -> SDoc
- vcat :: [SDoc] -> SDoc
- sep :: [SDoc] -> SDoc
- cat :: [SDoc] -> SDoc
- fsep :: [SDoc] -> SDoc
- fcat :: [SDoc] -> SDoc
- hang :: SDoc -> Int -> SDoc -> SDoc
- punctuate :: SDoc -> [SDoc] -> [SDoc]
- ppWhen, ppUnless :: Bool -> SDoc -> SDoc
- speakNth :: Int -> SDoc
- speakNTimes :: Int -> SDoc
- speakN :: Int -> SDoc
- speakNOf :: Int -> SDoc -> SDoc
- plural :: [a] -> SDoc
- coloured :: PprColour -> SDoc -> SDoc
- data PprColour
- colType :: PprColour
- colCoerc :: PprColour
- colDataCon :: PprColour
- colBinder :: PprColour
- bold :: SDoc -> SDoc
- keyword :: SDoc -> SDoc
- printSDoc :: SDoc -> PprStyle -> IO ()
- printErrs :: SDoc -> PprStyle -> IO ()
- printOutput :: Doc -> IO ()
- hPrintDump :: Handle -> SDoc -> IO ()
- printDump :: SDoc -> IO ()
- printForC :: Handle -> SDoc -> IO ()
- printForAsm :: Handle -> SDoc -> IO ()
- printForUser :: Handle -> PrintUnqualified -> SDoc -> IO ()
- printForUserPartWay :: Handle -> Int -> PrintUnqualified -> SDoc -> IO ()
- pprCode :: CodeStyle -> SDoc -> SDoc
- mkCodeStyle :: CodeStyle -> PprStyle
- showSDoc :: SDoc -> String
- showSDocOneLine :: SDoc -> String
- showSDocForUser :: PrintUnqualified -> SDoc -> String
- showSDocDebug :: SDoc -> String
- showSDocDump :: SDoc -> String
- showSDocDumpOneLine :: SDoc -> String
- showPpr :: Outputable a => a -> String
- showSDocUnqual :: SDoc -> String
- showsPrecSDoc :: Int -> SDoc -> ShowS
- renderWithStyle :: SDoc -> PprStyle -> String
- pprInfixVar :: Bool -> SDoc -> SDoc
- pprPrefixVar :: Bool -> SDoc -> SDoc
- pprHsChar :: Char -> SDoc
- pprHsString :: FastString -> SDoc
- pprFastFilePath :: FastString -> SDoc
- data BindingSite
- = LambdaBind
- | CaseBind
- | LetBind
- data PprStyle
- data CodeStyle
- type PrintUnqualified = (QueryQualifyName, QueryQualifyModule)
- alwaysQualify, neverQualify :: PrintUnqualified
- data QualifyName
- getPprStyle :: (PprStyle -> SDoc) -> SDoc
- withPprStyle :: PprStyle -> SDoc -> SDoc
- withPprStyleDoc :: PprStyle -> SDoc -> Doc
- pprDeeper :: SDoc -> SDoc
- pprDeeperList :: ([SDoc] -> SDoc) -> [SDoc] -> SDoc
- pprSetDepth :: Depth -> SDoc -> SDoc
- codeStyle :: PprStyle -> Bool
- userStyle :: PprStyle -> Bool
- debugStyle :: PprStyle -> Bool
- dumpStyle :: PprStyle -> Bool
- asmStyle :: PprStyle -> Bool
- ifPprDebug :: SDoc -> SDoc
- qualName :: PprStyle -> QueryQualifyName
- qualModule :: PprStyle -> QueryQualifyModule
- mkErrStyle :: PrintUnqualified -> PprStyle
- defaultErrStyle :: PprStyle
- defaultUserStyle, defaultDumpStyle :: PprStyle
- mkUserStyle :: PrintUnqualified -> Depth -> PprStyle
- cmdlineParserStyle :: PprStyle
- data Depth
- pprPanic :: String -> SDoc -> a
- pprSorry :: String -> SDoc -> a
- assertPprPanic :: String -> Int -> SDoc -> a
- pprPanicFastInt :: String -> SDoc -> FastInt
- pprPgmError :: String -> SDoc -> a
- pprTrace :: String -> SDoc -> a -> a
- pprDefiniteTrace :: String -> SDoc -> a -> a
- warnPprTrace :: Bool -> String -> Int -> SDoc -> a -> a
- trace :: String -> a -> a
- panic, pgmError, sorry :: String -> a
- panicFastInt :: String -> FastInt
- assertPanic :: String -> Int -> a
Type classes
class Outputable a whereSource
Class designating that some type has an SDoc
representation
class Outputable a => OutputableBndr a whereSource
When we print a binder, we often want to print its type too.
The OutputableBndr
class encapsulates this idea.
pprBndr :: BindingSite -> a -> SDocSource
pprPrefixOcc, pprInfixOcc :: a -> SDocSource
OutputableBndr Name | |
OutputableBndr Var | |
OutputableBndr RdrName | |
Outputable name => OutputableBndr (IPName name) | |
Outputable b => OutputableBndr (TaggedBndr b) |
class PlatformOutputable a whereSource
pprPlatform :: Platform -> a -> SDocSource
pprPlatformPrec :: Platform -> Rational -> a -> SDocSource
Pretty printing combinators
initSDocContext :: PprStyle -> SDocContextSource
interppSP :: Outputable a => [a] -> SDocSource
Returns the seperated concatenation of the pretty printed things.
interpp'SP :: Outputable a => [a] -> SDocSource
Returns the comma-seperated concatenation of the pretty printed things.
pprQuotedList :: Outputable a => [a] -> SDocSource
Returns the comma-seperated concatenation of the quoted pretty printed things.
[x,y,z] ==> `x', `y', `z'
quotedListWithOr :: [SDoc] -> SDocSource
ftext :: FastString -> SDocSource
parens, angleBrackets, doubleQuotes, quote, quotes, brackets, braces :: SDoc -> SDocSource
A paragraph-fill combinator. It's much like sep, only it keeps fitting things on one line until it can't fit any more.
Converts an integer to a verbal index:
speakNth 1 = text "first" speakNth 5 = text "fifth" speakNth 21 = text "21st"
speakNTimes :: Int -> SDocSource
Converts a strictly positive integer into a number of times:
speakNTimes 1 = text "once" speakNTimes 2 = text "twice" speakNTimes 4 = text "4 times"
Converts an integer to a verbal multiplicity:
speakN 0 = text "none" speakN 5 = text "five" speakN 10 = text "10"
speakNOf :: Int -> SDoc -> SDocSource
Converts an integer and object description to a statement about the multiplicity of those objects:
speakNOf 0 (text "melon") = text "no melons" speakNOf 1 (text "melon") = text "one melon" speakNOf 3 (text "melon") = text "three melons"
Determines the pluralisation suffix appropriate for the length of a list:
plural [] = char 's' plural ["Hello"] = empty plural ["Hello", "World"] = char 's'
coloured :: PprColour -> SDoc -> SDocSource
Apply the given colour/style for the argument.
Only takes effect if colours are enabled.
Converting SDoc
into strings and outputing it
printOutput :: Doc -> IO ()Source
hPrintDump :: Handle -> SDoc -> IO ()Source
printForAsm :: Handle -> SDoc -> IO ()Source
printForUser :: Handle -> PrintUnqualified -> SDoc -> IO ()Source
printForUserPartWay :: Handle -> Int -> PrintUnqualified -> SDoc -> IO ()Source
showSDocOneLine :: SDoc -> StringSource
showSDocForUser :: PrintUnqualified -> SDoc -> StringSource
showSDocDebug :: SDoc -> StringSource
showSDocDump :: SDoc -> StringSource
showPpr :: Outputable a => a -> StringSource
showSDocUnqual :: SDoc -> StringSource
showsPrecSDoc :: Int -> SDoc -> ShowSSource
renderWithStyle :: SDoc -> PprStyle -> StringSource
pprInfixVar :: Bool -> SDoc -> SDocSource
pprPrefixVar :: Bool -> SDoc -> SDocSource
pprHsString :: FastString -> SDocSource
Special combinator for showing string literals.
Controlling the style in which output is printed
data BindingSite Source
BindingSite
is used to tell the thing that prints binder what
language construct is binding the identifier. This can be used
to decide how much info to print.
type PrintUnqualified = (QueryQualifyName, QueryQualifyModule)Source
getPprStyle :: (PprStyle -> SDoc) -> SDocSource
withPprStyle :: PprStyle -> SDoc -> SDocSource
withPprStyleDoc :: PprStyle -> SDoc -> DocSource
pprSetDepth :: Depth -> SDoc -> SDocSource
debugStyle :: PprStyle -> BoolSource
ifPprDebug :: SDoc -> SDocSource
qualModule :: PprStyle -> QueryQualifyModuleSource
mkErrStyle :: PrintUnqualified -> PprStyleSource
Style for printing error messages
mkUserStyle :: PrintUnqualified -> Depth -> PprStyleSource
Error handling and debugging utilities
pprPanic :: String -> SDoc -> aSource
Throw an exception saying bug in GHC
pprSorry :: String -> SDoc -> aSource
Throw an exception saying this isn't finished yet
assertPprPanic :: String -> Int -> SDoc -> aSource
Panic with an assertation failure, recording the given file and line number. Should typically be accessed with the ASSERT family of macros
pprPanicFastInt :: String -> SDoc -> FastIntSource
Specialization of pprPanic that can be safely used with FastInt
pprPgmError :: String -> SDoc -> aSource
Throw an exception saying bug in pgm being compiled (used for unusual program errors)
pprDefiniteTrace :: String -> SDoc -> a -> aSource
Same as pprTrace, but show even if -dno-debug-output is on
warnPprTrace :: Bool -> String -> Int -> SDoc -> a -> aSource
Just warn about an assertion failure, recording the given file and line number. Should typically be accessed with the WARN macros
trace :: String -> a -> aSource
The trace
function outputs the trace message given as its first argument,
before returning the second argument as its result.
For example, this returns the value of f x
but first outputs the message.
trace ("calling f with x = " ++ show x) (f x)
The trace
function should only be used for debugging, or for monitoring
execution. The function is not referentially transparent: its type indicates
that it is a pure function but it has the side effect of outputting the
trace message.
panicFastInt :: String -> FastIntSource
Panic while pretending to return an unboxed int. You can't use the regular panic functions in expressions producing unboxed ints because they have the wrong kind.
assertPanic :: String -> Int -> aSource
Throw an failed assertion exception for a given filename and line number.