butcher/example2.md

544 B

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