| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Text.Madlibs
Contents
Description
Main module exporting the relevant functions
- parseTok :: FilePath -> [(Key, RandTok)] -> [Text] -> Text -> Either (ParseError Char Dec) RandTok
- parseTokM :: [Text] -> Parser (Context RandTok)
- runFile :: [Text] -> FilePath -> IO Text
- parseFile :: [Text] -> FilePath -> FilePath -> IO (Either (ParseError Char Dec) RandTok)
- makeTree :: [Text] -> FilePath -> FilePath -> IO (Either (ParseError Char Dec) RandTok)
- run :: MonadRandom m => RandTok -> m Text
- runText :: MonadRandom m => [Text] -> String -> Text -> m Text
- data RandTok
- type Context a = State [(Key, RandTok)] a
- data SemanticError
- runMadlang :: IO ()
Parsers for .mad files
parseTok :: FilePath -> [(Key, RandTok)] -> [Text] -> Text -> Either (ParseError Char Dec) RandTok Source #
Parse text given a context
import qualified Data.Text.IO as TIO f <- TIO.readFile "template.mad" parseTok "filename.mad" [] [] f
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
Arguments
| :: [Text] | variables to substitute into the template |
| -> FilePath | folder |
| -> FilePath | filepath within folder |
| -> IO (Either (ParseError Char Dec) RandTok) | parsed |
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
runText :: MonadRandom m => [Text] -> String -> Text -> m Text Source #
Run based on text input, with nothing linked.
datatype for a token returning a random string
Instances
| Eq RandTok Source # | |
| Show RandTok Source # | |
| Monoid RandTok Source # | Make (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 |
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
data SemanticError Source #
Datatype for a semantic error
Constructors
| NoReturn | |
| CircularFunctionCalls Text Text | |
| InsufficientArgs Int Int | |
| DoubleDefinition Text | |
| NoContext Text |
Instances
| Show SemanticError Source # | display a |
| Exception SemanticError Source # | Derived via our show instance; |
Command-line executable
runMadlang :: IO () Source #
Main program action