> On 20. May 2017, at 17:00, Juancarlo Añez <apal...@gmail.com> wrote:
> 
> What has been done about parser recovery over quasi-valid input in PEG?

That probably depends on the language you are defining. We recently 
experimented with some convenience rules that you can use in your grammar if 
parts of the grammar have clear terminators, e.g. end-of-line, a semicolon, a 
closing bracket, etc.

Our library is the PEGTL, we recently release version 2.0.0: 
<https://github.com/taocpp/PEGTL>.

The example for error recovery can be found in: 
<https://github.com/taocpp/PEGTL/blob/949a5796e5a54c75ce9a6d48f7b11b92f1defbf8/src/example/pegtl/recover.cpp>

The core idea is to have a grammar rule R which defines the content of a 
section, while a rule T defines the terminator for that section. We than have a 
rule template 'recoverable<R,T>' which tries to parse a sequence of R and T. If 
that fails, it skips over the input until it can parse T, calling an action for 
the skipped part of the input to allow error reporting/recording, then 
continues after T. You can use recoverable<R,T> multiple times in your grammar 
to allow as-local-as-possible recovery. We haven't used it in practice, though.

Daniel


_______________________________________________
PEG mailing list
PEG@lists.csail.mit.edu
https://lists.csail.mit.edu/mailman/listinfo/peg

Reply via email to