prettyprinter-configurable-1.30.0.0: Configurable pretty-printing
Safe HaskellSafe-Inferred
LanguageHaskell2010

Text.PrettyBy.Fixity

Description

Configurable precedence-aware pretty-printing.

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

Synopsis

Documentation

class HasRenderContext config where Source #

A constraint for "RenderContext is a part of config".

Methods

renderContext ∷ Lens' config RenderContext Source #

Instances

Instances details
HasRenderContext RenderContext Source # 
Instance details

Defined in Text.PrettyBy.Fixity

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

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

Methods

prettyConfig ∷ Lens' (Sole config) config Source #

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

Defined in Text.PrettyBy.Fixity

Methods

askInContextM config (Sole config)

local ∷ (Sole config → Sole config) → InContextM config a → InContextM config a

reader ∷ (Sole config → a) → InContextM config a

newtype InContextM config a Source #

A monad for precedence-aware pretty-printing.

Constructors

InContextM 

Fields

Instances

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

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 #

Monad (InContextM config) Source # 
Instance details

Defined in Text.PrettyBy.Fixity

Methods

(>>=)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 #

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

Defined in Text.PrettyBy.Fixity

Methods

askInContextM config (Sole config)

local ∷ (Sole config → Sole config) → InContextM config a → InContextM config a

reader ∷ (Sole config → a) → InContextM config a

(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

Methods

fromStringStringInContextM config doc Source #

type AnyToDoc config ann = ∀ a. PrettyBy config a ⇒ a → Doc ann Source #

The type of a general config-based pretty-printer.

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

unitDocMMonadPrettyContext config env m ⇒ Doc ann → m (Doc ann) Source #

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

withPrettyInMonadPrettyContext config env m ⇒ ((∀ a. PrettyBy config a ⇒ DirectionFixity → a → Doc ann) → m r) → m r Source #

Instantiate a supplied continuation with a precedence-aware pretty-printer.

withPrettyAtMonadPrettyContext config env m ⇒ DirectionFixity → (AnyToDoc config ann → m r) → m r Source #

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

compoundDocMMonadPrettyContext config env m ⇒ Fixity → ((∀ a. PrettyBy config a ⇒ DirectionFixity → 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.

sequenceDocMMonadPrettyContext config env m ⇒ DirectionFixity → (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).

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