module TextShow.Text.PrettyPrint (
renderB
, renderStyleB
#if MIN_VERSION_pretty(1,1,3)
, renderAnnotB
, renderStyleAnnotB
#endif
, showbMode
, showbStylePrec
, showbTextDetailsPrec
#if MIN_VERSION_pretty(1,1,2)
, showbPrettyLevelPrec
#endif
#if MIN_VERSION_pretty(1,1,3)
, liftShowbAnnotDetailsPrec
, showbPrettyLevelAnnotPrec
, liftShowbSpanPrec
#endif
) where
import Data.Monoid.Compat
import Text.PrettyPrint.HughesPJ (Doc, Mode, Style(..), TextDetails(..),
fullRender, style)
#if MIN_VERSION_pretty(1,1,2)
import Text.PrettyPrint.HughesPJClass (PrettyLevel)
#endif
#if MIN_VERSION_pretty(1,1,3)
import qualified Text.PrettyPrint.Annotated.HughesPJ as Annot (Doc, fullRender, style)
import Text.PrettyPrint.Annotated.HughesPJ (AnnotDetails, Span)
import qualified Text.PrettyPrint.Annotated.HughesPJClass as Annot (PrettyLevel)
import TextShow (TextShow1(..))
import TextShow.TH (deriveTextShow1)
#endif
import TextShow (TextShow(..), Builder, fromString, singleton)
import TextShow.TH (deriveTextShow)
#include "inline.h"
renderB :: Doc -> Builder
renderB = renderStyleB style
renderStyleB :: Style -> Doc -> Builder
renderStyleB sty doc = fullRender (mode sty)
(lineLength sty)
(ribbonsPerLine sty)
txtPrinter
mempty
doc
txtPrinter :: TextDetails -> Builder -> Builder
txtPrinter (Chr c) b = singleton c <> b
txtPrinter (Str s') b = fromString s' <> b
txtPrinter (PStr s') b = fromString s' <> b
showbMode :: Mode -> Builder
showbMode = showb
showbStylePrec :: Int -> Style -> Builder
showbStylePrec = showbPrec
showbTextDetailsPrec :: Int -> TextDetails -> Builder
showbTextDetailsPrec = showbPrec
#if MIN_VERSION_pretty(1,1,2)
showbPrettyLevelPrec :: Int -> PrettyLevel -> Builder
showbPrettyLevelPrec = showbPrec
#endif
#if MIN_VERSION_pretty(1,1,3)
renderAnnotB :: Annot.Doc a -> Builder
renderAnnotB = renderStyleAnnotB Annot.style
renderStyleAnnotB :: Style -> Annot.Doc a -> Builder
renderStyleAnnotB sty doc =
Annot.fullRender (mode sty)
(lineLength sty)
(ribbonsPerLine sty)
txtPrinter
mempty
doc
liftShowbAnnotDetailsPrec :: (Int -> a -> Builder) -> Int -> AnnotDetails a -> Builder
liftShowbAnnotDetailsPrec sp = liftShowbPrec sp undefined
showbPrettyLevelAnnotPrec :: Int -> Annot.PrettyLevel -> Builder
showbPrettyLevelAnnotPrec = showbPrec
liftShowbSpanPrec :: (Int -> a -> Builder) -> Int -> Span a -> Builder
liftShowbSpanPrec sp = liftShowbPrec sp undefined
#endif
instance TextShow Doc where
showb = renderB
INLINE_INST_FUN(showb)
$(deriveTextShow ''Mode)
$(deriveTextShow ''Style)
$(deriveTextShow ''TextDetails)
#if MIN_VERSION_pretty(1,1,2)
$(deriveTextShow ''PrettyLevel)
#endif
#if MIN_VERSION_pretty(1,1,3)
$(deriveTextShow ''AnnotDetails)
$(deriveTextShow1 ''AnnotDetails)
instance TextShow (Annot.Doc a) where
showb = renderAnnotB
INLINE_INST_FUN(showb)
instance TextShow1 Annot.Doc where
liftShowbPrec _ _ = showbPrec
INLINE_INST_FUN(liftShowbPrec)
$(deriveTextShow ''Annot.PrettyLevel)
$(deriveTextShow ''Span)
$(deriveTextShow1 ''Span)
#endif