module TextShow.Text.PrettyPrint (
renderB
, renderStyleB
#if MIN_VERSION_pretty(1,1,3)
, renderAnnotB
, renderStyleAnnotB
#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)
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
#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
#endif
instance TextShow Doc where
showb = renderB
$(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
instance TextShow1 Annot.Doc where
liftShowbPrec _ _ = showbPrec
$(deriveTextShow ''Annot.PrettyLevel)
$(deriveTextShow ''Span)
$(deriveTextShow1 ''Span)
#endif