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

Станислав Черничкин schernichkin at gmail.com
Wed Apr 17 13:46:19 UTC 2019


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20190417/9eda761c/attachment.html>


More information about the Haskell-Cafe mailing list