madlang-0.1.0.1: Randomized templating language DSL

Safe HaskellNone
LanguageHaskell2010

Text.Madlibs

Contents

Description

Main module exporting the relevant functions

Synopsis

Parsers for `.mad` files

parseTok :: Text -> Either (ParseError Char Dec) RandTok Source #

Parse text as a token

f <- readFile "template.mad"
parseTok f

runFile :: FilePath -> IO Text Source #

Generate randomized text from a file conatining a template

parseFile :: FilePath -> IO (Either (ParseError Char Dec) RandTok) Source #

Parse a template file into the RandTok data type

templateGen :: Text -> Either (ParseError Char Dec) (IO Text) Source #

Generate randomized text from a template

Functions and constructs for the RandTok data type

run :: RandTok -> IO Text Source #

Generate randomized text from a RandTok

data RandTok Source #

datatype for a token returning a random string

Constructors

List [(Prob, RandTok)] 
Value Text 

Instances

Eq RandTok Source # 

Methods

(==) :: RandTok -> RandTok -> Bool #

(/=) :: RandTok -> RandTok -> Bool #

Show RandTok Source # 
Monoid RandTok Source #

Make RandTok a monoid so we can append them together nicely (since they do generate text).

(Value "Hello") <> (List [(0.5," you"), (0.5, " me")])
(List [(0.5,"Hello you"), (0.5, "Hello me")])
Eq a => Eq (Context a) Source #

Compare inside the state monad using only the underlying objects

Methods

(==) :: Context a -> Context a -> Bool #

(/=) :: Context a -> Context a -> Bool #

Types associated with the parser

type Context a = State [(Key, RandTok)] a Source #

State monad providing context, i.e. function we've already called before

Command-line executable

exec :: IO () Source #

Main program action