[Haskell-beginners] how to parse

PICCA Frederic-Emmanuel frederic-emmanuel.picca at synchrotron-soleil.fr
Tue Dec 10 09:47:41 UTC 2019


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


More information about the Beginners mailing list