
29 Aug
2006
29 Aug
'06
1:08 p.m.
Udo Stenzel wrote:
Stephane Bortzmeyer wrote:
Parsec provides "count n p" to run the parser p exactly n times. I'm looking for a combinator "countBetween m n p" which will run the parser between m and n times. It does not exist in Parsec.
infixr 2 <:> (<:>) = ap . ap (return (:))
Again, Parsec requires you to put "try" where you need it
countBetween 0 0 _ = return [] countBetween 0 n p = try p <:> countBetween 0 (n-1) p <|> return [] countBetween m n p = p <:> countBetween (m-1) (n-1) p
or what I'd ordinarily use:
(<:>) = liftM2 (:)