How do I implement a parser for this example from grep --help
:
--binary-files=TYPE assume that binary files are TYPE;
TYPE is 'binary', 'text', or 'without-match'
Assuming that I have
data BinaryFiles = Binary | Text | WithoutMatch
How do I write a parser? option auto
seems a kludge since Read
is supposed to be an "inverse" to Show
, and I'd like to keep the derived instance Show BinaryFiles
.
Use str
instead of auto
:
binFile :: ReadM BinaryFiles
binFile = str >>= \s -> case s of
"binary" -> return Binary
"text" -> return Text
"without-match" -> return WithoutMatch
_ -> readerError "Accepted binary file types are 'binary', 'text', and 'without-match'."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With