-
Let's say that I have this parser: it either parses a function definition or an expression. let fn_ = keyword("fn").padded()
.ignore_then(ident_)
.then(args)
.then(fn_body);
choice((
fn_,
expr,
)) How do I prevent my parser from falling back to expression parsing after it has encountered a Nom has a Why do I need this? If there was a problem with function arguments I want to see the error there instead of an error due it my parser failing to parse an expression. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello,
Chumsky will automatically prioritise error branches that make the most progress into the input. This means that if the parser sees The exact mechanism for this is kept as an implementation detail (there are some future changes we might be able to do to improve error prioritisation even further), but the parser will already exhibit the behaviour you're looking for without any extra combinators :) |
Beta Was this translation helpful? Give feedback.
Hello,
Chumsky will automatically prioritise error branches that make the most progress into the input. This means that if the parser sees
fn <malformed>
, the error you will see will be that generated by thefn_
parser (unless, of course, theexpr
parser contains some syntax rule that can parse thefn
too).The exact mechanism for this is kept as an implementation detail (there are some future changes we might be able to do to improve error prioritisation even further), but the parser will already exhibit the behaviour you're looking for witho…