-
Sorry if the question sounds stupid, but I cannot figure out how the let parser =
just::<_, _, extra::Err<Rich<char>>>("abc").recover_with(via_parser(just("abd")));
assert_eq!(parser.parse("abd").into_result().unwrap(), "abd"); which outputs:
I naively expect To give more context, I try to parse either a parser 1 or a parser 2, and both contain similar keywords. Knowing that chumsky is a PEG, a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The result here is both expected and correct: parser recovery doesn't mean that the error in the first branch ( If you check out the docs for If both patterns are considered valid syntax, then |
Beta Was this translation helpful? Give feedback.
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).