{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module Text.PrettyBy.Fixity
( module Export
, module Text.PrettyBy.Fixity
) where
import Text.Fixity as Export
import Text.Pretty
import Text.PrettyBy.Internal
import Text.PrettyBy.Internal.Utils
import Text.PrettyBy.Monad as Export
import Control.Monad.Reader
import Data.String
import Lens.Micro
class HasRenderContext config where
renderContext :: Lens' config RenderContext
instance HasRenderContext RenderContext where
renderContext :: Lens' RenderContext RenderContext
renderContext = forall a. a -> a
id
type MonadPrettyContext config env m = (MonadPretty config env m, HasRenderContext config)
newtype Sole a = Sole
{ forall a. Sole a -> a
unSole :: a
}
instance HasPrettyConfig (Sole config) config where
prettyConfig :: Lens' (Sole config) config
prettyConfig config -> f config
f (Sole config
x) = forall a. a -> Sole a
Sole forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> config -> f config
f config
x
newtype InContextM config a = InContextM
{ forall config a. InContextM config a -> Reader (Sole config) a
unInContextM :: Reader (Sole config) a
} deriving newtype (forall a b. a -> InContextM config b -> InContextM config a
forall a b. (a -> b) -> InContextM config a -> InContextM config b
forall config a b. a -> InContextM config b -> InContextM config a
forall config a b.
(a -> b) -> InContextM config a -> InContextM config b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> InContextM config b -> InContextM config a
$c<$ :: forall config a b. a -> InContextM config b -> InContextM config a
fmap :: forall a b. (a -> b) -> InContextM config a -> InContextM config b
$cfmap :: forall config a b.
(a -> b) -> InContextM config a -> InContextM config b
Functor, forall config. Functor (InContextM config)
forall a. a -> InContextM config a
forall config a. a -> InContextM config a
forall a b.
InContextM config a -> InContextM config b -> InContextM config a
forall a b.
InContextM config a -> InContextM config b -> InContextM config b
forall a b.
InContextM config (a -> b)
-> InContextM config a -> InContextM config b
forall config a b.
InContextM config a -> InContextM config b -> InContextM config a
forall config a b.
InContextM config a -> InContextM config b -> InContextM config b
forall config a b.
InContextM config (a -> b)
-> InContextM config a -> InContextM config b
forall a b c.
(a -> b -> c)
-> InContextM config a
-> InContextM config b
-> InContextM config c
forall config a b c.
(a -> b -> c)
-> InContextM config a
-> InContextM config b
-> InContextM config c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: forall a b.
InContextM config a -> InContextM config b -> InContextM config a
$c<* :: forall config a b.
InContextM config a -> InContextM config b -> InContextM config a
*> :: forall a b.
InContextM config a -> InContextM config b -> InContextM config b
$c*> :: forall config a b.
InContextM config a -> InContextM config b -> InContextM config b
liftA2 :: forall a b c.
(a -> b -> c)
-> InContextM config a
-> InContextM config b
-> InContextM config c
$cliftA2 :: forall config a b c.
(a -> b -> c)
-> InContextM config a
-> InContextM config b
-> InContextM config c
<*> :: forall a b.
InContextM config (a -> b)
-> InContextM config a -> InContextM config b
$c<*> :: forall config a b.
InContextM config (a -> b)
-> InContextM config a -> InContextM config b
pure :: forall a. a -> InContextM config a
$cpure :: forall config a. a -> InContextM config a
Applicative, forall config. Applicative (InContextM config)
forall a. a -> InContextM config a
forall config a. a -> InContextM config a
forall a b.
InContextM config a -> InContextM config b -> InContextM config b
forall a b.
InContextM config a
-> (a -> InContextM config b) -> InContextM config b
forall config a b.
InContextM config a -> InContextM config b -> InContextM config b
forall config a b.
InContextM config a
-> (a -> InContextM config b) -> InContextM config b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: forall a. a -> InContextM config a
$creturn :: forall config a. a -> InContextM config a
>> :: forall a b.
InContextM config a -> InContextM config b -> InContextM config b
$c>> :: forall config a b.
InContextM config a -> InContextM config b -> InContextM config b
>>= :: forall a b.
InContextM config a
-> (a -> InContextM config b) -> InContextM config b
$c>>= :: forall config a b.
InContextM config a
-> (a -> InContextM config b) -> InContextM config b
Monad, MonadReader (Sole config))
runInContextM :: config -> InContextM config a -> a
runInContextM :: forall config a. config -> InContextM config a -> a
runInContextM config
config (InContextM Reader (Sole config) a
a) = forall r a. Reader r a -> r -> a
runReader Reader (Sole config) a
a forall a b. (a -> b) -> a -> b
$ forall a. a -> Sole a
Sole config
config
inContextM :: (a -> InContextM config (Doc ann)) -> config -> a -> Doc ann
inContextM :: forall a config ann.
(a -> InContextM config (Doc ann)) -> config -> a -> Doc ann
inContextM a -> InContextM config (Doc ann)
pM config
config = forall config a. config -> InContextM config a -> a
runInContextM config
config forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> InContextM config (Doc ann)
pM
instance (HasRenderContext config, doc ~ Doc ann) => IsString (InContextM config doc) where
fromString :: String -> InContextM config doc
fromString = forall config env (m :: * -> *) ann.
MonadPrettyContext config env m =>
Doc ann -> m (Doc ann)
unitDocM forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IsString a => String -> a
fromString
encloseM :: MonadPrettyContext config env m => Fixity -> Doc ann -> m (Doc ann)
encloseM :: forall config env (m :: * -> *) ann.
MonadPrettyContext config env m =>
Fixity -> Doc ann -> m (Doc ann)
encloseM Fixity
fixity Doc ann
doc =
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view (forall env config. HasPrettyConfig env config => Lens' env config
prettyConfig forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall config.
HasRenderContext config =>
Lens' config RenderContext
renderContext) forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \RenderContext
context ->
forall prec a.
Ord prec =>
(a -> a) -> RenderContextOver prec -> FixityOver prec -> a -> a
encloseIn forall ann. Doc ann -> Doc ann
parens RenderContext
context Fixity
fixity Doc ann
doc
type AnyToDoc config ann = forall a. PrettyBy config a => a -> Doc ann
withPrettyIn
:: MonadPrettyContext config env m
=> ((forall a. PrettyBy config a => Direction -> Fixity -> a -> Doc ann) -> m r) -> m r
withPrettyIn :: forall config env (m :: * -> *) ann r.
MonadPrettyContext config env m =>
((forall a.
PrettyBy config a =>
Direction -> Fixity -> a -> Doc ann)
-> m r)
-> m r
withPrettyIn (forall a.
PrettyBy config a =>
Direction -> Fixity -> a -> Doc ann)
-> m r
cont = do
config
config <- forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view forall env config. HasPrettyConfig env config => Lens' env config
prettyConfig
(forall a.
PrettyBy config a =>
Direction -> Fixity -> a -> Doc ann)
-> m r
cont forall a b. (a -> b) -> a -> b
$ \Direction
dir Fixity
fixity -> forall config a ann. PrettyBy config a => config -> a -> Doc ann
prettyBy forall a b. (a -> b) -> a -> b
$ config
config forall a b. a -> (a -> b) -> b
& forall config.
HasRenderContext config =>
Lens' config RenderContext
renderContext forall s t a b. ASetter s t a b -> b -> s -> t
.~ forall prec. Direction -> FixityOver prec -> RenderContextOver prec
RenderContext Direction
dir Fixity
fixity
withPrettyAt
:: MonadPrettyContext config env m
=> Direction -> Fixity -> (AnyToDoc config ann -> m r) -> m r
withPrettyAt :: forall config env (m :: * -> *) ann r.
MonadPrettyContext config env m =>
Direction -> Fixity -> (AnyToDoc config ann -> m r) -> m r
withPrettyAt Direction
dir Fixity
fixity AnyToDoc config ann -> m r
cont = forall config env (m :: * -> *) ann r.
MonadPrettyContext config env m =>
((forall a.
PrettyBy config a =>
Direction -> Fixity -> a -> Doc ann)
-> m r)
-> m r
withPrettyIn forall a b. (a -> b) -> a -> b
$ \forall a. PrettyBy config a => Direction -> Fixity -> a -> Doc ann
prettyIn -> AnyToDoc config ann -> m r
cont forall a b. (a -> b) -> a -> b
$ forall a. PrettyBy config a => Direction -> Fixity -> a -> Doc ann
prettyIn Direction
dir Fixity
fixity
unitDocM :: MonadPrettyContext config env m => Doc ann -> m (Doc ann)
unitDocM :: forall config env (m :: * -> *) ann.
MonadPrettyContext config env m =>
Doc ann -> m (Doc ann)
unitDocM = forall config env (m :: * -> *) ann.
MonadPrettyContext config env m =>
Fixity -> Doc ann -> m (Doc ann)
encloseM Fixity
unitFixity
compoundDocM
:: MonadPrettyContext config env m
=> Fixity
-> ((forall a. PrettyBy config a => Direction -> Fixity -> a -> Doc ann) -> Doc ann)
-> m (Doc ann)
compoundDocM :: forall config env (m :: * -> *) ann.
MonadPrettyContext config env m =>
Fixity
-> ((forall a.
PrettyBy config a =>
Direction -> Fixity -> a -> Doc ann)
-> Doc ann)
-> m (Doc ann)
compoundDocM Fixity
fixity (forall a.
PrettyBy config a =>
Direction -> Fixity -> a -> Doc ann)
-> Doc ann
k = forall config env (m :: * -> *) ann r.
MonadPrettyContext config env m =>
((forall a.
PrettyBy config a =>
Direction -> Fixity -> a -> Doc ann)
-> m r)
-> m r
withPrettyIn forall a b. (a -> b) -> a -> b
$ \forall a. PrettyBy config a => Direction -> Fixity -> a -> Doc ann
prettyIn -> forall config env (m :: * -> *) ann.
MonadPrettyContext config env m =>
Fixity -> Doc ann -> m (Doc ann)
encloseM Fixity
fixity forall a b. (a -> b) -> a -> b
$ (forall a.
PrettyBy config a =>
Direction -> Fixity -> a -> Doc ann)
-> Doc ann
k forall a. PrettyBy config a => Direction -> Fixity -> a -> Doc ann
prettyIn
sequenceDocM
:: MonadPrettyContext config env m
=> Direction -> Fixity -> (AnyToDoc config ann -> Doc ann) -> m (Doc ann)
sequenceDocM :: forall config env (m :: * -> *) ann.
MonadPrettyContext config env m =>
Direction
-> Fixity -> (AnyToDoc config ann -> Doc ann) -> m (Doc ann)
sequenceDocM Direction
dir Fixity
fixity AnyToDoc config ann -> Doc ann
k = forall config env (m :: * -> *) ann.
MonadPrettyContext config env m =>
Fixity
-> ((forall a.
PrettyBy config a =>
Direction -> Fixity -> a -> Doc ann)
-> Doc ann)
-> m (Doc ann)
compoundDocM Fixity
fixity forall a b. (a -> b) -> a -> b
$ \forall a. PrettyBy config a => Direction -> Fixity -> a -> Doc ann
prettyIn -> AnyToDoc config ann -> Doc ann
k forall a b. (a -> b) -> a -> b
$ forall a. PrettyBy config a => Direction -> Fixity -> a -> Doc ann
prettyIn Direction
dir Fixity
fixity
infixDocM
:: MonadPrettyContext config env m
=> Fixity
-> (AnyToDoc config ann -> AnyToDoc config ann -> Doc ann)
-> m (Doc ann)
infixDocM :: forall config env (m :: * -> *) ann.
MonadPrettyContext config env m =>
Fixity
-> (AnyToDoc config ann -> AnyToDoc config ann -> Doc ann)
-> m (Doc ann)
infixDocM Fixity
fixity AnyToDoc config ann -> AnyToDoc config ann -> Doc ann
k =
forall config env (m :: * -> *) ann.
MonadPrettyContext config env m =>
Fixity
-> ((forall a.
PrettyBy config a =>
Direction -> Fixity -> a -> Doc ann)
-> Doc ann)
-> m (Doc ann)
compoundDocM Fixity
fixity forall a b. (a -> b) -> a -> b
$ \forall a. PrettyBy config a => Direction -> Fixity -> a -> Doc ann
prettyIn ->
AnyToDoc config ann -> AnyToDoc config ann -> Doc ann
k (forall a. PrettyBy config a => Direction -> Fixity -> a -> Doc ann
prettyIn Direction
ToTheLeft Fixity
fixity) (forall a. PrettyBy config a => Direction -> Fixity -> a -> Doc ann
prettyIn Direction
ToTheRight Fixity
fixity)
juxtPrettyM
:: (MonadPrettyContext config env m, PrettyBy config a, PrettyBy config b)
=> a -> b -> m (Doc ann)
juxtPrettyM :: forall config env (m :: * -> *) a b ann.
(MonadPrettyContext config env m, PrettyBy config a,
PrettyBy config b) =>
a -> b -> m (Doc ann)
juxtPrettyM a
fun b
arg =
forall config env (m :: * -> *) ann.
MonadPrettyContext config env m =>
Fixity
-> (AnyToDoc config ann -> AnyToDoc config ann -> Doc ann)
-> m (Doc ann)
infixDocM Fixity
juxtFixity forall a b. (a -> b) -> a -> b
$ \AnyToDoc config ann
prettyL AnyToDoc config ann
prettyR -> AnyToDoc config ann
prettyL a
fun forall ann. Doc ann -> Doc ann -> Doc ann
<+> AnyToDoc config ann
prettyR b
arg