Parsec's satisfy equivalent in uu-parsinglib

94 views Asked by At

I am looking for a satisfy function like the one Parsec has. Something like:

--The parser satisfy f succeeds for any character for which the supplied
--function f returns True.
--Returns the character that is actually parsed.
satisfy :: (Char -> Bool) -> Parser Char

The only thing I have found is pSatisfy, which requires an Insertion as argument. I don't understand why this is necessary... I just want the parser to fail in case the predicate is not satisfied!

How can I achieve this?

1

There are 1 answers

0
aochagavia On BEST ANSWER

Finally I managed to hack up a satisfy function which meeted my needs. However, uu-parsinglib is an error correcting parser and will throw an exception in case you don't provide a correcting alternative.

This means you should use the normal pSatisfy function and provide an Insertion element. If you are not sure about what the cost should be you can use 5, as seen in the implementations of other parsers like pSymbol.