[Haskell-cafe] ANN: format-0.1.0.0
Scott Lawrence
bytbox at gmail.com
Sun May 27 01:19:59 CEST 2012
Hey all,
I've just uploaded to hackage format-0.1, a small library for handling format
strings similar to those used by nginx's log_format directive. The idea is to
allow easy parsing of text rendered with such a format string, to make parsing
simple, automatically generated text files as easy as possible. So for
example, if you want to parse lines consisting of two bits of text, separated
by " -- ", then
map (scanFormatString "$a -- $b") $ lines text
will do so, generating associative arrays with the variable names as keys and
their content as values. A `renderFormatString` function, doing the obvious,
is also provided.
Obligatory blog post with some more details:
http://bytbox.net/blog/2012/05/format-haskell.html
I hope somebody finds this useful. (This seems the sort of thing which should
already have existed, but I couldn't find anything. Did I miss it?)
I'm using parsec underneath, both for parsing the format string and the
generated parser, and I've payed no attention to optimization. Some simple
testing indicates that a reasonably fast computer takes about 1 second to
parse 5000 lines with nginx's (and apache's) default format string - pretty
slow. If there's demand, I'll be happy to pay more attention to that.
--
Scott Lawrence
More information about the Haskell-Cafe
mailing list