summaryrefslogtreecommitdiff
path: root/src/compiler/GF/Text
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2014-07-27 22:13:13 +0000
committerhallgren <hallgren@chalmers.se>2014-07-27 22:13:13 +0000
commit59172ce9c5baf593e3110036a14c910da80878f7 (patch)
tree9ef752a113b9cbc84a04971ca2a7338eaeac6a50 /src/compiler/GF/Text
parent30cda5151651e712803527b6ab4e5abc07536f2c (diff)
Adding GF.Infra.Location and GF.Text.Pretty (forgot to 'darcs add' them before)
Diffstat (limited to 'src/compiler/GF/Text')
-rw-r--r--src/compiler/GF/Text/Pretty.hs47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/compiler/GF/Text/Pretty.hs b/src/compiler/GF/Text/Pretty.hs
new file mode 100644
index 000000000..29ca7f131
--- /dev/null
+++ b/src/compiler/GF/Text/Pretty.hs
@@ -0,0 +1,47 @@
+-- | Pretty printing with class
+module GF.Text.Pretty(module GF.Text.Pretty,module PP) where
+import qualified Text.PrettyPrint as PP
+import Text.PrettyPrint as PP(Doc,Style(..),Mode(..),style,empty,isEmpty)
+
+class Pretty a where
+ pp :: a -> Doc
+ ppList :: [a] -> Doc
+ ppList = fsep . map pp -- hmm
+
+instance Pretty Doc where pp = id
+instance Pretty Int where pp = PP.int
+instance Pretty Integer where pp = PP.integer
+instance Pretty Float where pp = PP.float
+instance Pretty Double where pp = PP.double
+instance Pretty Char where pp = PP.char; ppList = PP.text
+
+instance Pretty a => Pretty [a] where
+ pp = ppList
+ ppList = fsep . map pp -- hmm
+
+render x = PP.render (pp x)
+renderStyle s x = PP.renderStyle s (pp x)
+
+infixl 5 $$,$+$
+infixl 6 <>,<+>
+
+x $$ y = pp x PP.$$ pp y
+x $+$ y = pp x PP.$+$ pp y
+x <+> y = pp x PP.<+> pp y
+x <> y = pp x PP.<> pp y
+
+braces x = PP.braces (pp x)
+brackets x = PP.brackets (pp x)
+cat xs = PP.cat (map pp xs)
+doubleQuotes x = PP.doubleQuotes (pp x)
+fcat xs = PP.fcat (map pp xs)
+fsep xs = PP.fsep (map pp xs)
+hang x d y = PP.hang (pp x) d (pp y)
+hcat xs = PP.hcat (map pp xs)
+hsep xs = PP.hsep (map pp xs)
+nest d x = PP.nest d (pp x)
+parens x = PP.parens (pp x)
+punctuate x ys = PP.punctuate (pp x) (map pp ys)
+quotes x = PP.quotes (pp x)
+sep xs = PP.sep (map pp xs)
+vcat xs = PP.vcat (map pp xs)