prettyprinter-0.1: A modern, extensible and well-documented prettyprinter.

Safe HaskellSafe
LanguageHaskell2010

Data.Text.Prettyprint.Doc.Render.Util.StackMachine

Description

A strict State/Writer monad to implement a stack machine for rendering SimpleDocs.

Synopsis

Documentation

data StackMachine output style a Source #

WriterT output StateT [style] a, but with a strict Writer value.

The output type is used to append data chunks to, the style is the member of a stack of styles to model nested styles with.

Instances

Monoid output => Monad (StackMachine output style) Source # 

Methods

(>>=) :: StackMachine output style a -> (a -> StackMachine output style b) -> StackMachine output style b #

(>>) :: StackMachine output style a -> StackMachine output style b -> StackMachine output style b #

return :: a -> StackMachine output style a #

fail :: String -> StackMachine output style a #

Functor (StackMachine output style) Source # 

Methods

fmap :: (a -> b) -> StackMachine output style a -> StackMachine output style b #

(<$) :: a -> StackMachine output style b -> StackMachine output style a #

Monoid output => Applicative (StackMachine output style) Source # 

Methods

pure :: a -> StackMachine output style a #

(<*>) :: StackMachine output style (a -> b) -> StackMachine output style a -> StackMachine output style b #

(*>) :: StackMachine output style a -> StackMachine output style b -> StackMachine output style b #

(<*) :: StackMachine output style a -> StackMachine output style b -> StackMachine output style a #

execStackMachine :: [styles] -> StackMachine output styles a -> (output, [styles]) Source #

Run the renderer and retrive the writing end

pushStyle :: Monoid output => style -> StackMachine output style () Source #

Add a new style to the style stack.

unsafePopStyle :: Monoid output => StackMachine output style style Source #

Get the topmost style.

If the stack is empty, this raises an error.

unsafePeekStyle :: Monoid output => StackMachine output style style Source #

View the topmost style, but do not modify the stack.

If the stack is empty, this raises an error.

writeOutput :: output -> StackMachine output style () Source #

Append a value to the output end.