Haskell: Best tools to validate textual input?
Posted
by
Ana
on Programmers
See other posts from Programmers
or by Ana
Published on 2013-11-06T18:56:29Z
Indexed on
2013/11/06
22:07 UTC
Read the original article
Hit count: 383
In Haskell, there are a few different options to "parsing text". I know of Alex & Happy, Parsec and Attoparsec. Probably some others.
I'd like to put together a library where the user can input pieces of a URL (scheme e.g. HTTP, hostname, username, port, path, query, etc.) I'd like to validate the pieces according to the ABNF specified in RFC 3986.
In other words, I'd like to put together a set of functions such as:
validateScheme :: String -> Bool
validateUsername :: String -> Bool
validatePassword :: String -> Bool
validateAuthority :: String -> Bool
validatePath :: String -> Bool
validateQuery :: String -> Bool
What is the most appropriate tool to use to write these functions?
Alex's regexps is very concise, but it's a tokenizer and doesn't straightforwardly allow you to parse using specific rules, so it's not quite what I'm looking for, but perhaps it can be wrangled into doing this easily.
I've written Parsec code that does some of the above, but it looks very different from the original ABNF and unnecessarily long.
So, there must be an easier and/or more appropriate way. Recommendations?
© Programmers or respective owner