Skip to content

Cannot make recover_with(via_parser(…)) work #609

Answered by zesterer
soywod asked this question in Q&A
Discussion options

You must be logged in to vote

The result here is both expected and correct: parser recovery doesn't mean that the error in the first branch (just("abc")) gets swallowed, it just means that an error gets emitted and then parsing continues, using the recovery strategy to 'fill the whole', as it were.

If you check out the docs for ParseResult, you'll see that it's possible for a parser to both produce a valid output and emit errors at the same time. This is what is happening here. recover_with(via_parser(...)) should only be used to recover from errors.

If both patterns are considered valid syntax, then choice/or are the thing to use (both do the same thing internally).

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by soywod
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants