wumpus-basic-0.21.0: Basic objects and system code built on Wumpus-Core.

PortabilityGHC
Stabilityhighly unstable
MaintainerStephen Tetley <stephen.tetley@gmail.com>

Wumpus.Basic.Utils.FormatCombinators

Description

Formatting combinators - pretty printers without the fitting.

Note - indentation support is very limited. Generally one should use a proper pretty printing library.

Synopsis

Documentation

data Doc Source

Doc is a Join List ...

Instances

type DocS = Doc -> DocSource

class Format a whereSource

Methods

format :: a -> DocSource

empty :: DocSource

Create an empty, zero length document.

showsDoc :: ShowS -> DocSource

Create a document from a ShowS function.

(<>) :: Doc -> Doc -> DocSource

Horizontally concatenate two documents with no space between them.

(<+>) :: Doc -> Doc -> DocSource

Horizontally concatenate two documents with a single space between them.

vconcat :: Doc -> Doc -> DocSource

Vertical concatenate two documents with a line break.

hcat :: [Doc] -> DocSource

Horizontally concatenate a list of documents with (<>).

hsep :: [Doc] -> DocSource

Horizontally concatenate a list of documents with (<+>).

vcat :: [Doc] -> DocSource

Vertically concatenate a list of documents, with a line break between each doc.

text :: String -> DocSource

Create a document from a literal string.

The string should not contain newlines (though this is not enforced).

char :: Char -> DocSource

Create a document from a literal character.

The char should not be a tab or newline.

int :: Int -> DocSource

Show the Int as a Doc.

 int  = text . show

integer :: Integer -> DocSource

Show the Integer as a Doc.

integral :: Integral a => a -> DocSource

Show an "integral value" as a Doc via fromIntegral.

float :: Double -> DocSource

Show the Float as a Doc.

double :: Double -> DocSource

Show the Double as a Doc.

hex4 :: Int -> DocSource

Show the Int as hexadecimal, padding up to 4 digits if necessary.

No trucation occurs if the value has more than 4 digits.

space :: DocSource

Create a Doc containing a single space character.

comma :: DocSource

Create a Doc containing a comma, ",".

semicolon :: DocSource

Create a Doc containing a semi colon, ";".

line :: DocSource

Create a Doc containing newline, "\n".

fill :: Int -> Doc -> DocSource

Fill a doc to the supplied length, padding the right-hand side with spaces.

Note - this function is expensive - it unrolls the functional representation of the String.

Also it should only be used for single line Doc's.

fillStringR :: Int -> String -> DocSource

String version of fill.

This is more efficient than fill as the input is a string so its length is more accesible.

Padding is the space character appended to the right.

fillStringL :: Int -> String -> DocSource

Left-padding version of fillStringR.

punctuate :: Doc -> [Doc] -> DocSource

Punctuate the Doc list with the separator, producing a Doc.

enclose :: Doc -> Doc -> Doc -> DocSource

Enclose the final Doc within the first two.

There are no spaces between the documents:

 enclose l r d = l <> d <> r

squotes :: Doc -> DocSource

Enclose the Doc within single quotes.

dquotes :: Doc -> DocSource

Enclose the Doc within double quotes.

parens :: Doc -> DocSource

Enclose the Doc within parens ().

brackets :: Doc -> DocSource

Enclose the Doc within square brackets [].

braces :: Doc -> DocSource

Enclose the Doc within curly braces {}.

angles :: Doc -> DocSource

Enclose the Doc within angle brackets <>.

lparen :: DocSource

Create a Doc containing a left paren, '('.

rparen :: DocSource

Create a Doc containing a right paren, ')'.

lbracket :: DocSource

Create a Doc containing a left square bracket, '['.

rbracket :: DocSource

Create a Doc containing a right square bracket, ']'.

lbrace :: DocSource

Create a Doc containing a left curly brace, '{'.

rbrace :: DocSource

Create a Doc containing a right curly brace, '}'.

langle :: DocSource

Create a Doc containing a left angle bracket, '<'.

rangle :: DocSource

Create a Doc containing a right angle bracket, '>'.

list :: [Doc] -> DocSource

Comma separate the list of documents and enclose in square brackets.

tupled :: [Doc] -> DocSource

Comma separate the list of documents and enclose in parens.

semiBraces :: [Doc] -> DocSource

Separate the list with a semicolon and enclose in curly braces.

indent :: Int -> Doc -> DocSource

Horizontally indent a Doc.

Note - this space-prefixes the Doc on the current line. It does not indent subsequent lines if the Doc spans multiple lines.

writeDoc :: FilePath -> Doc -> IO ()Source

Write a Doc to file.