Errors and Ors #30
Replies: 4 comments 1 reply
-
The purpose of The precise way errors emitted by each of the parsers is handled is left unspecified (because there is room for improvement in the future), but the important details are:
When multiple parsers in the chain fail, Chumsky has a series of internal heuristics for determining which errors should be emitted. Generally speaking, we try to emit the error(s) that would be 'most useful' to the user.
Chumsky already does this (along with a few other things). |
Beta Was this translation helpful? Give feedback.
-
Oh interesting! I'll need to check then to see why my parsers aren't creating any errors when they fail to parse. Will a "Just" parser create an error if it doesn't get the right token, or do you need to use map_err or filter_map to make an error in all cases? |
Beta Was this translation helpful? Give feedback.
-
If your parser is not producing an output (i.e: |
Beta Was this translation helpful? Give feedback.
-
When my parsers are failing on invalid input right now, they are producing So it's not I'm very sure I'm doing something wrong; I'm both new to Rust and new to creating programming languages. I'd be happy to show you what I'm trying, it's in a private repo right now but I'll add you to it. |
Beta Was this translation helpful? Give feedback.
-
Let me know if I'm misunderstanding something major, or need to review the examples better.
My understanding of "or" parsers is that they stop errors from propagating. For example, if you have a chain of parsers like parser1.or(parser2).or(parser3), and you create an error in parser1, it will not be collected with your other parser errors. This makes sense, because an error with parser1 is an indication that you should try parser2.
The problem this causes is if all of your parsers are combined in a large "or" chain (which I think is typical in any non-trivial parser) then very few parser errors actually create an error. So if parser1, 2, and 3 all fail, then you don't get any errors at all. (it just doesn't parse)
If I'm understanding this correctly then I have a proposal: Propagate the error for whichever parser in the chain consumed the most tokens before finding an error. So if Parser1 consumes 3 tokens before an error, Parser2 1 token, and Parser3 0 tokens, then it would collect the error from the first parser.
Beta Was this translation helpful? Give feedback.
All reactions