on 54dfb21 help sign in
elk/src/Reporting/PrettyPrint.hs
46 lines 706 B history raw
1{-# LANGUAGE FlexibleInstances #-}
2module Reporting.PrettyPrint where
4import qualified Data.Map as Map
5import Text.PrettyPrint as P
7import qualified AST.Helpers as Help
10-- PRETTY
12class Pretty a where
13 pretty :: Dealiaser -> Bool -> a -> Doc
16type Dealiaser =
17 Map.Map String String
20-- INSTANCES
22instance Pretty String where
23 pretty _ _ str =
24 P.text str
27-- HELPERS
29commaCat :: [Doc] -> Doc
30commaCat docs =
31 cat (punctuate comma docs)
34commaSep :: [Doc] -> Doc
35commaSep docs =
36 sep (punctuate comma docs)
39parensIf :: Bool -> Doc -> Doc
40parensIf bool doc =
41 if bool then parens doc else doc
44variable :: String -> Doc
45variable x =
46 if Help.isOp x then parens (text x) else text x