title: Skip blank lines with Parsec
body: <p>New to Parsec, a beginner's question. How can one parse a file of lines where some lines may be blank, consisting only of whitespace followed by a newline? I just want to skip them, not have them in the parsed output.</p>
  
  <pre><code>import Text.ParserCombinators.Parsec
  
  -- alias for parseTest
  run :: Show a =&gt; Parser a -&gt; String -&gt; IO ()
  run = parseTest
  
  -- parse lines
  p :: Parser [[String]]
  p = lineP `endBy` newline &lt;* eof
    where lineP = wordP `sepBy` (char ' ')
          wordP = many $ noneOf "\n"
  </code></pre>
  
  <p>Example parse with blank line:</p>
  
  <pre><code>*Main&gt; run p "z x c\n1 2 3\n    \na\n"
  [["z x c"],["1 2 3"],["    "],["a"]]
  </code></pre>
  
  <p>I suspect I am going about this all wrong.</p>