Copyright : (c) Klaus L�ttich, C. Maeder Uni Bremen 2002-2004
Maintainer : luettich@tzi.de
A very simplified version of John Hughes's
and Simon Peyton Jones's Pretty Printer Combinators. Only catenable
string sequences are left over
-- * Primitive SDocuments
-- * Converting values into documents
-- * Wrapping documents in delimiters
parens, brackets, braces,
render, fullRender, writeFileSDoc
-- ---------------------------------------------------------------------------
-- The primitive SDoc values
empty :: SDoc; -- ^ An empty document
comma :: SDoc; -- ^ A ',' character
parens :: SDoc -> SDoc; -- ^ Wrap document in @(...)@
brackets :: SDoc -> SDoc; -- ^ Wrap document in @[...]@
braces :: SDoc -> SDoc; -- ^ Wrap document in @{...}@
-- Combining @SDoc@ values
(<>) :: SDoc -> SDoc -> SDoc; -- ^Beside
-- Displaying @SDoc@ values.
showsPrec _prec doc cont = showSDoc doc cont
-- | Renders the document as a string using the default style
parens p = text "(" <> p <> text ")"
brackets p = text "[" <> p <> text "]"
braces p = text "{" <> p <> text "}"
-- ---------------------------------------------------------------------------
-- A SDoc represents a *set* of layouts. A SDoc with
-- no occurrences of Union or NoSDoc represents just one layout.
-- | The abstract type of documents
-- ---------------------------------------------------------------------------
-- ---------------------------------------------------------------------------
-- Horizontal composition @<>@
-- ---------------------------------------------------------------------------
-- Displaying the best layout
writeFileSDoc :: FilePath -> SDoc -> IO ()
do h <- openFile fp WriteMode
fullRender (hPutStr h) (>>) sd
render doc = showSDoc doc ""
showSDoc :: SDoc -> String -> String
showSDoc doc = fullRender showString (.) doc
fullRender :: (String -> a)
lay (Beside p q) = lay p `comp` lay q