Skip to content

Instantly share code, notes, and snippets.

@munro
Last active August 29, 2015 14:01
Show Gist options
  • Save munro/11e4eecc196a746a7975 to your computer and use it in GitHub Desktop.
Save munro/11e4eecc196a746a7975 to your computer and use it in GitHub Desktop.
-- | [33] IntConstant ::= ('+' | '-')? Digit+
-- >>> parse intConstant "fail" "+123"
-- Right "+123"
--
-- >>> parse intConstant "fail" "0003"
-- Right "0003"
--
-- >>> parse intConstant "fail" "-321"
-- Right "-321"
intConstant :: GenParser Char st String
intConstant = do
chr <- optionMaybe (char '+' <|> char '-')
str <- many digit
return $ case chr of Just a -> a : str
Nothing -> str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment