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