Say I have an attoparsec parser, x
.
I am looking to create a function f :: Int -> Parser a -> Parser a
, such that if y = f n x
, then:
y
fails if x
failsy
fails if x
succeeds and x
does not consume n
bytesy
succeeds otherwiseHow would I go about doing this?
You can use match to implement it:
f n x = do
(bs, res) <- match x
guard (BS.length bs >= n)
return res
You should check that this interacts with (<|>)
in an acceptable way before putting it to heavy use.