on e4e8d89 help sign in
elk/compiler/SourceSyntax/PrettyPrint.hs
22 lines 489 B history raw
2module SourceSyntax.PrettyPrint where
4import Text.PrettyPrint
5import SourceSyntax.Location
6import qualified SourceSyntax.Helpers as Help
8class Pretty a where
9 pretty :: a -> Doc
11instance Pretty a => Pretty (Located a) where
12 pretty (L _ e) = pretty e
14instance Pretty () where
15 pretty () = empty
17commaCat docs = cat (punctuate comma docs)
18commaSep docs = sep (punctuate comma docs)
20parensIf bool doc = if bool then parens doc else doc
22variable x = parensIf (Help.isOp x) (text x)