zesterer / chumsky

Write expressive, high-performance parsers with ease.
https://crates.io/crates/chumsky
MIT License
3.61k stars 155 forks source link

Missing documentation with example of the recovery system #42

Open bew opened 2 years ago

bew commented 2 years ago

AFAIK there's not a lot of documentation (except few lines), nor examples on how to use the recovery module and the parse_recovery_* functions https://docs.rs/chumsky/latest/chumsky/recovery/index.html

Especially on the functions nested_delimiters skip_then_retry_until skip_until

spencerpogo commented 2 years ago

Adding on, it would also be nice to see an example of how to construct a partial syntax tree with Error nodes like in the README screenshot. It seems like none of the current examples do this and it is crucial to having a good IDE experience

zesterer commented 2 years ago

Currently, the following examples do parser error recovery:

There is also documentation on Parser::recover_with, the main method used to invoke recovery.

It's true that this is somewhat hard to find though: the recovery module docs should probably point to it and give a little overview of the various recovery options available.

spencerpogo commented 2 years ago

nested_delimiters works great but I'm not sure to how apply the other strategies. For example, say I have a statement parser that is separtated_by(Semicolon). How could I recover valid statements with syntax errors in-between? Or, at least recover statements before a syntax error?

zesterer commented 2 years ago

How could I recover valid statements with syntax errors in-between?

skip_until will probably serve your needs.

I'm intending to refactor the recovery system when zero-copy merged to make it more flexible and easier to work with.