Skip to content

Instantly share code, notes, and snippets.

@svdberg
Created February 21, 2015 12:48
Show Gist options
  • Save svdberg/abb9f12c8f91367341f0 to your computer and use it in GitHub Desktop.
Save svdberg/abb9f12c8f91367341f0 to your computer and use it in GitHub Desktop.
{-# 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