I have been working through the exercises in a Write Yourself a Scheme in 48 Hours/Parsing and hacked together something to get parseString to comprehend escaped characters. Also had some inspiration from Real World Haskell chapter 16 minus the applicative parts.
parseString :: Parser LispVal parseString = do char '"' x <- many $ chars char '"' return $ String x where chars = escaped <|> noneOf "\"" escaped = choice $ map tryEscaped escapedChars tryEscaped c = try $ char '\\' >> char (fst c) >> return (snd c) escapedChars = zip "bnfrt\\\"/" "\b\n\f\r\t\\\"/"
This works but I am not fond of my 'tryEscaped' definition. What are the alternatives?