Safe Haskell | None |
---|---|
Language | Haskell2010 |
Configurable precedence-aware pretty-printing.
Look into
test/Expr.hs
for an extended example.
Synopsis
- module Text.PrettyBy.Monad
- module Text.Fixity
- type AnyToDoc config ann = forall a. PrettyBy config a => a -> Doc ann
-
newtype
InContextM
config a =
InContextM
{
- unInContextM :: Reader ( Sole config) a
-
newtype
Sole
a =
Sole
{
- unSole :: a
- type MonadPrettyContext config env m = ( MonadPretty config env m, HasRenderContext config)
-
class
HasRenderContext
config
where
- renderContext :: Lens' config RenderContext
- runInContextM :: config -> InContextM config a -> a
- inContextM :: (a -> InContextM config ( Doc ann)) -> config -> a -> Doc ann
- encloseM :: MonadPrettyContext config env m => Fixity -> Doc ann -> m ( Doc ann)
- withPrettyIn :: MonadPrettyContext config env m => (( forall a. PrettyBy config a => Direction -> Fixity -> a -> Doc ann) -> m r) -> m r
- withPrettyAt :: MonadPrettyContext config env m => Direction -> Fixity -> ( AnyToDoc config ann -> m r) -> m r
- unitDocM :: MonadPrettyContext config env m => Doc ann -> m ( Doc ann)
- compoundDocM :: MonadPrettyContext config env m => Fixity -> (( forall a. PrettyBy config a => Direction -> Fixity -> a -> Doc ann) -> Doc ann) -> m ( Doc ann)
- sequenceDocM :: MonadPrettyContext config env m => Direction -> Fixity -> ( AnyToDoc config ann -> Doc ann) -> m ( Doc ann)
- infixDocM :: MonadPrettyContext config env m => Fixity -> ( AnyToDoc config ann -> AnyToDoc config ann -> Doc ann) -> m ( Doc ann)
- juxtPrettyM :: ( MonadPrettyContext config env m, PrettyBy config a, PrettyBy config b) => a -> b -> m ( Doc ann)
Documentation
module Text.PrettyBy.Monad
module Text.Fixity
type AnyToDoc config ann = forall a. PrettyBy config a => a -> Doc ann Source #
The type of a general
config
-based pretty-printer.
newtype InContextM config a Source #
A monad for precedence-aware pretty-printing.
InContextM | |
|
Instances
Monad ( InContextM config) Source # | |
Defined in Text.PrettyBy.Fixity (>>=) :: InContextM config a -> (a -> InContextM config b) -> InContextM config b Source # (>>) :: InContextM config a -> InContextM config b -> InContextM config b Source # return :: a -> InContextM config a Source # |
|
Functor ( InContextM config) Source # | |
Defined in Text.PrettyBy.Fixity fmap :: (a -> b) -> InContextM config a -> InContextM config b Source # (<$) :: a -> InContextM config b -> InContextM config a Source # |
|
Applicative ( InContextM config) Source # | |
Defined in Text.PrettyBy.Fixity pure :: a -> InContextM config a Source # (<*>) :: InContextM config (a -> b) -> InContextM config a -> InContextM config b Source # liftA2 :: (a -> b -> c) -> InContextM config a -> InContextM config b -> InContextM config c Source # (*>) :: InContextM config a -> InContextM config b -> InContextM config b Source # (<*) :: InContextM config a -> InContextM config b -> InContextM config a Source # |
|
MonadReader ( Sole config) ( InContextM config) Source # | |
Defined in Text.PrettyBy.Fixity ask :: InContextM config ( Sole config) Source # local :: ( Sole config -> Sole config) -> InContextM config a -> InContextM config a Source # reader :: ( Sole config -> a) -> InContextM config a Source # |
|
( HasRenderContext config, doc ~ Doc ann) => IsString ( InContextM config doc) Source # |
A string written in the
|
Defined in Text.PrettyBy.Fixity fromString :: String -> InContextM config doc Source # |
A
newtype
wrapper around
a
introduced for its
HasPrettyConfig
instance.
Instances
HasPrettyConfig ( Sole config) config Source # |
It's not possible to have
|
Defined in Text.PrettyBy.Fixity prettyConfig :: Lens' ( Sole config) config Source # |
|
MonadReader ( Sole config) ( InContextM config) Source # | |
Defined in Text.PrettyBy.Fixity ask :: InContextM config ( Sole config) Source # local :: ( Sole config -> Sole config) -> InContextM config a -> InContextM config a Source # reader :: ( Sole config -> a) -> InContextM config a Source # |
type MonadPrettyContext config env m = ( MonadPretty config env m, HasRenderContext config) Source #
A constraint for "
m
is a
Monad
supporting configurable precedence-aware pretty-printing".
class HasRenderContext config where Source #
A constraint for "
RenderContext
is a part of
config
".
renderContext :: Lens' config RenderContext Source #
Instances
runInContextM :: config -> InContextM config a -> a Source #
Run
InContextM
by supplying a
config
.
inContextM :: (a -> InContextM config ( Doc ann)) -> config -> a -> Doc ann Source #
Takes a monadic pretty-printer and turns it into one that receives a
config
explicitly.
Useful for defining instances of
PrettyBy
monadically when writing precedence-aware
pretty-printing code (and since all functions below are monadic, it's currenty the only option).
encloseM :: MonadPrettyContext config env m => Fixity -> Doc ann -> m ( Doc ann) Source #
Enclose a
Doc
in parentheses if required or leave it as is. The need for enclosing is
determined from an outer
RenderContext
(stored in the environment of the monad) and the inner
fixity provided as an argument.
withPrettyIn :: MonadPrettyContext config env m => (( forall a. PrettyBy config a => Direction -> Fixity -> a -> Doc ann) -> m r) -> m r Source #
Instantiate a supplied continuation with a precedence-aware pretty-printer.
withPrettyAt :: MonadPrettyContext config env m => Direction -> Fixity -> ( AnyToDoc config ann -> m r) -> m r Source #
unitDocM :: MonadPrettyContext config env m => Doc ann -> m ( Doc ann) Source #
Call
encloseM
on
unitFixity
.
compoundDocM :: MonadPrettyContext config env m => Fixity -> (( forall a. PrettyBy config a => Direction -> Fixity -> a -> Doc ann) -> Doc ann) -> m ( Doc ann) Source #
sequenceDocM :: MonadPrettyContext config env m => Direction -> Fixity -> ( AnyToDoc config ann -> Doc ann) -> m ( Doc ann) Source #
infixDocM :: MonadPrettyContext config env m => Fixity -> ( AnyToDoc config ann -> AnyToDoc config ann -> Doc ann) -> m ( Doc ann) Source #
Instantiate a supplied continuation with two pretty-printers (one is going in the
ToTheLeft
direction, the other is in the
ToTheRight
direction) specialized to supplied
Fixity
and apply
encloseM
, specialized to the same fixity, to the result.
The idea is that to the outside an infix operator has the same inner fixity as
it has the outer fixity to inner subexpressions.
juxtPrettyM :: ( MonadPrettyContext config env m, PrettyBy config a, PrettyBy config b) => a -> b -> m ( Doc ann) Source #
Pretty-print two things with a space between them. The fixity of the context in which the
arguments get pretty-printed is set to
juxtFixity
.