Skip to content

Instantly share code, notes, and snippets.

@jtanguy
Created January 22, 2016 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtanguy/1e5bf37bca84b5ce58da to your computer and use it in GitHub Desktop.
Save jtanguy/1e5bf37bca84b5ce58da to your computer and use it in GitHub Desktop.
Simple query parameter parser
{-|
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