[Haskell-cafe] Is there already a lib to parse a line of string with a pattern and generate key-value map or a record?

Frank Dedden frank at dedden.net
Wed Apr 17 15:27:22 UTC 2019


I think you're looking for a scanf (well known in C) like function. A quick
search give me:
https://hackage.haskell.org/package/scanf
https://hackage.haskell.org/package/xformat

I haven't used either of them, so I can't recommend one.

Regards,
Frank Dedden

On Wed, Apr 17, 2019 at 10:32:07PM +0800, Magicloud Magiclouds wrote:
> Thanks. I am familiar with this kind of usage (attoparsec). But it is
> still somehow complex and not flexible.
> 
> Let me see what Frame can do.
> 
> On Wed, Apr 17, 2019 at 9:46 PM Станислав Черничкин
> <schernichkin at gmail.com> wrote:
> >
> > I think specific formats can be parsed with attoparsec (Data.Attoparsec.Text):
> >
> > p = do
> >    year <- yearP
> >    char '/'
> >    month <- monthP
> >    char '/'
> >    ....
> >    return (year, month, ...)
> >
> > You may also use cassava to parse csv-like files, or Frames for type-safe parsing. With Frames you may custom readers ( http://acowley.github.io/Frames/#orgfa57664 ) with complex pattern-matching, this will require typing skills though.
> >
> > ср, 17 апр. 2019 г. в 12:30, Magicloud Magiclouds <magicloud.magiclouds at gmail.com>:
> >>
> >> Hi,
> >>
> >> I saw this function in some web tools, pretty useful when parsing log
> >> or so. So I wonder if Haskell has similar libs already.
> >>
> >> Sample:
> >>
> >> Input line: "2019/04/17 17:27 User magicloud runs command ls."
> >>
> >> Pattern: "${year}/${month}/${day} ${hour}:${minute} User ${username}
> >> runs command ${command}."
> >>
> >> Output: toList [ ("year", "2019"), ("month", "04") , etc ]
> >>
> >> --
> >> 竹密岂妨流水过
> >> 山高哪阻野云飞
> >>
> >> And for G+, please use magiclouds#gmail.com.
> >> _______________________________________________
> >> Haskell-Cafe mailing list
> >> To (un)subscribe, modify options or view archives go to:
> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> >> Only members subscribed via the mailman list are allowed to post.
> >
> >
> >
> > --
> > Sincerely, Stanislav Chernichkin.
> 
> 
> 
> -- 
> 竹密岂妨流水过
> 山高哪阻野云飞
> 
> And for G+, please use magiclouds#gmail.com.
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.


More information about the Haskell-Cafe mailing list