module Text.Show.Text.GHC.Generics (
showbU1
, showbPar1Prec
, showbRec1Prec
, showbK1Prec
, showbM1Prec
, showbSumTypePrec
, showbProductTypePrec
, showbCompFunctorsPrec
, showbFixityPrec
, showbAssociativity
, showbArityPrec
) where
import Data.Text.Lazy.Builder (Builder)
import GHC.Generics (U1(..), Par1, Rec1(..), K1(..),
M1(..), (:+:)(..), (:*:)(..), (:.:)(..),
Fixity, Associativity, Arity)
import GHC.Show (appPrec, appPrec1)
import Prelude hiding (Show)
import Text.Show.Text.Class (Show(showb, showbPrec), showbParen)
import Text.Show.Text.Data.Integral ()
import Text.Show.Text.TH.Internal (deriveShow)
import Text.Show.Text.Utils ((<>), s)
showbU1 :: U1 p -> Builder
showbU1 U1 = "U1"
showbPar1Prec :: Show p => Int -> Par1 p -> Builder
showbPar1Prec = showbPrec
showbRec1Prec :: Show (f p) => Int -> Rec1 f p -> Builder
showbRec1Prec p (Rec1 ur) = showbParen (p > appPrec) $
"Rec1 {unRec1 = " <> showb ur <> s '}'
showbK1Prec :: Show c => Int -> K1 i c p -> Builder
showbK1Prec p (K1 uk) = showbParen (p > appPrec) $
"K1 {unK1 = " <> showb uk <> s '}'
showbM1Prec :: Show (f p) => Int -> M1 i c f p -> Builder
showbM1Prec p (M1 um) = showbParen (p > appPrec) $
"M1 {unM1 = " <> showb um <> s '}'
showbSumTypePrec :: (Show (f p), Show (g p)) => Int -> (f :+: g) p -> Builder
showbSumTypePrec p (L1 l) = showbParen (p > appPrec) $ "L1 " <> showbPrec appPrec1 l
showbSumTypePrec p (R1 r) = showbParen (p > appPrec) $ "R1 " <> showbPrec appPrec1 r
showbProductTypePrec :: (Show (f p), Show (g p)) => Int -> (f :*: g) p -> Builder
showbProductTypePrec p (l :*: r) = showbParen (p > prec) $
showbPrec (prec + 1) l
<> " :*: "
<> showbPrec (prec + 1) r
where
prec :: Int
prec = 6
showbCompFunctorsPrec :: Show (f (g p)) => Int -> (f :.: g) p -> Builder
showbCompFunctorsPrec p (Comp1 uc) = showbParen (p > appPrec) $
"Comp1 {unComp1 = " <> showb uc <> s '}'
showbFixityPrec :: Int -> Fixity -> Builder
showbFixityPrec = showbPrec
showbAssociativity :: Associativity -> Builder
showbAssociativity = showb
showbArityPrec :: Int -> Arity -> Builder
showbArityPrec = showbPrec
instance Show (U1 p) where
showb = showbU1
$(deriveShow ''Par1)
instance Show (f p) => Show (Rec1 f p) where
showbPrec = showbRec1Prec
instance Show c => Show (K1 i c p) where
showbPrec = showbK1Prec
instance Show (f p) => Show (M1 i c f p) where
showbPrec = showbM1Prec
instance (Show (f p), Show (g p)) => Show ((f :+: g) p) where
showbPrec = showbSumTypePrec
instance (Show (f p), Show (g p)) => Show ((f :*: g) p) where
showbPrec = showbProductTypePrec
instance Show (f (g p)) => Show ((f :.: g) p) where
showbPrec = showbCompFunctorsPrec
$(deriveShow ''Fixity)
$(deriveShow ''Associativity)
$(deriveShow ''Arity)