Re:Don't Panic! Better, Fewer, Syntax Errors for LR Parsers
by ltratt on Thursday July 16, 2020 @03:26AM
(#23856671)
I think we are in agreement that skipping over large chunks of input is rarely a good idea. In Section 7 ("Using error recovery in practice") we show how you can make fine-grained decisions about what to do when recovery has happened in our Rust parsing system. The more fine-grained you go, the more code you have to write, but it allows you to do exactly the sorts of things that rustc does with structs if you want. https://softdevteam.github.io/grmtools/master/book/errorreco... is a more approachable version of the same stuff.
Beyond the parser, the AST needs to keep around a lot of extra information for error recovery that would otherwise not be needed. An example from rustc[1] (what I'm familiar with) is structs and struct variants that have had some parse error. We recover the parse and keep a node for the variant in the AST signaling the existence of a parse error, which means that later passes of the compiler can type and borrow check, but if it finds a use that is either missing or adding fields we do not emit an error for it[2][3] under the assumption that the parse error caused the field being used to not be captured in the AST node for the variant. This can have quite dramatic impact on the quantity of errors being emitted.
[1]: https://github.com/rust-lang/rust/blob/7e11379f3b4c376fbb9a6...
[2]: https://github.com/rust-lang/rust/blob/7e11379f3b4c376fbb9a6...
[3]: https://github.com/rust-lang/rust/blob/7e11379f3b4c376fbb9a6...