【发布时间】:2014-07-10 10:16:05
【问题描述】:
我的类型:
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
有解决这个问题的想法吗?
【问题讨论】:
-
顺便说一下,你在
Test和Link之间切换。 -
@Zeta 抱歉,这是我的错误。更新为
Test。 (我原来的数据结构实际上是Link,它有更多的字段。我只是为了这个问题将它简化为Test。)
标签: haskell attoparsec haskell-pipes