silkscreen-0.0.0.1: Prettyprinting transformers.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Silkscreen

Description

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

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.

Minimal complete definition

liftDoc0, liftDoc1, liftDoc2, column, nesting, pageWidth

Associated Types

type Ann p Source #

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.

Methods

liftDoc0 :: Doc (Ann p) -> p Source #

Lift a Doc to a Printer.

liftDoc1 :: (Doc (Ann p) -> Doc (Ann p)) -> p -> p Source #

Lift a unary function on Doc to a Printer.

liftDoc2 :: (Doc (Ann p) -> Doc (Ann p) -> Doc (Ann p)) -> p -> p -> p Source #

Lift a binary function on Doc to a Printer.

enclosing :: p -> p -> p -> p Source #

enclosing l r x wraps x 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.

squotes :: p -> p Source #

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

dquotes :: p -> p Source #

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

parens :: p -> p Source #

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

brackets :: p -> p Source #

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

braces :: p -> p Source #

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

angles :: p -> p Source #

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 #

nesting :: (Int -> p) -> p Source #

pageWidth :: (PageWidth -> p) -> p Source #

Instances

Instances details
Printer (Doc ann) Source # 
Instance details

Defined in Silkscreen

Associated Types

type Ann (Doc ann) Source #

Methods

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 #

nesting :: (Int -> Doc ann) -> Doc ann Source #

pageWidth :: (PageWidth -> Doc ann) -> Doc ann Source #

Printer a => Printer (Rainbow a) Source # 
Instance details

Defined in Silkscreen.Printer.Rainbow

Associated Types

type Ann (Rainbow a) Source #

Methods

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 #

nesting :: (Int -> Rainbow a) -> Rainbow a Source #

pageWidth :: (PageWidth -> Rainbow a) -> Rainbow a Source #

Printer b => Printer (a -> b) Source # 
Instance details

Defined in Silkscreen

Associated Types

type Ann (a -> b) Source #

Methods

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 #

nesting :: (Int -> a -> b) -> a -> b Source #

pageWidth :: (PageWidth -> a -> b) -> a -> b Source #

(Printer a, Printer b, Ann a ~ Ann b) => Printer (a, b) Source # 
Instance details

Defined in Silkscreen

Associated Types

type Ann (a, b) Source #

Methods

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 #

nesting :: (Int -> (a, b)) -> (a, b) Source #

pageWidth :: (PageWidth -> (a, b)) -> (a, b) Source #

(Bounded level, Printer a) => Printer (Prec level a) Source # 
Instance details

Defined in Silkscreen.Printer.Prec

Associated Types

type Ann (Prec level a) Source #

Methods

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 #

annotate :: Printer p => Ann p -> p -> p Source #

Annotate a Printer with an Ann p.

group :: Printer p => p -> p Source #

Try to unwrap the argument, if it will fit.

flatAlt :: Printer p => p -> p -> p Source #

Print the first argument by default, or the second when an enclosing group flattens it.

align :: Printer p => p -> p Source #

Indent lines in the argument to the current column.

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 #

nest i p changes the indentation level for new lines in p by i.

concatWith :: (Monoid p, Foldable t) => (p -> p -> p) -> t p -> p Source #

hsep :: Printer p => [p] -> p Source #

vsep :: Printer p => [p] -> p Source #

fillSep :: Printer p => [p] -> p Source #

sep :: Printer p => [p] -> p Source #

hcat :: Printer p => [p] -> p Source #

vcat :: Printer p => [p] -> p Source #

fillCat :: Printer p => [p] -> p Source #

cat :: Printer p => [p] -> p Source #

punctuate :: Printer p => p -> [p] -> [p] Source #

width :: Printer p => p -> (Int -> p) -> p Source #

fill :: Printer p => Int -> p -> p Source #

fillBreak :: Printer p => Int -> p -> p Source #

plural :: (Num amount, Eq amount) => doc -> doc -> amount -> doc #

enclose :: Printer p => p -> p -> p -> p Source #

enclose l r x wraps x in l and r.

encloseSep :: Printer p => p -> p -> p -> [p] -> p Source #

list :: Printer p => [p] -> p Source #

tupled :: Printer p => [p] -> p Source #

surround :: Printer p => p -> p -> p -> p Source #

surround x l r wraps x in l and r.

