how to parse

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

how to parse

PICCA Frederic-Emmanuel
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
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: how to parse

Francesco Ariis
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-Combinator.html#v:manyTill
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: how to parse

PICCA Frederic-Emmanuel
> `manyTill` [1] should do
> [1] https://hackage.haskell.org/package/attoparsec-0.13.2.2/docs/Data-Attoparsec-Combinator.html#v:manyTill

It works,

thanks
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: how to parse

David McBride
I would actually use Data.Attoparsec.ByteString.Char8.takeWhile1.

prefix <- takeWhile1 (/= '_')


On Tue, Dec 10, 2019, 15:17 PICCA Frederic-Emmanuel <[hidden email]> wrote:
> `manyTill` [1] should do
> [1] https://hackage.haskell.org/package/attoparsec-0.13.2.2/docs/Data-Attoparsec-Combinator.html#v:manyTill

It works,

thanks
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: how to parse

PICCA Frederic-Emmanuel
The problem is that prefix can contain also a '_'
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners