我的类型:
data Test = Test {
a :: Int,
b :: Int
} deriving (Show)
我的解析器:
testParser :: Parser Test
testParser = do
a <- decimal
tab
b <- decimal
return $ Test a b
tab = char '\t'
现在为了跳过第一行,我做了这样的事情:
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)
但是上面的parser
函数使每个备用链接都跳过(这很明显)。如何仅以与 Pipes 生态系统一起使用的方式跳过第一行(Producer
应该产生单个Test
值。)这是我不想要的一个明显的解决方案(以下代码仅在我修改 testParser 以读取换行符时才有效) 因为它返回整个[Test]
而不是单个值:
tests :: Parser [Test]
tests = manyTill anyChar endOfLine *>
many1 testParser
有什么想法可以解决这个问题吗?