transf-0.12: Text transformer and interpreter.

Safe HaskellNone

Text.Transf

Contents

Synopsis

Basic types

type Line = StringSource

A single line of text.

type Lines = StringSource

Multiple lines of text.

type RelativePath = FilePathSource

  A relative file path.

The Context type

type Context = ContextT IOSource

  The Context monad defines the context of a transformation.

The main purpose of this type is to restrict the the number of functions you can pass to transform.

data ContextT m a Source

runContext :: Context a -> IO (Either String a)Source

Run a computation in the Context monad.

Transformormations

data Transform Source

A transformation.

transform :: String -> (Lines -> Context Lines) -> TransformSource

Create a new transformation.

This transformation processes everything in between lines containing a fence such as

 ~~~name
 ~~~

or

 ```name
 ```

where name is the name of the transformation.

To create a suitable change function, use the combinators defined below.

Running transformations

runTransform :: Transform -> String -> Context StringSource

  Run a transformation in the Context monad.

Combinators

Input/output

writeFile :: RelativePath -> String -> Context ()Source

Write to a file.

inform :: String -> Context ()Source

Write to the standard error stream.

Evaluation

eval :: Typeable a => String -> Context aSource

Evaluate a Haskell expression.

evalWith :: Typeable a => [String] -> String -> Context aSource

Evaluate a Haskell expression with the given modules in scope. Note that Prelude is not implicitly imported.

All requested modules must be present on the system or the computation will fail. Also, the string must be a valid Haskell expression using constructs which in scope after loading the given modules.

Errors can be caught using catchError.

addPost :: Context () -> Context ()Source

Register an action to be run after text processing has finished. This can be used to optimize tasks such as external file generations.

Note that addPost does not work trasitively, i.e. post actions of post actions are thrown away.

Transformormations

printT :: TransformSource

This named transformation posts its input to the standard error stream and returns nothing.

evalT :: TransformSource

This named transformation evaluates its input as a Haskell expression of type String and returns the value of the expression.

For example the input

 ~~~haskell
 "The number is " ++ show $ 3 + 2
 ~~~

Will be transformed into

 The number is 6

musicT :: TransformSource

This named transformation evaluates its input as a music expression.

The music is rendered as an .ly file and a .mid fiel, then lilypond and convert is run to render a .png file. A markdown image tag and a HTML play and stop button is returned.

The expression must return a value of type Score Note. The Music.Prelude.Basic module is implicitly imported.

data MusicOpts Source

Constructors

MusicOpts 

Fields

format :: String
 
resolution :: Int
 
resize :: Int
 

Instances

haskellT :: TransformSource

This named transformation passes everything through and retains the source.

musicHaskellT :: TransformSource

This named transformation runs the music transformation and retains the source.

musicExtraT :: TransformSource

This named transformation includes stuff needed for music playback.

It should be used exactly once in the document.