prettyprinter-configurable-1.1.0.0
Safe Haskell None
Language Haskell2010

Text.PrettyBy.Fixity

Description

Configurable precedence-aware pretty-printing.

Look into test/Expr.hs for an extended example.

Synopsis

Documentation

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.

Constructors

InContextM

Fields

Instances

Instances details
Monad ( InContextM config) Source #
Instance details

Defined in Text.PrettyBy.Fixity

Functor ( InContextM config) Source #
Instance details

Defined in Text.PrettyBy.Fixity

Methods

fmap :: (a -> b) -> InContextM config a -> InContextM config b Source #

(<$) :: a -> InContextM config b -> InContextM config a Source #

Applicative ( InContextM config) Source #
Instance details

Defined in Text.PrettyBy.Fixity

Methods

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 #
Instance details

Defined in Text.PrettyBy.Fixity

Methods

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 InContextM monad gets enclosed with unitDocM automatically.

Instance details

Defined in Text.PrettyBy.Fixity

newtype Sole a Source #

A newtype wrapper around a introduced for its HasPrettyConfig instance.

Constructors

Sole

Fields

Instances

Instances details
HasPrettyConfig ( Sole config) config Source #

It's not possible to have HasPrettyConfig config config , because that would mean that every environment is a pretty-printing config on its own, which doesn't make sense. We could have an OVERLAPPABLE instance, but I'd rather not.

Instance details

Defined in Text.PrettyBy.Fixity

MonadReader ( Sole config) ( InContextM config) Source #
Instance details

Defined in Text.PrettyBy.Fixity

Methods

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

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 #

Instantiate a supplied continuation with a pretty-printer specialized to supplied Fixity and Direction .

compoundDocM :: MonadPrettyContext config env m => Fixity -> (( forall a. PrettyBy config a => Direction -> Fixity -> a -> Doc ann) -> Doc ann) -> m ( Doc ann) Source #

Instantiate a supplied continuation with a pretty-printer and apply encloseM , specialized to supplied Fixity , to the result.

sequenceDocM :: MonadPrettyContext config env m => Direction -> Fixity -> ( AnyToDoc config ann -> Doc ann) -> m ( Doc ann) Source #

Instantiate a supplied continuation with a pretty-printer specialized to supplied Fixity and Direction and apply encloseM specialized to the provided fixity to the result. This can be useful for pretty-printing a sequence of values (possibly consisting of a single value).

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 .