madlang-2.1.1.2: Randomized templating language DSL

Safe HaskellNone
LanguageHaskell2010

Text.Madlibs

Contents

Description

Main module exporting the relevant functions

Synopsis

Parsers for `.mad` files

parseTok :: FilePath -> [(Key, RandTok)] -> [Text] -> Text -> Either (ParseError Char Dec) RandTok Source #

Parse text as a token

f <- readFile "template.mad"
parseTok f

| Parse text given a context

parseTokM :: [Text] -> Parser (Context RandTok) Source #

Parse text as a token + context (aka a reader monad with all the other functions)

runFile :: [Text] -> FilePath -> IO Text Source #

Generate randomized text from a file conatining a template

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

Parse a template file into the RandTok data type

makeTree :: [Text] -> FilePath -> FilePath -> IO (Either (ParseError Char Dec) RandTok) Source #

Parse a template into a RandTok suitable to be displayed as a tree

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

runMadlang :: IO () Source #

Main program action