-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Prettyprinting transformers. -- -- Prettyprinting transformers for rainbow parens, precedence, etc. @package silkscreen @version 0.0.0.2 -- | 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. module Silkscreen -- | A Printer abstracts pretty-printing to allow the composition of -- behaviours such as e.g. rainbow parentheses, precedence handling, and -- so forth. class Monoid p => Printer p where { -- | 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. type family Ann p; } -- | Lift a Doc to a Printer. liftDoc0 :: Printer p => Doc (Ann p) -> p -- | Lift a unary function on Doc to a Printer. liftDoc1 :: Printer p => (Doc (Ann p) -> Doc (Ann p)) -> p -> p -- | Lift a binary function on Doc to a Printer. liftDoc2 :: Printer p => (Doc (Ann p) -> Doc (Ann p) -> Doc (Ann p)) -> p -> p -> p -- | 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. enclosing :: Printer p => p -> p -> p -> p -- | 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). squotes :: Printer p => p -> p -- | 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). dquotes :: Printer p => p -> p -- | 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). parens :: Printer p => p -> p -- | 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). brackets :: Printer p => p -> p -- | 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). braces :: Printer p => p -> p -- | 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). angles :: Printer p => p -> p column :: Printer p => (Int -> p) -> p nesting :: Printer p => (Int -> p) -> p pageWidth :: Printer p => (PageWidth -> p) -> p -- | Pretty-print a value using the Pretty instance for its type. pretty :: (Printer p, Pretty t) => t -> p prettyList :: (Printer p, Pretty t) => [t] -> p -- | Annotate a Printer with an Ann p. annotate :: Printer p => Ann p -> p -> p -- | Try to unwrap the argument, if it will fit. group :: Printer p => p -> p -- | Print the first argument by default, or the second when an enclosing -- group flattens it. flatAlt :: Printer p => p -> p -> p -- | Indent lines in the argument to the current column. align :: Printer p => p -> p -- | Indent following lines in the argument to the current column + some -- delta. hang :: Printer p => Int -> p -> p -- | Indent lines in the argument to the current column + some delta. indent :: Printer p => Int -> p -> p -- | nest i p changes the indentation level for new lines -- in p by i. 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 l r x wraps x in l and -- r. 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 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
--
surround :: Printer p => p -> p -> p -> p
-- | Separate the arguments with a space.
(<+>) :: Printer p => p -> p -> p
infixr 6 <+>
-- | Separate the arguments with a line.
(>) :: Printer p => p -> p -> p
infixr 6 >
-- | Conditional parenthesization of a printer. Analogous to
-- showParen, but for printers.
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
AvailablePerLine :: !Int -> !Double -> PageWidth
Unbounded :: PageWidth
instance Silkscreen.Printer (Prettyprinter.Internal.Doc ann)
instance (Silkscreen.Printer a, Silkscreen.Printer b, Silkscreen.Ann a GHC.Types.~ Silkscreen.Ann b) => Silkscreen.Printer (a, b)
instance Silkscreen.Printer b => Silkscreen.Printer (a -> b)
module Silkscreen.Nesting
class Printer p => NestingPrinter p
-- | Make a printer informed by the current nesting level.
askingNesting :: NestingPrinter p => (Int -> p) -> p
-- | Locally change the nesting level for a printer.
localNesting :: NestingPrinter p => (Int -> Int) -> p -> p
-- | Apply the current nesting level to a printer.
--
-- Different instances can give different meanings to this, e.g.
-- annotating the argument with the nesting level or some other means of
-- rendering it differently.
applyNesting :: NestingPrinter p => p -> p
-- | Increment the nesting level of a printer.
--
-- This should be used inside parentheses, brackets, braces, etc., and
-- will inform the annotation of their delimiters.
incrNesting :: NestingPrinter p => p -> p
encloseNesting :: NestingPrinter p => p -> p -> p -> p
instance Silkscreen.Nesting.NestingPrinter b => Silkscreen.Nesting.NestingPrinter (a -> b)
module Silkscreen.Precedence
-- | Pretty-printing with parenthesis insertion resolving precedence.
--
-- Given:
--
-- -- data ArithLevel = Bottom | Add | Mult | Exp | Top -- deriving (Eq, Ord) -- -- (+.) :: (PrecedencePrinter p, Level p ~ ArithLevel) => p -> p -> p -- (+.) = assoc Add (surround (pretty " + ")) -- infixl 6 +. -- -- (*.) :: (PrecedencePrinter p, Level p ~ ArithLevel) => p -> p -> p -- (*.) = assoc Mult (surround (pretty " * ")) -- infixl 7 *. -- -- (^.) :: (PrecedencePrinter p, Level p ~ ArithLevel) => p -> p -> p -- (^.) = rightAssoc Exp Top (surround (pretty " ^ ")) -- infixr 8 ^. ---- --
-- >>> putDoc . runPrec Bottom $ ('pretty' "a" +. 'pretty' "b") *. 'pretty' "c" ^. ('pretty' "d" *. 'pretty' "e")
-- (a + b) * c ^ (d * e)
--
class Printer p => PrecedencePrinter p where {
-- | The type used to represent precedence levels. This is defined as an
-- associated type so that consumers can use e.g. symbolic
-- representations of their DSL’s precedence levels instead of e.g.
-- unsemantic Ints.
--
-- This type will usually be Ordered, but this isn’t strictly
-- required so that other means of determining precedence can be
-- provided.
type family Level p;
}
-- | Print informed by the current Level.
askingPrec :: PrecedencePrinter p => (Level p -> p) -> p
-- | Locally change the Level in a printer.
localPrec :: PrecedencePrinter p => (Level p -> Level p) -> p -> p
-- | Set a constant precedence.
--
-- This function does not insert parentheses, and thus should be used
-- when inserting parentheses or otherwise resetting the precedence
-- level.
setPrec :: PrecedencePrinter p => Level p -> p -> p
-- | Set a constant precedence, parenthesizing in higher-precedence
-- contexts.
prec :: (PrecedencePrinter p, Ord (Level p)) => Level p -> p -> p
-- | Make an associative infix combinator at the given level.
assoc :: (PrecedencePrinter p, Ord (Level p)) => Level p -> (p -> p -> p) -> p -> p -> p
-- | Make a non-associative infix combinator at the given levels for the
-- operator itself and its operands.
nonAssoc :: (PrecedencePrinter p, Ord (Level p)) => Level p -> Level p -> (p -> p -> p) -> p -> p -> p
-- | Make a left-associative infix combinator at the given levels for the
-- operator itself and its right operand.
leftAssoc :: (PrecedencePrinter p, Ord (Level p)) => Level p -> Level p -> (p -> p -> p) -> p -> p -> p
-- | Make a right-associative infix combinator at the given levels for the
-- operator itself and its left operand.
rightAssoc :: (PrecedencePrinter p, Ord (Level p)) => Level p -> Level p -> (p -> p -> p) -> p -> p -> p
-- | Make an infix combinator at the given level for the operator itself,
-- applying functions to either operand.
infix_ :: (PrecedencePrinter p, Ord (Level p)) => Level p -> (p -> p) -> (p -> p) -> (p -> p -> p) -> p -> p -> p
instance Silkscreen.Precedence.PrecedencePrinter b => Silkscreen.Precedence.PrecedencePrinter (a -> b)
module Silkscreen.Printer.Prec
runPrec :: level -> Prec level a -> a
newtype Prec level a
Prec :: (level -> a) -> Prec level a
instance GHC.Base.Semigroup a => GHC.Base.Semigroup (Silkscreen.Printer.Prec.Prec level a)
instance GHC.Base.Monoid a => GHC.Base.Monoid (Silkscreen.Printer.Prec.Prec level a)
instance GHC.Base.Monad (Silkscreen.Printer.Prec.Prec level)
instance GHC.Base.Functor (Silkscreen.Printer.Prec.Prec level)
instance GHC.Base.Applicative (Silkscreen.Printer.Prec.Prec level)
instance (GHC.Enum.Bounded level, GHC.Show.Show a) => GHC.Show.Show (Silkscreen.Printer.Prec.Prec level a)
instance (GHC.Enum.Bounded level, Silkscreen.Printer a) => Silkscreen.Printer (Silkscreen.Printer.Prec.Prec level a)
instance (GHC.Enum.Bounded level, Silkscreen.Printer a) => Silkscreen.Precedence.PrecedencePrinter (Silkscreen.Printer.Prec.Prec level a)
instance (GHC.Enum.Bounded level, Silkscreen.Nesting.NestingPrinter p) => Silkscreen.Nesting.NestingPrinter (Silkscreen.Printer.Prec.Prec level p)
module Silkscreen.Printer.Rainbow
runRainbow :: (Int -> a -> a) -> Int -> Rainbow a -> a
newtype Rainbow a
Rainbow :: ((Int -> a -> a) -> Int -> a) -> Rainbow a
instance GHC.Base.Semigroup a => GHC.Base.Semigroup (Silkscreen.Printer.Rainbow.Rainbow a)
instance GHC.Base.Monoid a => GHC.Base.Monoid (Silkscreen.Printer.Rainbow.Rainbow a)
instance GHC.Show.Show a => GHC.Show.Show (Silkscreen.Printer.Rainbow.Rainbow a)
instance Silkscreen.Printer a => Silkscreen.Printer (Silkscreen.Printer.Rainbow.Rainbow a)
instance Silkscreen.Printer a => Silkscreen.Nesting.NestingPrinter (Silkscreen.Printer.Rainbow.Rainbow a)
instance Silkscreen.Precedence.PrecedencePrinter p => Silkscreen.Precedence.PrecedencePrinter (Silkscreen.Printer.Rainbow.Rainbow p)