Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Configurable precedence-aware pretty-printing.
Look into test/Expr.hs
for an extended example.
Synopsis
- module Text.PrettyBy.Monad
- module Text.Fixity
- class HasRenderContext config where
- renderContext ∷ Lens' config RenderContext
- type MonadPrettyContext config env m = (MonadPretty config env m, HasRenderContext config)
- newtype Sole a = Sole {
- unSole ∷ a
- newtype InContextM config a = InContextM {
- unInContextM ∷ Reader (Sole config) a
- type AnyToDoc config ann = ∀ a. PrettyBy config a ⇒ a → Doc ann
- runInContextM ∷ config → InContextM config a → a
- inContextM ∷ (a → InContextM config (Doc ann)) → config → a → Doc ann
- unitDocM ∷ MonadPrettyContext config env m ⇒ Doc ann → m (Doc ann)
- encloseM ∷ MonadPrettyContext config env m ⇒ Fixity → Doc ann → m (Doc ann)
- withPrettyIn ∷ MonadPrettyContext config env m ⇒ ((∀ 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
- compoundDocM ∷ MonadPrettyContext config env m ⇒ Fixity → ((∀ 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
class HasRenderContext config where Source #
A constraint for "RenderContext
is a part of config
".
renderContext ∷ Lens' config RenderContext Source #
Instances
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".
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 # |
newtype InContextM config a Source #
A monad for precedence-aware pretty-printing.
InContextM | |
|
Instances
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).
unitDocM ∷ MonadPrettyContext config env m ⇒ Doc ann → m (Doc ann) Source #
Call encloseM
on unitFixity
.
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 ⇒ ((∀ 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 #
compoundDocM ∷ MonadPrettyContext config env m ⇒ Fixity → ((∀ 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
.