Created
February 21, 2015 12:48
-
-
Save svdberg/abb9f12c8f91367341f0 to your computer and use it in GitHub Desktop.
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
{-# LANGUAGE OverloadedStrings #-} | |
module CommandParser where | |
import Data.Attoparsec.Char8 | |
import Control.Applicative | |
import qualified Data.Text.Lazy as L | |
import Data.Text.Encoding | |
data Command = Retrieve | Delete | New deriving Show | |
parseCommand :: Parser Command | |
parseCommand = | |
(string "Retrieve" >> return Retrieve) | |
<|> (string "Delete" >> return Delete) | |
<|> (string "New" >> return New) | |
parse :: L.Text -> Either String Command | |
parse s = parseOnly parseCommand ((encodeUtf8 . L.toStrict) s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment