-
-
Save reinh/7e93f3fdad806221afcf 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.ByteString.Char8 | |
import Data.Attoparsec.Combinator | |
import Control.Applicative | |
import Data.ByteString | |
data Command = Retrieve | Delete | New deriving Show | |
parseCommand :: Parser Command | |
parseCommand = choice | |
[ Retrieve <? string "Retrieve" | |
, Delete <? string "Delete" | |
, New <? string "New" | |
] | |
parseInput s = parseOnly (parseCommand <|> string s) | |
parse :: ByteString -> Either String Command | |
parse s = parseOnly parseCommand s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment