final-pretty-printer-0.1.0.0: Extensible pretty printing with semantic annotations and proportional fonts

Copyright(c) David Darais David Christiansen and Weixi Ma 2016-2017
LicenseMIT
Maintainerdavid.darais@gmail.com
Stabilityexperimental
PortabilityPortable
Safe HaskellNone
LanguageHaskell2010

Text.PrettyPrint.Final.Extensions.Precedence

Contents

Description

A transformer of pretty monads that provides effects for inserting parentheses minimally and correctly.

Synopsis

Precedence information

data PrecEnv ann Source #

A precedence environment contains enough information to determine whether parentheses should be inserted.

Constructors

PrecEnv 

Fields

  • level :: Int

    The current precedence level of the context

  • bumped :: Bool

    A tiebreaker used to distinguish left- and right-associative contexts

  • lparen :: (Text, Maybe ann)

    What to show for a left parenthesis. The optional annotation will be applied.

  • rparen :: (Text, Maybe ann)

    What to show for a right parenthesis. The optional annotation will be applied.

precEnv0 :: PrecEnv ann Source #

An initial precedence environment that works for languages with parentheses as delimiters.

Precedence effects

askLevel :: (Functor m, MonadReaderPrec ann m) => m Int Source #

What is the current precedence level?

localLevel :: (Functor m, MonadReaderPrec ann m) => (Int -> Int) -> m a -> m a Source #

Run a subcomputation with a modified precedence level.

infl :: MonadPrettyPrec w ann fmt m => Int -> m () -> m () -> m () -> m () Source #

Display a left-associative infix operator at a precedence level

infr :: MonadPrettyPrec w ann fmt m => Int -> m () -> m () -> m () -> m () Source #

Display a right-associative infix operator at a precedence level

atLevel :: MonadPrettyPrec w ann fmt m => Int -> m () -> m () Source #

Run a subcomputation at a particular precedence level

botLevel :: MonadPrettyPrec w ann fmt m => m () -> m () Source #

Put a subdocument in the lowest precedence context

app :: MonadPrettyPrec w ann fmt m => m () -> [m ()] -> m () Source #

Perform function application with precedence level <100

askBumped :: (Functor m, MonadReaderPrec ann m) => m Bool Source #

Is the current precedence bumped? See PrecEnv.

The transformer

class MonadReaderPrec ann m | m -> ann where Source #

Precedence follows the structure of a document, so a Reader provides the appropriate dynamic extent of precedence information.

Minimal complete definition

askPrecEnv, localPrecEnv

Methods

askPrecEnv :: m (PrecEnv ann) Source #

What is the current precedence environment? (see ask)

localPrecEnv :: (PrecEnv ann -> PrecEnv ann) -> m a -> m a Source #

Override the precedence environment in a subcomputation. (see local)

Instances

Monad m => MonadReaderPrec ann (PrecT ann m) Source # 

Methods

askPrecEnv :: PrecT ann m (PrecEnv ann) Source #

localPrecEnv :: (PrecEnv ann -> PrecEnv ann) -> PrecT ann m a -> PrecT ann m a Source #

(Monad m, MonadReaderPrec ann m) => MonadReaderPrec ann (EnvT env m) Source # 

Methods

askPrecEnv :: EnvT env m (PrecEnv ann) Source #

localPrecEnv :: (PrecEnv ann -> PrecEnv ann) -> EnvT env m a -> EnvT env m a Source #

class (MonadPretty w ann fmt m, MonadReaderPrec ann m) => MonadPrettyPrec w ann fmt m | m -> w, m -> ann, m -> fmt Source #

A pretty monad that can read precedence environments

newtype PrecT ann m a Source #

A monad transformer that adds a precedence effects

Constructors

PrecT 

Fields

Instances

MonadReader r m => MonadReader r (PrecT ann m) Source # 

Methods

ask :: PrecT ann m r #

local :: (r -> r) -> PrecT ann m a -> PrecT ann m a #

reader :: (r -> a) -> PrecT ann m a #

MonadState s m => MonadState s (PrecT ann m) Source # 

Methods

get :: PrecT ann m s #

put :: s -> PrecT ann m () #

state :: (s -> (a, s)) -> PrecT ann m a #

MonadWriter o m => MonadWriter o (PrecT ann m) Source # 

Methods

writer :: (a, o) -> PrecT ann m a #

tell :: o -> PrecT ann m () #

listen :: PrecT ann m a -> PrecT ann m (a, o) #

pass :: PrecT ann m (a, o -> o) -> PrecT ann m a #

Monad m => MonadReaderPrec ann (PrecT ann m) Source # 

Methods

askPrecEnv :: PrecT ann m (PrecEnv ann) Source #

localPrecEnv :: (PrecEnv ann -> PrecEnv ann) -> PrecT ann m a -> PrecT ann m a Source #

MonadTrans (PrecT ann) Source # 

Methods

lift :: Monad m => m a -> PrecT ann m a #

Monad m => Monad (PrecT ann m) Source # 

Methods

(>>=) :: PrecT ann m a -> (a -> PrecT ann m b) -> PrecT ann m b #

(>>) :: PrecT ann m a -> PrecT ann m b -> PrecT ann m b #

return :: a -> PrecT ann m a #

fail :: String -> PrecT ann m a #

Functor m => Functor (PrecT ann m) Source # 

Methods

fmap :: (a -> b) -> PrecT ann m a -> PrecT ann m b #

(<$) :: a -> PrecT ann m b -> PrecT ann m a #

Applicative m => Applicative (PrecT ann m) Source # 

Methods

pure :: a -> PrecT ann m a #

(<*>) :: PrecT ann m (a -> b) -> PrecT ann m a -> PrecT ann m b #

(*>) :: PrecT ann m a -> PrecT ann m b -> PrecT ann m b #

(<*) :: PrecT ann m a -> PrecT ann m b -> PrecT ann m a #

Alternative m => Alternative (PrecT ann m) Source # 

Methods

empty :: PrecT ann m a #

(<|>) :: PrecT ann m a -> PrecT ann m a -> PrecT ann m a #

some :: PrecT ann m a -> PrecT ann m [a] #

many :: PrecT ann m a -> PrecT ann m [a] #

runPrecT :: PrecEnv ann -> PrecT ann m a -> m a Source #

Run a precedence transformer with some initial precedence environment

mapPrecT :: (m a -> n b) -> PrecT ann m a -> PrecT ann n b Source #

Transform the value returned by a PrecT