I'm trying to parse some Text with parsec:
data Cmd = LoginCmd String
| JoinCmd String
| LeaveCmd String
deriving (Show)
singleparam :: Parser Cmd
singleparam = do
cmd <- choice [string "leave", string "login", string "join"]
spaces
nick <- many1 anyChar
eof
return $ LoginCmd nick
I'm expecting choice
to try to match "leave", and if it fails, then try "login" etc. But it only tries to match "leave", and if it fails, then gives an error.
ghci> parseTest singleparam (pack "login asdf")
parse error at (line 1, column 1):
unexpected "o"
expecting "leave"
ghci> parseTest singleparam (pack "leave asdf")
LoginCmd "asdf"
What am I doing wrong?