Cam*_*tin 1 haskell attoparsec
假设我有一个attoparsec解析器,x.
我正在寻找创建一个函数f :: Int -> Parser a -> Parser a,如果y = f n x,然后:
y如果x失败则失败y如果x成功x则失败并且不消耗n字节y 否则就会成功我该怎么做呢?
您可以使用匹配来实现它:
f n x = do
(bs, res) <- match x
guard (BS.length bs >= n)
return res
Run Code Online (Sandbox Code Playgroud)
(<|>)在将其大量使用之前,您应该检查它是否以可接受的方式与之交互.