如何从grep --help
:
--binary-files=TYPE assume that binary files are TYPE;
TYPE is 'binary', 'text', or 'without-match'
假设我有
data BinaryFiles = Binary | Text | WithoutMatch
如何编写解析器? option auto
似乎是一个问题因为Read
应该与Show
“反向”,我想保留派生的instance Show BinaryFiles
。
答案 0 :(得分:5)
使用str
代替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'."