I am trying to parse text with a 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 expect choice try to match "leave", and if that fails, try "login", etc. But he is only trying to match the "leave", and if he fails, he 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?
haskell parsec
sinan
source share