#if __GLASGOW_HASKELL__ >= 701
{-# LANGUAGE Safe #-}
#endif
module Text.PrettyPrint.HughesPJClass (
Pretty(..),
PrettyLevel(..), prettyNormal,
prettyShow, prettyParen,
module Text.PrettyPrint.HughesPJ
) where
import Text.PrettyPrint.HughesPJ
newtype PrettyLevel = PrettyLevel Int
deriving (PrettyLevel -> PrettyLevel -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PrettyLevel -> PrettyLevel -> Bool
$c/= :: PrettyLevel -> PrettyLevel -> Bool
== :: PrettyLevel -> PrettyLevel -> Bool
$c== :: PrettyLevel -> PrettyLevel -> Bool
Eq, Eq PrettyLevel
PrettyLevel -> PrettyLevel -> Bool
PrettyLevel -> PrettyLevel -> Ordering
PrettyLevel -> PrettyLevel -> PrettyLevel
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: PrettyLevel -> PrettyLevel -> PrettyLevel
$cmin :: PrettyLevel -> PrettyLevel -> PrettyLevel
max :: PrettyLevel -> PrettyLevel -> PrettyLevel
$cmax :: PrettyLevel -> PrettyLevel -> PrettyLevel
>= :: PrettyLevel -> PrettyLevel -> Bool
$c>= :: PrettyLevel -> PrettyLevel -> Bool
> :: PrettyLevel -> PrettyLevel -> Bool
$c> :: PrettyLevel -> PrettyLevel -> Bool
<= :: PrettyLevel -> PrettyLevel -> Bool
$c<= :: PrettyLevel -> PrettyLevel -> Bool
< :: PrettyLevel -> PrettyLevel -> Bool
$c< :: PrettyLevel -> PrettyLevel -> Bool
compare :: PrettyLevel -> PrettyLevel -> Ordering
$ccompare :: PrettyLevel -> PrettyLevel -> Ordering
Ord, Int -> PrettyLevel -> ShowS
[PrettyLevel] -> ShowS
PrettyLevel -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PrettyLevel] -> ShowS
$cshowList :: [PrettyLevel] -> ShowS
show :: PrettyLevel -> String
$cshow :: PrettyLevel -> String
showsPrec :: Int -> PrettyLevel -> ShowS
$cshowsPrec :: Int -> PrettyLevel -> ShowS
Show)
prettyNormal :: PrettyLevel
prettyNormal :: PrettyLevel
prettyNormal = Int -> PrettyLevel
PrettyLevel Int
0
class Pretty a where
pPrintPrec :: PrettyLevel -> Rational -> a -> Doc
pPrintPrec PrettyLevel
_ Rational
_ = forall a. Pretty a => a -> Doc
pPrint
pPrint :: a -> Doc
pPrint = forall a. Pretty a => PrettyLevel -> Rational -> a -> Doc
pPrintPrec PrettyLevel
prettyNormal Rational
0
pPrintList :: PrettyLevel -> [a] -> Doc
pPrintList PrettyLevel
l = Doc -> Doc
brackets forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Doc] -> Doc
fsep forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> [Doc] -> [Doc]
punctuate Doc
comma forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (forall a. Pretty a => PrettyLevel -> Rational -> a -> Doc
pPrintPrec PrettyLevel
l Rational
0)
#if __GLASGOW_HASKELL__ >= 708
{-# MINIMAL pPrintPrec | pPrint #-}
#endif
prettyShow :: (Pretty a) => a -> String
prettyShow :: forall a. Pretty a => a -> String
prettyShow = Doc -> String
render forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Pretty a => a -> Doc
pPrint
pPrint0 :: (Pretty a) => PrettyLevel -> a -> Doc
pPrint0 :: forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l = forall a. Pretty a => PrettyLevel -> Rational -> a -> Doc
pPrintPrec PrettyLevel
l Rational
0
appPrec :: Rational
appPrec :: Rational
appPrec = Rational
10
{-# DEPRECATED prettyParen "Please use 'maybeParens' instead" #-}
prettyParen :: Bool -> Doc -> Doc
prettyParen :: Bool -> Doc -> Doc
prettyParen = Bool -> Doc -> Doc
maybeParens
instance Pretty Int where pPrint :: Int -> Doc
pPrint = Int -> Doc
int
instance Pretty Integer where pPrint :: Integer -> Doc
pPrint = Integer -> Doc
integer
instance Pretty Float where pPrint :: Float -> Doc
pPrint = Float -> Doc
float
instance Pretty Double where pPrint :: Double -> Doc
pPrint = Double -> Doc
double
instance Pretty () where pPrint :: () -> Doc
pPrint ()
_ = String -> Doc
text String
"()"
instance Pretty Bool where pPrint :: Bool -> Doc
pPrint = String -> Doc
text forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
instance Pretty Ordering where pPrint :: Ordering -> Doc
pPrint = String -> Doc
text forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
instance Pretty Char where
pPrint :: Char -> Doc
pPrint = Char -> Doc
char
pPrintList :: PrettyLevel -> String -> Doc
pPrintList PrettyLevel
_ = String -> Doc
text forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show
instance (Pretty a) => Pretty (Maybe a) where
pPrintPrec :: PrettyLevel -> Rational -> Maybe a -> Doc
pPrintPrec PrettyLevel
_ Rational
_ Maybe a
Nothing = String -> Doc
text String
"Nothing"
pPrintPrec PrettyLevel
l Rational
p (Just a
x) =
Bool -> Doc -> Doc
prettyParen (Rational
p forall a. Ord a => a -> a -> Bool
> Rational
appPrec) forall a b. (a -> b) -> a -> b
$ String -> Doc
text String
"Just" Doc -> Doc -> Doc
<+> forall a. Pretty a => PrettyLevel -> Rational -> a -> Doc
pPrintPrec PrettyLevel
l (Rational
appPrecforall a. Num a => a -> a -> a
+Rational
1) a
x
instance (Pretty a, Pretty b) => Pretty (Either a b) where
pPrintPrec :: PrettyLevel -> Rational -> Either a b -> Doc
pPrintPrec PrettyLevel
l Rational
p (Left a
x) =
Bool -> Doc -> Doc
prettyParen (Rational
p forall a. Ord a => a -> a -> Bool
> Rational
appPrec) forall a b. (a -> b) -> a -> b
$ String -> Doc
text String
"Left" Doc -> Doc -> Doc
<+> forall a. Pretty a => PrettyLevel -> Rational -> a -> Doc
pPrintPrec PrettyLevel
l (Rational
appPrecforall a. Num a => a -> a -> a
+Rational
1) a
x
pPrintPrec PrettyLevel
l Rational
p (Right b
x) =
Bool -> Doc -> Doc
prettyParen (Rational
p forall a. Ord a => a -> a -> Bool
> Rational
appPrec) forall a b. (a -> b) -> a -> b
$ String -> Doc
text String
"Right" Doc -> Doc -> Doc
<+> forall a. Pretty a => PrettyLevel -> Rational -> a -> Doc
pPrintPrec PrettyLevel
l (Rational
appPrecforall a. Num a => a -> a -> a
+Rational
1) b
x
instance (Pretty a) => Pretty [a] where
pPrintPrec :: PrettyLevel -> Rational -> [a] -> Doc
pPrintPrec PrettyLevel
l Rational
_ = forall a. Pretty a => PrettyLevel -> [a] -> Doc
pPrintList PrettyLevel
l
instance (Pretty a, Pretty b) => Pretty (a, b) where
pPrintPrec :: PrettyLevel -> Rational -> (a, b) -> Doc
pPrintPrec PrettyLevel
l Rational
_ (a
a, b
b) =
Doc -> Doc
parens forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
fsep forall a b. (a -> b) -> a -> b
$ Doc -> [Doc] -> [Doc]
punctuate Doc
comma [forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l a
a, forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l b
b]
instance (Pretty a, Pretty b, Pretty c) => Pretty (a, b, c) where
pPrintPrec :: PrettyLevel -> Rational -> (a, b, c) -> Doc
pPrintPrec PrettyLevel
l Rational
_ (a
a, b
b, c
c) =
Doc -> Doc
parens forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
fsep forall a b. (a -> b) -> a -> b
$ Doc -> [Doc] -> [Doc]
punctuate Doc
comma [forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l a
a, forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l b
b, forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l c
c]
instance (Pretty a, Pretty b, Pretty c, Pretty d) => Pretty (a, b, c, d) where
pPrintPrec :: PrettyLevel -> Rational -> (a, b, c, d) -> Doc
pPrintPrec PrettyLevel
l Rational
_ (a
a, b
b, c
c, d
d) =
Doc -> Doc
parens forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
fsep forall a b. (a -> b) -> a -> b
$ Doc -> [Doc] -> [Doc]
punctuate Doc
comma
[forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l a
a, forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l b
b, forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l c
c, forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l d
d]
instance (Pretty a, Pretty b, Pretty c, Pretty d, Pretty e) => Pretty (a, b, c, d, e) where
pPrintPrec :: PrettyLevel -> Rational -> (a, b, c, d, e) -> Doc
pPrintPrec PrettyLevel
l Rational
_ (a
a, b
b, c
c, d
d, e
e) =
Doc -> Doc
parens forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
fsep forall a b. (a -> b) -> a -> b
$ Doc -> [Doc] -> [Doc]
punctuate Doc
comma
[forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l a
a, forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l b
b, forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l c
c, forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l d
d, forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l e
e]
instance (Pretty a, Pretty b, Pretty c, Pretty d, Pretty e, Pretty f) => Pretty (a, b, c, d, e, f) where
pPrintPrec :: PrettyLevel -> Rational -> (a, b, c, d, e, f) -> Doc
pPrintPrec PrettyLevel
l Rational
_ (a
a, b
b, c
c, d
d, e
e, f
f) =
Doc -> Doc
parens forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
fsep forall a b. (a -> b) -> a -> b
$ Doc -> [Doc] -> [Doc]
punctuate Doc
comma
[forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l a
a, forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l b
b, forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l c
c,
forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l d
d, forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l e
e, forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l f
f]
instance (Pretty a, Pretty b, Pretty c, Pretty d, Pretty e, Pretty f, Pretty g) =>
Pretty (a, b, c, d, e, f, g) where
pPrintPrec :: PrettyLevel -> Rational -> (a, b, c, d, e, f, g) -> Doc
pPrintPrec PrettyLevel
l Rational
_ (a
a, b
b, c
c, d
d, e
e, f
f, g
g) =
Doc -> Doc
parens forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
fsep forall a b. (a -> b) -> a -> b
$ Doc -> [Doc] -> [Doc]
punctuate Doc
comma
[forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l a
a, forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l b
b, forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l c
c,
forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l d
d, forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l e
e, forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l f
f, forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l g
g]
instance (Pretty a, Pretty b, Pretty c, Pretty d, Pretty e, Pretty f, Pretty g, Pretty h) =>
Pretty (a, b, c, d, e, f, g, h) where
pPrintPrec :: PrettyLevel -> Rational -> (a, b, c, d, e, f, g, h) -> Doc
pPrintPrec PrettyLevel
l Rational
_ (a
a, b
b, c
c, d
d, e
e, f
f, g
g, h
h) =
Doc -> Doc
parens forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
fsep forall a b. (a -> b) -> a -> b
$ Doc -> [Doc] -> [Doc]
punctuate Doc
comma
[forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l a
a, forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l b
b, forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l c
c,
forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l d
d, forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l e
e, forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l f
f, forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l g
g, forall a. Pretty a => PrettyLevel -> a -> Doc
pPrint0 PrettyLevel
l h
h]