module Clash.Pretty where

import Data.Text.Prettyprint.Doc
import Data.Text.Prettyprint.Doc.Render.String

showDoc :: Doc ann -> String
showDoc :: Doc ann -> String
showDoc = SimpleDocStream ann -> String
forall ann. SimpleDocStream ann -> String
renderString (SimpleDocStream ann -> String)
-> (Doc ann -> SimpleDocStream ann) -> Doc ann -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LayoutOptions -> Doc ann -> SimpleDocStream ann
forall ann. LayoutOptions -> Doc ann -> SimpleDocStream ann
layoutPretty (PageWidth -> LayoutOptions
LayoutOptions (Int -> Double -> PageWidth
AvailablePerLine 80 0.6))

removeAnnotations :: Doc ann -> Doc ()
removeAnnotations :: Doc ann -> Doc ()
removeAnnotations = (ann -> ()) -> Doc ann -> Doc ()
forall ann ann'. (ann -> ann') -> Doc ann -> Doc ann'
reAnnotate ((ann -> ()) -> Doc ann -> Doc ())
-> (ann -> ()) -> Doc ann -> Doc ()
forall a b. (a -> b) -> a -> b
$ () -> ann -> ()
forall a b. a -> b -> a
const ()

-- | A variant of @Pretty@ that is not polymorphic on the type of annotations.
-- This is needed to derive instances from Clash's pretty printer (PrettyPrec),
-- which annotates documents with Clash-specific information and, therefore,
-- fixes the type of annotations.
class ClashPretty a where
  clashPretty :: a -> Doc ()

fromPretty :: Pretty a => a -> Doc ()
fromPretty :: a -> Doc ()
fromPretty = Doc Any -> Doc ()
forall ann. Doc ann -> Doc ()
removeAnnotations (Doc Any -> Doc ()) -> (a -> Doc Any) -> a -> Doc ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Doc Any
forall a ann. Pretty a => a -> Doc ann
pretty