Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Silkscreen is a library of pretty-printing transformers built around the prettyprinter package. This module defines the core Printer
abstraction and a few instances.
More documentation can be found in Prettyprinter.
Synopsis
- class Monoid p => Printer p where
- type Ann p
- liftDoc0 :: Doc (Ann p) -> p
- liftDoc1 :: (Doc (Ann p) -> Doc (Ann p)) -> p -> p
- liftDoc2 :: (Doc (Ann p) -> Doc (Ann p) -> Doc (Ann p)) -> p -> p -> p
- enclosing :: p -> p -> p -> p
- squotes :: p -> p
- dquotes :: p -> p
- parens :: p -> p
- brackets :: p -> p
- braces :: p -> p
- angles :: p -> p
- column :: (Int -> p) -> p
- nesting :: (Int -> p) -> p
- pageWidth :: (PageWidth -> p) -> p
- pretty :: (Printer p, Pretty t) => t -> p
- prettyList :: (Printer p, Pretty t) => [t] -> p
- annotate :: Printer p => Ann p -> p -> p
- group :: Printer p => p -> p
- flatAlt :: Printer p => p -> p -> p
- align :: Printer p => p -> p
- hang :: Printer p => Int -> p -> p
- indent :: Printer p => Int -> p -> p
- nest :: Printer p => Int -> p -> p
- concatWith :: (Monoid p, Foldable t) => (p -> p -> p) -> t p -> p
- hsep :: Printer p => [p] -> p
- vsep :: Printer p => [p] -> p
- fillSep :: Printer p => [p] -> p
- sep :: Printer p => [p] -> p
- hcat :: Printer p => [p] -> p
- vcat :: Printer p => [p] -> p
- fillCat :: Printer p => [p] -> p
- cat :: Printer p => [p] -> p
- punctuate :: Printer p => p -> [p] -> [p]
- width :: Printer p => p -> (Int -> p) -> p
- fill :: Printer p => Int -> p -> p
- fillBreak :: Printer p => Int -> p -> p
- plural :: (Num amount, Eq amount) => doc -> doc -> amount -> doc
- enclose :: Printer p => p -> p -> p -> p
- encloseSep :: Printer p => p -> p -> p -> [p] -> p
- list :: Printer p => [p] -> p
- tupled :: Printer p => [p] -> p
- surround :: Printer p => p -> p -> p -> p
- (<+>) :: Printer p => p -> p -> p
- (</>) :: Printer p => p -> p -> p
- parensIf :: Printer p => Bool -> p -> p
- space :: Printer p => p
- line :: Printer p => p
- line' :: Printer p => p
- softline :: Printer p => p
- softline' :: Printer p => p
- hardline :: Printer p => p
- lparen :: Printer p => p
- rparen :: Printer p => p
- lbracket :: Printer p => p
- rbracket :: Printer p => p
- lbrace :: Printer p => p
- rbrace :: Printer p => p
- langle :: Printer p => p
- rangle :: Printer p => p
- squote :: Printer p => p
- dquote :: Printer p => p
- semi :: Printer p => p
- comma :: Printer p => p
- colon :: Printer p => p
- dot :: Printer p => p
- slash :: Printer p => p
- backslash :: Printer p => p
- equals :: Printer p => p
- pipe :: Printer p => p
- class Pretty a
- data PageWidth
Printing
class Monoid p => Printer p where Source #
A Printer
abstracts pretty-printing to allow the composition of behaviours such as e.g. rainbow parentheses, precedence handling, and so forth.
The type of annotations supported by the printer.
We provide this as a type family instead of defining Printer
over kind Type -> Type
in order to allow instances to constrain annotations.
liftDoc0 :: Doc (Ann p) -> p Source #
liftDoc1 :: (Doc (Ann p) -> Doc (Ann p)) -> p -> p Source #
liftDoc2 :: (Doc (Ann p) -> Doc (Ann p) -> Doc (Ann p)) -> p -> p -> p Source #
enclosing :: p -> p -> p -> p Source #
wraps enclosing
l r xx
in l
and r
.
Distinct from enclose
(which is not overloaded) so that enclose
remains available as a convenience for appending documents without whatever extra semantics are implied by any particular Printer
(rainbow precedences, resetting precedence, etc.).
Overloadable to support e.g. rainbow parentheses.
Wrap the argument in single quotes.
The default definition is given in terms of enclosing
. Overloadable to support e.g. rainbow quotes (or disabling of same, if desired).
Wrap the argument in double quotes.
The default definition is given in terms of enclosing
. Overloadable to support e.g. rainbow quotes (or disabling of same, if desired).
Parenthesize the argument.
The default definition is given in terms of enclosing
. Overloadable to support e.g. rainbow parentheses (or disabling of same, if desired).
Wrap the argument in brackets.
The default definition is given in terms of enclosing
. Overloadable to support e.g. rainbow brackets (or disabling of same, if desired).
Wrap the argument in braces.
The default definition is given in terms of enclosing
. Overloadable to support e.g. rainbow braces (or disabling of same, if desired).
Wrap the argument in angle brackets.
The default definition is given in terms of enclosing
. Overloadable to support e.g. rainbow angle brackets (or disabling of same, if desired).
column :: (Int -> p) -> p Source #
Instances
Printer (Doc ann) Source # | |
Defined in Silkscreen liftDoc0 :: Doc (Ann (Doc ann)) -> Doc ann Source # liftDoc1 :: (Doc (Ann (Doc ann)) -> Doc (Ann (Doc ann))) -> Doc ann -> Doc ann Source # liftDoc2 :: (Doc (Ann (Doc ann)) -> Doc (Ann (Doc ann)) -> Doc (Ann (Doc ann))) -> Doc ann -> Doc ann -> Doc ann Source # enclosing :: Doc ann -> Doc ann -> Doc ann -> Doc ann Source # squotes :: Doc ann -> Doc ann Source # dquotes :: Doc ann -> Doc ann Source # parens :: Doc ann -> Doc ann Source # brackets :: Doc ann -> Doc ann Source # braces :: Doc ann -> Doc ann Source # angles :: Doc ann -> Doc ann Source # column :: (Int -> Doc ann) -> Doc ann Source # | |
Printer a => Printer (Rainbow a) Source # | |
Defined in Silkscreen.Printer.Rainbow liftDoc0 :: Doc (Ann (Rainbow a)) -> Rainbow a Source # liftDoc1 :: (Doc (Ann (Rainbow a)) -> Doc (Ann (Rainbow a))) -> Rainbow a -> Rainbow a Source # liftDoc2 :: (Doc (Ann (Rainbow a)) -> Doc (Ann (Rainbow a)) -> Doc (Ann (Rainbow a))) -> Rainbow a -> Rainbow a -> Rainbow a Source # enclosing :: Rainbow a -> Rainbow a -> Rainbow a -> Rainbow a Source # squotes :: Rainbow a -> Rainbow a Source # dquotes :: Rainbow a -> Rainbow a Source # parens :: Rainbow a -> Rainbow a Source # brackets :: Rainbow a -> Rainbow a Source # braces :: Rainbow a -> Rainbow a Source # angles :: Rainbow a -> Rainbow a Source # column :: (Int -> Rainbow a) -> Rainbow a Source # | |
Printer b => Printer (a -> b) Source # | |
Defined in Silkscreen liftDoc0 :: Doc (Ann (a -> b)) -> a -> b Source # liftDoc1 :: (Doc (Ann (a -> b)) -> Doc (Ann (a -> b))) -> (a -> b) -> a -> b Source # liftDoc2 :: (Doc (Ann (a -> b)) -> Doc (Ann (a -> b)) -> Doc (Ann (a -> b))) -> (a -> b) -> (a -> b) -> a -> b Source # enclosing :: (a -> b) -> (a -> b) -> (a -> b) -> a -> b Source # squotes :: (a -> b) -> a -> b Source # dquotes :: (a -> b) -> a -> b Source # parens :: (a -> b) -> a -> b Source # brackets :: (a -> b) -> a -> b Source # braces :: (a -> b) -> a -> b Source # angles :: (a -> b) -> a -> b Source # column :: (Int -> a -> b) -> a -> b Source # | |
(Printer a, Printer b, Ann a ~ Ann b) => Printer (a, b) Source # | |
Defined in Silkscreen liftDoc0 :: Doc (Ann (a, b)) -> (a, b) Source # liftDoc1 :: (Doc (Ann (a, b)) -> Doc (Ann (a, b))) -> (a, b) -> (a, b) Source # liftDoc2 :: (Doc (Ann (a, b)) -> Doc (Ann (a, b)) -> Doc (Ann (a, b))) -> (a, b) -> (a, b) -> (a, b) Source # enclosing :: (a, b) -> (a, b) -> (a, b) -> (a, b) Source # squotes :: (a, b) -> (a, b) Source # dquotes :: (a, b) -> (a, b) Source # parens :: (a, b) -> (a, b) Source # brackets :: (a, b) -> (a, b) Source # braces :: (a, b) -> (a, b) Source # angles :: (a, b) -> (a, b) Source # column :: (Int -> (a, b)) -> (a, b) Source # | |
(Bounded level, Printer a) => Printer (Prec level a) Source # | |
Defined in Silkscreen.Printer.Prec liftDoc0 :: Doc (Ann (Prec level a)) -> Prec level a Source # liftDoc1 :: (Doc (Ann (Prec level a)) -> Doc (Ann (Prec level a))) -> Prec level a -> Prec level a Source # liftDoc2 :: (Doc (Ann (Prec level a)) -> Doc (Ann (Prec level a)) -> Doc (Ann (Prec level a))) -> Prec level a -> Prec level a -> Prec level a Source # enclosing :: Prec level a -> Prec level a -> Prec level a -> Prec level a Source # squotes :: Prec level a -> Prec level a Source # dquotes :: Prec level a -> Prec level a Source # parens :: Prec level a -> Prec level a Source # brackets :: Prec level a -> Prec level a Source # braces :: Prec level a -> Prec level a Source # angles :: Prec level a -> Prec level a Source # column :: (Int -> Prec level a) -> Prec level a Source # nesting :: (Int -> Prec level a) -> Prec level a Source # pageWidth :: (PageWidth -> Prec level a) -> Prec level a Source # |
Combinators
pretty :: (Printer p, Pretty t) => t -> p Source #
Pretty-print a value using the Pretty
instance for its type.
prettyList :: (Printer p, Pretty t) => [t] -> p Source #
flatAlt :: Printer p => p -> p -> p Source #
Print the first argument by default, or the second when an enclosing group
flattens it.
hang :: Printer p => Int -> p -> p Source #
Indent following lines in the argument to the current column + some delta.
indent :: Printer p => Int -> p -> p Source #
Indent lines in the argument to the current column + some delta.
nest :: Printer p => Int -> p -> p Source #
changes the indentation level for new lines in nest
i pp
by i
.
concatWith :: (Monoid p, Foldable t) => (p -> p -> p) -> t p -> p Source #
(
is plural
n one many)one
if n
is 1
, and many
otherwise. A
typical use case is adding a plural "s".
>>>
let things = [True]
>>>
let amount = length things
>>>
pretty things <+> "has" <+> pretty amount <+> plural "entry" "entries" amount
[True] has 1 entry
encloseSep :: Printer p => p -> p -> p -> [p] -> p Source #
Conditional combinators
parensIf :: Printer p => Bool -> p -> p Source #
Conditional parenthesization of a printer. Analogous to showParen
, but for printers.
Symbols
Re-exports
Instances
Pretty Bool |
|
Defined in Prettyprinter.Internal | |
Pretty Char | Instead of
|
Defined in Prettyprinter.Internal | |
Pretty Double |
|
Defined in Prettyprinter.Internal | |
Pretty Float |
|
Defined in Prettyprinter.Internal | |
Pretty Int |
|
Defined in Prettyprinter.Internal | |
Pretty Int8 | |
Defined in Prettyprinter.Internal | |
Pretty Int16 | |
Defined in Prettyprinter.Internal | |
Pretty Int32 | |
Defined in Prettyprinter.Internal | |
Pretty Int64 | |
Defined in Prettyprinter.Internal | |
Pretty Integer |
|
Defined in Prettyprinter.Internal | |
Pretty Natural | |
Defined in Prettyprinter.Internal | |
Pretty Word | |
Defined in Prettyprinter.Internal | |
Pretty Word8 | |
Defined in Prettyprinter.Internal | |
Pretty Word16 | |
Defined in Prettyprinter.Internal | |
Pretty Word32 | |
Defined in Prettyprinter.Internal | |
Pretty Word64 | |
Defined in Prettyprinter.Internal | |
Pretty () |
The argument is not used,
|
Defined in Prettyprinter.Internal | |
Pretty Void | Finding a good example for printing something that does not exist is hard, so here is an example of printing a list full of nothing.
|
Defined in Prettyprinter.Internal | |
Pretty Text | (lazy |
Defined in Prettyprinter.Internal | |
Pretty Text | Automatically converts all newlines to
Note that
Manually use |
Defined in Prettyprinter.Internal | |
Pretty a => Pretty [a] |
|
Defined in Prettyprinter.Internal | |
Pretty a => Pretty (Maybe a) | Ignore
|
Defined in Prettyprinter.Internal | |
Pretty a => Pretty (Identity a) |
|
Defined in Prettyprinter.Internal | |
Pretty a => Pretty (NonEmpty a) | |
Defined in Prettyprinter.Internal | |
(Pretty a1, Pretty a2) => Pretty (a1, a2) |
|
Defined in Prettyprinter.Internal | |
(Pretty a1, Pretty a2, Pretty a3) => Pretty (a1, a2, a3) |
|
Defined in Prettyprinter.Internal | |
Pretty a => Pretty (Const a b) | |
Defined in Prettyprinter.Internal |
Maximum number of characters that fit in one line. The layout algorithms
will try not to exceed the set limit by inserting line breaks when applicable
(e.g. via softline'
).
AvailablePerLine !Int !Double | Layouters should not exceed the specified space per line.
|
Unbounded | Layouters should not introduce line breaks on their own. |