3 ms·
As someone who needs parsers in a daily basis, I got hooked by your "oneliner parser". A search for parser generation in Haskell only gave me typical parser gen
by sasaf5 6y ago
As someone who needs parsers in a daily basis, I got hooked by your "oneliner parser". A search for parser generation in Haskell only gave me typical parser generators. Can you point some examples?
- WJW 6y agoWhat you'd want to google is "parser combinators" or "parsec tutorial" I think. The idea is that parsers are "just" functions and can therefore be combined with higher order functions in various ways to produce "bigger" parsers. For example, an element in the Redis replication stream can be either an Array, a BulkString, an Integer, an Error or a SimpleString and you can express that with the `choice` function: parseRedisValue = choice [ parseRedisArray, parseRedisBulkString, parseRedisInteger, parseRedisError, parseRedisSimpleString] Each of the underlying parsers (ie `parseRedisArray` etc) are also built up out of smaller parsers, all the way down to parsers that just detect a single character. It seems like it should be slow, but in my experience the results have not diappointed yet. If you're interested, I wrote a longer example on my blog, at http://www.wjwh.eu/posts/2019-01-01-parsing-infinite-streams.html http://www.wjwh.eu/posts/2019-01-01-parsing-infinite-streams...