ppr debug flags

ddump-parsed
This commit is contained in:
crumbtoo
2024-02-08 09:26:53 -07:00
parent 1079fc7c9b
commit 6c943af4a1
14 changed files with 244 additions and 41 deletions

View File

@@ -1,17 +1,51 @@
{-# LANGUAGE OverloadedStrings #-}
module Data.Pretty
( Pretty(..)
, ttext
-- * Pretty-printing lens combinators
, hsepOf, vsepOf
, module Text.PrettyPrint
, maybeParens
)
where
----------------------------------------------------------------------------------
import Data.String (IsString(..))
import Text.PrettyPrint hiding ((<>))
import Text.PrettyPrint.HughesPJ hiding ((<>))
import Data.String (IsString(..))
import Data.Text.Lens
import Data.Monoid
import Data.Text qualified as T
import Control.Lens
----------------------------------------------------------------------------------
class Pretty a where
-- pretty :: a -> ISeq
-- prettyPrec :: a -> Int -> ISeq
pretty :: a -> Doc
prettyPrec :: Int -> a -> Doc
-- {-# MINIMAL pretty | prettyPrec #-}
-- pretty a = prettyPrec a 0
-- prettyPrec a _ = iBracket (pretty a)
{-# MINIMAL pretty | prettyPrec #-}
pretty = prettyPrec 0
prettyPrec a _ = pretty a
instance Pretty String where
pretty = Text.PrettyPrint.text
instance Pretty T.Text where
pretty = Text.PrettyPrint.text . view unpacked
newtype Showing a = Showing a
instance (Show a) => Pretty (Showing a) where
prettyPrec p (Showing a) = fromString $ showsPrec p a ""
deriving via Showing Int instance Pretty Int
--------------------------------------------------------------------------------
ttext :: Pretty t => t -> Doc
ttext = pretty
hsepOf :: Getting (Endo Doc) s Doc -> s -> Doc
hsepOf l = foldrOf l (<+>) mempty
vsepOf :: Getting (Endo Doc) s Doc -> s -> Doc
vsepOf l = foldrOf l ($+$) mempty