ghc-lib-parser-9.10.1.20250103: The GHC API, decoupled from GHC versions

Safe Haskell | Ignore
Language | GHC2021

Language.Haskell.TH.PprLib

Contents

- The document type
- Primitive Documents
- Converting values into documents
- Wrapping documents in delimiters
- Combining documents
- Predicates on documents

Description

Monadic front-end to Text.PrettyPrint

Synopsis

- type Doc = PprM Doc
- data PprM a
- empty :: Doc
- semi :: Doc
- comma :: Doc
- colon :: Doc
- dcolon :: Doc
- space :: Doc
- equals :: Doc
- arrow :: Doc
- lparen :: Doc
- rparen :: Doc
- lbrack :: Doc
- rbrack :: Doc
- lbrace :: Doc
- rbrace :: Doc
- text :: String -> Doc
- char :: Char -> Doc
- ptext :: String -> Doc
- int :: Int -> Doc
- integer :: Integer -> Doc
- float :: Float -> Doc
- double :: Double -> Doc
- rational :: Rational -> Doc
- parens :: Doc -> Doc
- brackets :: Doc -> Doc
- braces :: Doc -> Doc
- quotes :: Doc -> Doc
- doubleQuotes :: Doc -> Doc
- (<>) :: Doc -> Doc -> Doc
- (<+>) :: Doc -> Doc -> Doc
- hcat :: [Doc] -> Doc
- hsep :: [Doc] -> Doc
- ($$) :: Doc -> Doc -> Doc
- ($+$) :: Doc -> Doc -> Doc
- vcat :: [Doc] -> Doc
- sep :: [Doc] -> Doc
- cat :: [Doc] -> Doc
- fsep :: [Doc] -> Doc
- fcat :: [Doc] -> Doc
- nest :: Int -> Doc -> Doc
- hang :: Doc -> Int -> Doc -> Doc
- punctuate :: Doc -> [Doc] -> [Doc]
- isEmpty :: Doc -> PprM Bool
- to_HPJ_Doc :: Doc -> Doc
- pprName :: Name -> Doc
- pprName' :: NameIs -> Name -> Doc

# The document type

type Doc = PprM Doc #

data PprM a #

#### Instances

Instances details

Applicative PprM # |
Instance details Defined in Language.Haskell.TH.PprLib Methods pure :: a -> PprM a # (<*>) :: PprM (a -> b) -> PprM a -> PprM b # liftA2 :: (a -> b -> c) -> PprM a -> PprM b -> PprM c # (*>) :: PprM a -> PprM b -> PprM b # (<*) :: PprM a -> PprM b -> PprM a #
Functor PprM # |
Instance details Defined in Language.Haskell.TH.PprLib Methods fmap :: (a -> b) -> PprM a -> PprM b # (<$) :: a -> PprM b -> PprM a #
Monad PprM # |
Instance details Defined in Language.Haskell.TH.PprLib Methods (>>=) :: PprM a -> (a -> PprM b) -> PprM b # (>>) :: PprM a -> PprM b -> PprM b # return :: a -> PprM a #
Show Doc # |
Instance details Defined in Language.Haskell.TH.PprLib Methods showsPrec :: Int -> Doc -> ShowS # show :: Doc -> String # showList :: [Doc] -> ShowS #

# Primitive Documents

empty #

Arguments

:: Doc | An empty document

semi #

Arguments

:: Doc | A ';' character

comma #

Arguments

:: Doc | A ',' character

colon #

Arguments

:: Doc | A `:` character

dcolon #

Arguments

:: Doc | A "::" string

space #

Arguments

:: Doc | A space character

equals #

Arguments

:: Doc | A '=' character

arrow #

Arguments

:: Doc | A "->" string

lparen #

Arguments

:: Doc | A '(' character

rparen #

Arguments

:: Doc | A ')' character

lbrack #

Arguments

:: Doc | A '[' character

rbrack #

Arguments

:: Doc | A ']' character

lbrace #

Arguments

:: Doc | A '{' character

rbrace #

Arguments

:: Doc | A '}' character

# Converting values into documents

text :: String -> Doc #

char :: Char -> Doc #

ptext :: String -> Doc #

int :: Int -> Doc #

integer :: Integer -> Doc #

float :: Float -> Doc #

double :: Double -> Doc #

rational :: Rational -> Doc #

# Wrapping documents in delimiters

parens #

Arguments

:: Doc |
-> Doc | Wrap document in `(...)`

brackets #

Arguments

:: Doc |
-> Doc | Wrap document in `[...]`

braces #

Arguments

:: Doc |
-> Doc | Wrap document in `{...}`

quotes #

Arguments

:: Doc |
-> Doc | Wrap document in `'...'`

doubleQuotes #

Arguments

:: Doc |
-> Doc | Wrap document in `"..."`

# Combining documents

(<>) infixl 6 #

Arguments

:: Doc |
-> Doc |
-> Doc | Beside

(<+>) infixl 6 #

Arguments

:: Doc |
-> Doc |
-> Doc | Beside, separated by space

hcat #

Arguments

:: [Doc] |
-> Doc | List version of `<>`

hsep #

Arguments

:: [Doc] |
-> Doc | List version of `<+>`

($$) infixl 5 #

Arguments

:: Doc |
-> Doc |
-> Doc | Above; if there is no overlap it "dovetails" the two

($+$) infixl 5 #

Arguments

:: Doc |
-> Doc |
-> Doc | Above, without dovetailing.

vcat #

Arguments

:: [Doc] |
-> Doc | List version of `$$`

sep #

Arguments

:: [Doc] |
-> Doc | Either hsep or vcat

cat #

Arguments

:: [Doc] |
-> Doc | Either hcat or vcat

fsep #

Arguments

:: [Doc] |
-> Doc | "Paragraph fill" version of sep

fcat #

Arguments

:: [Doc] |
-> Doc | "Paragraph fill" version of cat

nest #

Arguments

:: Int |
-> Doc |
-> Doc | Nested

hang #

Arguments

:: Doc |
-> Int |
-> Doc |

-> Doc

    hang d1 n d2 = sep [d1, nest n d2]

punctuate #

Arguments

:: Doc |
-> [Doc] |

-> [Doc]

    punctuate p [d1, ... dn] = [d1 <> p, d2 <> p, ... dn-1 <> p, dn]

# Predicates on documents

isEmpty #

Arguments

:: Doc |
-> PprM Bool | Returns `True` if the document is empty

to_HPJ_Doc :: Doc -> Doc #

pprName :: Name -> Doc #

pprName' :: NameIs -> Name -> Doc #