A macroprocessor is a program that transforms a text file by replacing specially identified keywords within the file by a specified piece of text. Keywords are strings that begin with the character ’$’. Each definition comprises a keyword followed by a (single) space character and then the keyword’s definition, which is a sequence of words, possibly including punctuation and whitespace characters. For example, given from the info file
$name William Shakespeare
$birth-date 1564
$town Stratford upon Avon
Welcome to $town, where $name was born in $birth-date.
Welcome to Stratford upon Avon, where William Shakespeare was born in 1564.
type FileContents = Stringtype Keyword = String
type KeywordValue = String
type KeywordDefs = [(Keyword, KeywordValue)]
lookUp :: String -> [(String, a)] -> [a]
given a search string and a list of string/item pairs, returns the list of items whose associated string matches the search string
split :: [Char] -> String -> (String, [String])
break up a string in a way that returns a pair comprising the separator characters, i.e. a String, and the list of words, a [String], in the order that they were encountered in the input
combine :: String -> [String] -> [String]
combine the components of a string from its constituent separator characters and words, as generated by a call to split.
getKeywordDefs :: [String] -> KeywordDefs
takes the contents of an information file in the form of a list of lines (each line is a string), and which returns a list of keyword/definition pairs.
expand :: FileContents -> FileContents -> FileContents
takes the contents of a text file and an info file and combines them using the above functions to build a string representing the output file.