Created
January 22, 2016 11:02
-
-
Save jtanguy/1e5bf37bca84b5ce58da to your computer and use it in GitHub Desktop.
Simple query parameter parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-| | |
Module : URIParser | |
Copyright : (c) 2016 Julien Tanguy | |
License : BSD3 | |
Maintainer : julien.tanguy@jhome.fr | |
Stability : experimental | |
Portability : portable | |
Simple URI parser. Parses query string parameters into a map | |
-} | |
module URIParser where | |
--------------------- | |
import Text.Trifecta | |
-------- OR --------- | |
-- import Text.Parsec | |
-- import Text.Parsec.String | |
--------------------- | |
type QueryMap = [(String,String)] | |
queryStringParser :: Parser QueryMap | |
queryStringParser = anyChar `manyTill` string "?" *> keyValue `sepBy` string "&" <* eof | |
keyValue :: Parser (String, String) | |
keyValue = (,) <$> key <*> (string "=" *> value) | |
key :: Parser String | |
key = many alphaNum | |
value :: Parser String | |
value = many alphaNum | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment