{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
module PlutusCore.Pretty.Classic
( PrettyConfigClassic (..)
, PrettyClassicBy
, PrettyClassic
, consAnnIf
, defPrettyConfigClassic
, debugPrettyConfigClassic
, prettyClassicDef
, prettyClassicDebug
) where
import PlutusPrelude
import PlutusCore.Pretty.ConfigName
import Prettyprinter.Internal (Doc (Empty))
data PrettyConfigClassic configName = PrettyConfigClassic
{ PrettyConfigClassic configName -> configName
_pccConfigName :: configName
, PrettyConfigClassic configName -> Bool
_pccDisplayAnn :: Bool
}
type instance HasPrettyDefaults (PrettyConfigClassic _) = 'True
type PrettyClassicBy configName = PrettyBy (PrettyConfigClassic configName)
type PrettyClassic = PrettyClassicBy PrettyConfigName
instance configName ~ PrettyConfigName => HasPrettyConfigName (PrettyConfigClassic configName) where
toPrettyConfigName :: PrettyConfigClassic configName -> PrettyConfigName
toPrettyConfigName = PrettyConfigClassic configName -> PrettyConfigName
forall configName. PrettyConfigClassic configName -> configName
_pccConfigName
isEmptyDoc :: Doc ann -> Bool
isEmptyDoc :: Doc ann -> Bool
isEmptyDoc Doc ann
Empty = Bool
True
isEmptyDoc Doc ann
_ = Bool
False
consAnnIf :: Pretty ann => PrettyConfigClassic configName -> ann -> [Doc dann] -> [Doc dann]
consAnnIf :: PrettyConfigClassic configName -> ann -> [Doc dann] -> [Doc dann]
consAnnIf PrettyConfigClassic configName
config ann
ann [Doc dann]
rest = (Doc dann -> Bool) -> [Doc dann] -> [Doc dann]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Doc dann -> Bool) -> Doc dann -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc dann -> Bool
forall ann. Doc ann -> Bool
isEmptyDoc) [ann -> Doc dann
forall a ann. Pretty a => a -> Doc ann
pretty ann
ann | PrettyConfigClassic configName -> Bool
forall configName. PrettyConfigClassic configName -> Bool
_pccDisplayAnn PrettyConfigClassic configName
config] [Doc dann] -> [Doc dann] -> [Doc dann]
forall a. [a] -> [a] -> [a]
++ [Doc dann]
rest
defPrettyConfigClassic :: PrettyConfigClassic PrettyConfigName
defPrettyConfigClassic :: PrettyConfigClassic PrettyConfigName
defPrettyConfigClassic = PrettyConfigName -> Bool -> PrettyConfigClassic PrettyConfigName
forall configName.
configName -> Bool -> PrettyConfigClassic configName
PrettyConfigClassic PrettyConfigName
defPrettyConfigName Bool
False
debugPrettyConfigClassic :: PrettyConfigClassic PrettyConfigName
debugPrettyConfigClassic :: PrettyConfigClassic PrettyConfigName
debugPrettyConfigClassic = PrettyConfigName -> Bool -> PrettyConfigClassic PrettyConfigName
forall configName.
configName -> Bool -> PrettyConfigClassic configName
PrettyConfigClassic PrettyConfigName
debugPrettyConfigName Bool
False
prettyClassicDef :: PrettyClassic a => a -> Doc ann
prettyClassicDef :: a -> Doc ann
prettyClassicDef = PrettyConfigClassic PrettyConfigName -> a -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic PrettyConfigName
defPrettyConfigClassic
prettyClassicDebug :: PrettyClassic a => a -> Doc ann
prettyClassicDebug :: a -> Doc ann
prettyClassicDebug = PrettyConfigClassic PrettyConfigName -> a -> Doc ann
forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy PrettyConfigClassic PrettyConfigName
debugPrettyConfigClassic