
Hello, I have a bunch of files names like this <prefix>_data_00006.cbf I would like to parse it into this type data CbfDataFile = CbfDataFile Text Int where Test is <prefix> and Int = 6 I am using attoparsec, I started to write my parser like this parseCbfDataFile :: String -> Parser CbfDataFile parseCbfDataFile s = do prefix <- ???? string "_data_" v <- decimal string ".cbf" return (CbfDataFile prefix v) So my question, is how to I write this parser. I miss for now the prefix part, and it seems also to me thaht I need something else for the numeric part. thanks for your help Frederic

On Tue, Dec 10, 2019 at 09:47:41AM +0000, PICCA Frederic-Emmanuel wrote:
I have a bunch of files names like this <prefix>_data_00006.cbf
[...]
I am using attoparsec, I started to write my parser like this
parseCbfDataFile :: String -> Parser CbfDataFile parseCbfDataFile s = do prefix <- ???? string "_data_" v <- decimal string ".cbf" return (CbfDataFile prefix v)
So my question, is how to I write this parser.
`manyTill` [1] should do [1] https://hackage.haskell.org/package/attoparsec-0.13.2.2/docs/Data-Attoparsec...

`manyTill` [1] should do [1] https://hackage.haskell.org/package/attoparsec-0.13.2.2/docs/Data-Attoparsec...
It works, thanks

I would actually use Data.Attoparsec.ByteString.Char8.takeWhile1. prefix <- takeWhile1 (/= '_') On Tue, Dec 10, 2019, 15:17 PICCA Frederic-Emmanuel < frederic-emmanuel.picca@synchrotron-soleil.fr> wrote:
`manyTill` [1] should do [1] https://hackage.haskell.org/package/attoparsec-0.13.2.2/docs/Data-Attoparsec...
It works,
thanks _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
participants (3)
-
David McBride
-
Francesco Ariis
-
PICCA Frederic-Emmanuel