Hello Roman, In section 17 of http://mousepeg.sourceforge.net/Manual.pdf > I give an example of using PEG itself to re-synchronize the parse after an > error. > However, it may be not what you ask for. > That solution consists on manually adding recovery rules. I think that’s the way to go (as opposed to blind, automated recovery).
Daniel mentioned that in PEGTL there is support in the grammar syntax for recovery rules. I like that because by marking recovery rules or expressions the parsers can provide special book-keeping (so a recovered parse is not confused with a parse of valid input), warn about the recovery, etc. ANTLR does a thorough analysis of the grammar (more than LL) to choose the most efficient strategy, and I’m almost certain it uses the information for automated recovery. TatSu calculates a quasi-LOOKAHEAD set only for the purpose of “expected *such*“ messages, and that could be refined to provide automated recovery by skipping to a token expected by one of the rules in the parse stack. But I’ve seen blind, automated recovery at work (Microsoft and Apple compilers do it) and the result is a myriad of useless messages. Choosing where and how to recover on a particular grammar seems more reasonable. BTW One of the first parser implementations I studied was the pone for *PL/0* in one of the last chapters of the Algorithms+Data Structures=Programs <https://www.amazon.com/Algorithms-Structures-Prentice-Hall-Automatic-Computation/dp/0130224189/> book by N. Wirth. It implemented *hand-crafted+=automated* recovery by parametrizing each rule with the tokens to seek when recovering from failure. That could be a strategy useable with PEG. (BTW, I think Wirth’s parser was PEG) Cheers! -- Juancarlo *Añez*
_______________________________________________ PEG mailing list PEG@lists.csail.mit.edu https://lists.csail.mit.edu/mailman/listinfo/peg