[Haskell-cafe] parsec: parserFail & multiple error messages

Antoine Latter aslatter at gmail.com
Thu Aug 9 05:28:52 CEST 2012


On Wed, Aug 8, 2012 at 8:26 PM, silly8888 <silly8888 at gmail.com> wrote:
> Inserting a character into the stream can be expensive if for example
> the stream is a ByteString.
> I tried the following crazy solution and it seems that it works:
>
> succeed :: Parser ()
> succeed = mkPT $ \st ->
>     return $ Consumed $ return $ Ok () st $ unknownError st
>
> succeed is a parser that always succeeds without really consuming any
> input but it also resets the error state.
>

Because you're using the 'Consumed' constructor, you're also telling
parsec not the back-track if there any errors following this parsers.

This means that 'succeed >> failingParser' won't backtrack, even if
'failingParser' doesn't consume input.

Are you using your original parser within a larger parser? Are the
error messages also not great?

Antoine



More information about the Haskell-Cafe mailing list