My types are:
data Test = Test {
a :: Int,
b :: Int
} deriving (Show)
My parser:
testParser :: Parser Test
testParser = do
a <- decimal
tab
b <- decimal
return $ Test a b
tab = char '\t'
Now, to skip the first line, I am doing something like this:
import qualified System.IO as IO
parser :: Parser Test
parser = manyTill anyChar endOfLine *> testParser
main = IO.withFile testFile IO.ReadMode $ \testHandle -> runEffect $
for (parsed (parser <* endOfLine) (fromHandle testHandle)) (lift . print)
But the above function parsermakes every alternate link skipped (which is obvious). As soon as you skip the first line so that it works with the Pipes ecosystem ( Producershould result in a single value Test). This is one obvious solution that I do not want (the code below will work if I change testParser to read new lines) because it returns an integer [Test]instead of a single value:
tests :: Parser [Test]
tests = manyTill anyChar endOfLine *>
many1 testParser
Any ideas to solve this problem?
source
share