Skip to content

Latest commit

 

History

History
24 lines (20 loc) · 544 Bytes

example2.md

File metadata and controls

24 lines (20 loc) · 544 Bytes

definitions

exampleCmdParser :: CmdParser Identity Int ()
exampleCmdParser = do
  addCmd "foo" $ addCmdImpl 42
  addCmd "bar" $ addCmdImpl 99
  addCmdImpl 0

fooBarParser :: String -> Either ParsingError (CommandDesc Int)
fooBarParser str = result
  where
    (_desc, result) =
      runCmdParser (Just "example") (InputString str) exampleCmdParser

Behaviour of fooBarParser:

fooBarParser ""    ~> Right 0
foobarParser "foo" ~> Right 42
foobarParser "bar" ~> Right 99
fooBarParser _     ~> Left someParsingError