Safe Haskell | None |
---|---|
Language | Haskell2010 |
Language.Lua.Pretty
Contents
Description
wl-pprint re-exports
data Doc :: *
The abstract data type Doc
represents pretty documents.
Doc
is an instance of the Show
class. (show doc)
pretty
prints document doc
with a page width of 100 characters and a
ribbon width of 40 characters.
show (text "hello" <$> text "world")
Which would return the string "hello\nworld", i.e.
hello world
class Pretty a where
The member prettyList
is only used to define the instance Pretty
a => Pretty [a]
. In normal circumstances only the pretty
function
is used.
Minimal complete definition
Instances
Pretty Bool | |
Pretty Char | |
Pretty Double | |
Pretty Float | |
Pretty Int | |
Pretty Integer | |
Pretty () | |
Pretty Doc | |
Pretty a => Pretty [a] | |
Pretty a => Pretty (Maybe a) | |
Pretty (Unop a) | |
Pretty (Binop a) | |
Pretty (Field a) | |
Pretty (TableConstructor a) | |
Pretty (FunctionBody a) | |
Pretty (FunctionArgs a) | |
Pretty (FunctionCall a) | |
Pretty (PrefixExpression a) | |
Pretty (Expression a) | |
Pretty (Variable a) | |
Pretty (FunctionName a) | |
Pretty (ReturnStatement a) | |
Pretty (Statement a) | |
Pretty (Block a) | |
Pretty (Ident a) | |
(Pretty a, Pretty b) => Pretty (a, b) | |
(Pretty a, Pretty b, Pretty c) => Pretty (a, b, c) |
data SimpleDoc :: *
The data type SimpleDoc
represents rendered documents and is
used by the display functions.
The Int
in SText
contains the length of the string. The Int
in SLine
contains the indentation for that line. The library
provides two default display functions displayS
and
displayIO
. You can provide your own display function by writing a
function from a SimpleDoc
to your own output format.
renderPretty :: Float -> Int -> Doc -> SimpleDoc
This is the default pretty printer which is used by show
,
putDoc
and hPutDoc
. (renderPretty ribbonfrac width x)
renders
document x
with a page width of width
and a ribbon width of
(ribbonfrac * width)
characters. The ribbon width is the maximal
amount of non-indentation characters on a line. The parameter
ribbonfrac
should be between 0.0
and 1.0
. If it is lower or
higher, the ribbon width will be 0 or width
respectively.
renderCompact :: Doc -> SimpleDoc
(renderCompact x)
renders document x
without adding any
indentation. Since no 'pretty' printing is involved, this
renderer is very fast. The resulting output contains fewer
characters than a pretty printed version and can be used for output
that is read by other programs.