KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I wanted, just to learn a bit about Iteratees, reimplement a simple parser I made, using Data.Iteratee and Data.Attoparsec.Iteratee. I'm pretty much stumped though. Below I have a simple example that is able to parse one line from a file. My parser reads one line at a time, so I need a way of feeding lines to the iteratee until it's done. I've read all I've found googling this, but a lot of the material on iteratee/enumerators is pretty advanced. This is the part of the code that matters: -- There are more imports above. import Data.Attoparsec.Iteratee import Data.Iteratee (joinI, run) import Data.Iteratee.IO (defaultBufSize, enumFile) line :: Parser ByteString -- left the implementation out (it doesn't check for new line) iter = parserToIteratee line main = do p <- liftM head getArgs i <- enumFile defaultBufSize p $ iter i' <- run i print i' This example will parse and print one line from a file with multiple lines. The original script mapped the parser over a list of ByteStrings. So I would like to do the same thing here. I found enumLines in Iteratee, but I can't for the life of me figure out how to use it. Maybe I misunderstand its purpose?
Tags (comma-separated)
Save Edits
Cancel