module Text.Show.Text.Data.Data (
showbConstr
, showbConstrRepPrec
, showbDataRepPrec
, showbDataTypePrec
, showbFixity
) where
import Data.Data (Constr, ConstrRep(..), DataRep(..), DataType, Fixity(..),
dataTypeName, dataTypeRep, showConstr)
import Data.Text.Lazy.Builder (Builder, fromString)
import GHC.Show (appPrec, appPrec1)
import Prelude hiding (Show)
import Text.Show.Text.Class (Show(showb, showbPrec), showbParen)
import Text.Show.Text.Data.Char (showbChar)
import Text.Show.Text.Data.Integral (showbIntPrec, showbIntegerPrec, showbRatioPrec)
import Text.Show.Text.Data.List ()
import Text.Show.Text.Utils ((<>), s)
showbDataTypePrec :: Int -> DataType -> Builder
showbDataTypePrec p dt = showbParen (p > appPrec) $
"DataType {tycon = "
<> showb (dataTypeName dt)
<> ", datarep = "
<> showb (dataTypeRep dt)
<> s '}'
showbDataRepPrec :: Int -> DataRep -> Builder
showbDataRepPrec p (AlgRep cs) = showbParen (p > appPrec) $ "AlgRep " <> showb cs
showbDataRepPrec _ IntRep = "IntRep"
showbDataRepPrec _ FloatRep = "FloatRep"
showbDataRepPrec _ CharRep = "CharRep"
showbDataRepPrec _ NoRep = "NoRep"
showbConstr :: Constr -> Builder
showbConstr = fromString . showConstr
showbFixity :: Fixity -> Builder
showbFixity Prefix = "Prefix"
showbFixity Infix = "Infix"
showbConstrRepPrec :: Int -> ConstrRep -> Builder
showbConstrRepPrec p (AlgConstr ci)
= showbParen (p > appPrec) $ "AlgConstr " <> showbIntPrec appPrec1 ci
showbConstrRepPrec p (IntConstr i)
= showbParen (p > appPrec) $ "IntConstr " <> showbIntegerPrec appPrec1 i
showbConstrRepPrec p (FloatConstr r)
= showbParen (p > appPrec) $ "FloatConstr " <> showbRatioPrec appPrec1 r
showbConstrRepPrec p (CharConstr c)
= showbParen (p > appPrec) $ "CharConstr " <> showbChar c
instance Show DataType where
showbPrec = showbDataTypePrec
instance Show DataRep where
showbPrec = showbDataRepPrec
instance Show Constr where
showb = showbConstr
instance Show ConstrRep where
showbPrec = showbConstrRepPrec
instance Show Fixity where
showb = showbFixity