on 9b0c310 help sign in
elk/src/Reporting/PrettyPrint.hs
34 lines 577 B history raw
1{-# LANGUAGE FlexibleInstances #-}
2module Reporting.PrettyPrint where
4import Text.PrettyPrint as P
5import qualified AST.Helpers as Help
8class Pretty a where
9 pretty :: Bool -> a -> Doc
12instance Pretty String where
13 pretty _ str =
14 P.text str
17commaCat :: [Doc] -> Doc
18commaCat docs =
19 cat (punctuate comma docs)
22commaSep :: [Doc] -> Doc
23commaSep docs =
24 sep (punctuate comma docs)
27parensIf :: Bool -> Doc -> Doc
28parensIf bool doc =
29 if bool then parens doc else doc
32variable :: String -> Doc
33variable x =
34 if Help.isOp x then parens (text x) else text x