Search code examples
haskellattoparsec

Attoparsec: Skip rest of current line


I'm writing a parser using attoparsec. The parser is parsing a line-based format, for example this file

1,2,3
4,5,6

Let's assume the parser is currently placed just before 2 in the first line. How can I skip the rest of the line including the \n character.

Note: This question was answered Q&A-style and therefore intentionally doesn't show research effort.


Solution

  • The answer to this is a simple combinator, however I wasn't able to find an easy & ready-to-use solution for this.

    import Data.Attoparsec.ByteString.Char8
    
    skipRestOfLine :: Parser ()
    skipRestOfLine = skipWhile (not . isEndOfLine) >> endOfLine