kangaroo-0.4.0: Binary parsing with random access.

Portabilityto be determined.
Stabilityhighly unstable
MaintainerStephen Tetley <stephen.tetley@gmail.com>

Text.PrettyPrint.JoinPrint

Contents

Description

Printing with join-strings.

Note - JoinPrint is just a formatter and not a 'pretty printer'. No line fitting takes place - lines are printed exactly as they are specified.

Synopsis

Documentation

data Doc Source

Doc is the abstract data type respresenting single line documents.

JoinPrint ditinguishes between single-line and multi-line documents. Single-line, horizontal documents support some operations not multi-line documents, e.g. padding, see padl and padr and truncating truncl and truncr.

Instances

data VDoc Source

VDoc is the abstract data type respresenting multi-line documents.

Multi-line documents have a limited set of operations (basically concatenation with or without a blank line inbetween) compared to single line docs which support e.g. padding and truncating.

Instances

empty :: DocSource

Create an empty, zero length document.

null :: Doc -> BoolSource

Test if the doc is empty.

length :: Doc -> IntSource

Get the length of the Doc.

Length is cached in the document's data type so this operation is O(1).

Compose Docs

(<>) :: 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.

hcat :: [Doc] -> DocSource

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

hsep :: [Doc] -> DocSource

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

Compose VDocs

vcat :: [Doc] -> VDocSource

Vertically concatenate a list of documents, one doc per line.

Note - this function produces a VDoc rather than a Doc.

vsep :: [Doc] -> VDocSource

Vertically concatenate a list of documents, one doc per line with a blank line inbetween.

Note - this function produces a VDoc rather than a Doc.

vcons :: Doc -> VDoc -> VDocSource

Prefix the Doc to the start of the VDoc.

vsnoc :: VDoc -> Doc -> VDocSource

Suffix the VDoc with the Doc.

vconcat :: [VDoc] -> VDocSource

Concatenate a list of VDoc.

vconcatSep :: [VDoc] -> VDocSource

Concatenate a list of VDoc with a blank line separating them.

Primitive Docs

text :: String -> DocSource

Create a document from a literal string.

The string should not contain tabs or newlines (though this is not enforced). To allow padding and truncating the horizontal width of a Doc is cached in the datatype, building a Doc containing tabs or newlines leads to unspecified behaviour.

char :: Char -> DocSource

Create a document from a literal character.

The char should not be a tab or newline. See text for the rational.

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.

sglspace :: DocSource

Create a Doc containing a single space character.

dblspace :: DocSource

Create a Doc containing a two-space characters.

comma :: DocSource

Create a Doc containing a comma, ",".

semicolon :: DocSource

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

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, '>'.

replicateChar :: Int -> Char -> DocSource

replicateChar : n * ch -> Doc

Repeat the supplied char (ch), n times.

spacer :: Int -> DocSource

Create a list of space characters of length n.

Padding and truncation

padl :: Int -> Char -> Doc -> DocSource

padl : width * ch * doc -> Doc

Pad the supplied Doc to fit width using the char ch. Padding is performed at the left, right-justifying the Doc.

If the doc is already wider than supplied width it is returned as-is (no truncation takes place).

padr :: Int -> Char -> Doc -> DocSource

padr : width * ch * doc -> Doc

Pad the supplied Doc to fit width using the char ch. Padding is performed at the right, left-justifying the Doc.

If the doc is already wider than supplied width it is returned as-is (no truncation takes place).

truncl :: Int -> Doc -> DocSource

truncl : width * doc -> Doc

Truncate a doc to the supplied width. Characters are dropped from the left until the document fits. If the document is shorter than the supplied width it is returned as is (no padding takes place).

truncr :: Int -> Doc -> DocSource

truncr : width * doc -> Doc

Truncate a doc to the supplied width. Characters are dropped from the right until the document fits. If the document is shorter than the supplied width it is returned as is (no padding takes place).

Output

render :: Doc -> StringSource

Rendering the Doc to a String. This is the same as using show.

renderIO :: Doc -> IO ()Source

Print the Doc.

 renderIO = putStrLn . render

hex :: Integral a => a -> DocSource

hex : i -> Doc

Print i as hexadecimal, no zero padding.

Negative numbers are printed as a string of asterisks.

hex2 :: Word8 -> DocSource

Print a Word8 as a 2-digit hex number.

hex4 :: Word16 -> DocSource

Print a Word16 as a 4-digit hex number.

hex8 :: Word32 -> DocSource

Print a Word32 as a 8-digit hex number.

oxhex :: Integral a => Int -> a -> DocSource

oxhex : pad-length * i -> Doc

Print i in hexadecimal, padding with '0' to the supplied pad-length and prefixing with "0x".

Negative numbers are printed as a string of asterisks.

oxhex2 :: Word8 -> DocSource

Print a Word8 as a 2-digit hex number prefixed with "0x".

oxhex4 :: Word16 -> DocSource

Print a Word16 as a 4-digit hex number prefixed with "0x".

oxhex8 :: Word32 -> DocSource

Print a Word32 as a 8-digit hex number prefixed with "0x".