Date: Fri, 4 Feb 2022 15:09:41 +0100 (CET)
From: PICCA Frederic-Emmanuel
        <frederic-emmanuel.picca@synchrotron-soleil.fr>
To: haskell-cafe@haskell.org
Subject: [Haskell-cafe] optparse-applicative with attoparsec parser
Message-ID:
        <30404406.15581346.1643983781075.JavaMail.zimbra@synchrotron-soleil.fr>

Content-Type: text/plain; charset=utf-8

Hello,

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))
    where
      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

It seems that the issue stems from having your arguments separated by spaces. If your parser is parsing [[ [debug-flag] <command> <file> <ranges> ]], then it does not know what to do with the last particle (735-736). You would need to wrap your ranges in quotes in your shell, to include the space, or replace the space with a comma instead (698-734,735-736)

Sébastien