ligo/tools/lsp/squirrel/src/Pretty.hs

30 lines
556 B
Haskell
Raw Normal View History

2020-05-08 01:18:26 +04:00
{-
Pretty printer, based on GHC one.
-}
module Pretty
( module Pretty
, module Text.PrettyPrint
)
where
import Data.Text
import Text.PrettyPrint hiding ((<>))
2020-05-08 01:18:26 +04:00
-- | With this, one can `data X = ...; derive Show via PP X`
newtype PP a = PP { unPP :: a }
instance Pretty a => Show (PP a) where
show = show . pp . unPP
2020-05-08 01:18:26 +04:00
-- | Pretty-printable types.
class Pretty p where
pp :: p -> Doc
2020-05-08 01:18:26 +04:00
-- | Common instance.
instance Pretty Text where
pp = text . unpack
2020-05-08 01:18:26 +04:00
-- | TODO: tuple, not list; actually /use/ it.
wrap [l, r] a = hang (hang l 2 r) 0 r