-- | Common 'Doc'-related functions for writting printers with a little more clarity.
module Utils.Drasil.Document (blank, indent, (+:+.), indentList) where

import Text.PrettyPrint.HughesPJ (Doc, nest, text, vcat)

-- | Creates a blank document with no text.
blank :: Doc
blank :: Doc
blank = String -> Doc
text ""

-- | Indents a document (by 4 spaces).
indent :: Doc -> Doc
indent :: Doc -> Doc
indent = Int -> Doc -> Doc
nest 4

-- | Helper which concatenates two Docs and appends a period.
(+:+.) :: Doc -> Doc -> Doc
a :: Doc
a +:+. :: Doc -> Doc -> Doc
+:+. b :: Doc
b = Doc
a Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> Doc
b Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
<> String -> Doc
text "."

-- | Indents a list of Docs and combines into one Doc.
indentList :: [Doc] -> Doc
indentList :: [Doc] -> Doc
indentList = [Doc] -> Doc
vcat ([Doc] -> Doc) -> ([Doc] -> [Doc]) -> [Doc] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Doc -> Doc) -> [Doc] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Doc -> Doc
indent  -- TODO: Isn't this just `indent . vcat`? This would be a bit more efficient too