This is a reordering of enclose, but allows for convenient use in e.g. folds:

>>> 'foldr1' ('surround' ('pretty' ", ")) ['pretty' "apple", 'pretty' "banana"]
apple, banana

(<+>) :: Printer p => p -> p -> p infixr 6 Source #

Separate the arguments with a space.

(</>) :: Printer p => p -> p -> p infixr 6 Source #

Separate the arguments with a line.

Conditional combinators

parensIf :: Printer p => Bool -> p -> p Source #

Conditional parenthesization of a printer. Analogous to showParen, but for printers.

Symbols

space :: Printer p => p Source #

line :: Printer p => p Source #

line' :: Printer p => p Source #

semi :: Printer p => p Source #

comma :: Printer p => p Source #

colon :: Printer p => p Source #

dot :: Printer p => p Source #

slash :: Printer p => p Source #

pipe :: Printer p => p Source #

Re-exports

class Pretty a #

Minimal complete definition

pretty

Instances

Instances details
Pretty Bool 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Bool -> Doc ann

prettyList :: [Bool] -> Doc ann

Pretty Char 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Char -> Doc ann

prettyList :: [Char] -> Doc ann

Pretty Double 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Double -> Doc ann

prettyList :: [Double] -> Doc ann

Pretty Float 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Float -> Doc ann

prettyList :: [Float] -> Doc ann

Pretty Int 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Int -> Doc ann

prettyList :: [Int] -> Doc ann

Pretty Int8 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Int8 -> Doc ann

prettyList :: [Int8] -> Doc ann

Pretty Int16 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Int16 -> Doc ann

prettyList :: [Int16] -> Doc ann

Pretty Int32 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Int32 -> Doc ann

prettyList :: [Int32] -> Doc ann

Pretty Int64 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Int64 -> Doc ann

prettyList :: [Int64] -> Doc ann

Pretty Integer 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Integer -> Doc ann

prettyList :: [Integer] -> Doc ann

Pretty Natural 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Natural -> Doc ann

prettyList :: [Natural] -> Doc ann

Pretty Word 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Word -> Doc ann

prettyList :: [Word] -> Doc ann

Pretty Word8 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Word8 -> Doc ann

prettyList :: [Word8] -> Doc ann

Pretty Word16 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Word16 -> Doc ann

prettyList :: [Word16] -> Doc ann

Pretty Word32 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Word32 -> Doc ann

prettyList :: [Word32] -> Doc ann

Pretty Word64 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Word64 -> Doc ann

prettyList :: [Word64] -> Doc ann

Pretty () 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: () -> Doc ann

prettyList :: [()] -> Doc ann

Pretty Void 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Void -> Doc ann

prettyList :: [Void] -> Doc ann

Pretty Text 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Text -> Doc ann

prettyList :: [Text] -> Doc ann

Pretty Text 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Text -> Doc ann

prettyList :: [Text] -> Doc ann

Pretty a => Pretty [a] 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: [a] -> Doc ann

prettyList :: [[a]] -> Doc ann

Pretty a => Pretty (Maybe a) 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Maybe a -> Doc ann

prettyList :: [Maybe a] -> Doc ann

Pretty a => Pretty (Identity a) 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Identity a -> Doc ann

prettyList :: [Identity a] -> Doc ann

Pretty a => Pretty (NonEmpty a) 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: NonEmpty a -> Doc ann

prettyList :: [NonEmpty a] -> Doc ann

(Pretty a1, Pretty a2) => Pretty (a1, a2) 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: (a1, a2) -> Doc ann

prettyList :: [(a1, a2)] -> Doc ann

(Pretty a1, Pretty a2, Pretty a3) => Pretty (a1, a2, a3) 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: (a1, a2, a3) -> Doc ann

prettyList :: [(a1, a2, a3)] -> Doc ann

Pretty a => Pretty (Const a b) 
Instance details

Defined in Prettyprinter.Internal

Methods

pretty :: Const a b -> Doc ann

prettyList :: [Const a b] -> Doc ann

data PageWidth #

Instances

Instances details
Eq PageWidth 
Instance details

Defined in Prettyprinter.Internal

Ord PageWidth 
Instance details

Defined in Prettyprinter.Internal

Show PageWidth 
Instance details

Defined in Prettyprinter.Internal