[Haskell-cafe] optparse-applicative with attoparsec parser

PICCA Frederic-Emmanuel frederic-emmanuel.picca at synchrotron-soleil.fr
Fri Feb 4 14:09:41 UTC 2022


I Try to write a parser for this command line

binoculars-ng --debug process data/test/config_sixs_ruche_flymedv_3.ini 698-734 735-736

But I  have this problem

Invalid argument `735-736'

The parser used for this is this one

processOptions :: Parser Options
processOptions = Process
                 <$> optional config
                 <*> optional (argument (eitherReader (parseOnly configRangeP . pack)) (metavar "RANGE"))

it use the configRangeP attoparser parser whcih knows how to deal with the string "698-734 735-736"

configRangeP :: Parser ConfigRange
configRangeP = ConfigRange <$> (inputRangeP `sepBy` many (satisfy isSep))
      isSep :: Char -> Bool
      isSep c = c == ' ' || c == ','

the result should be this one

Just (ConfigRange [InputRangeFromTo 698 734,InputRangeFromTo 735 736])

so my question how should I fix my processOptions fucntion in order to deal with this problem.

thanks for considering


More information about the Haskell-Cafe mailing list