[Haskell-beginners] attoparsec and EOF

Arthur Clune arthur at clune.org
Tue Jun 5 11:56:50 CEST 2012

I'm writing a simple attoparsec parser, which works fine except for
handling end of file:

value :: Parser T.Text
value = takeWhile1 (/= ' ')

accessLogLine::Parser AccessLogLine
accessLogLine = do
    lts        <- number
    lelapsed   <- skipSpace *> number
    lclientIP  <- space *> value
    -- [... more like this ...]
    lhierarchy <- space *> value
    lmimeType  <- space *> takeWhile1 (not . isEndOfLine) <* endOfLine
    return $ AccessLogLine lts lelapsed lclientIP laction lsize
lmethod lurl lident lhierarchy lmimeType

accessLogParser::Parser [AccessLogLine]
accessLogParser = do
    result <- many accessLogLine
    return result

main = do
    contents <- (S.readFile "/home/arthur/Work/data/sample_acccess_log")
    print (A.maybeResult $ (A.parse accessLogParser $ decodeUtf8 contents))

This all works, but I need to cover the case where the final line in
the file does not end with '\n' and I can't get that to work

I found http://stackoverflow.com/questions/2988988/problem-with-incomplete-input-when-using-attoparsec,
which hints at what my problem is, but I can't see how to apply that

Grateful for some hints.


Arthur Clune arthur at clune.org

More information about the Beginners mailing list