Skip to content

Instantly share code, notes, and snippets.

@reinh
Forked from svdberg/CommandParser.hs
Last active August 29, 2015 14:15
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 reinh/7e93f3fdad806221afcf to your computer and use it in GitHub Desktop.
Save reinh/7e93f3fdad806221afcf to your computer and use it in GitHub Desktop.
{-# 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