<forgot to CC the list before> --- Terence,
for error reporting parboiled applies this logic: 1. Determine error position (first input pos that cannot be parsed), if this is end-of-input we have no error and are done. 2. Restart the parser from the very beginning and “watch" the parser try to match the error position. Record all the rules (rule stacks) that are applied against the error position. From this list of rules we can construct proper error messages like: Invalid input 'x', expected 'f', Digit, hex or UpperAlpha (line 1, column 4): abcx ^ 4 rules mismatched at error location: targetRule / | / "fgh" / 'f' targetRule / | / Digit targetRule / | / hex targetRule / | / UpperAlpha Restarting the parser for gathering error info is acceptable in almost all use cases since errors are infrequent and added overhead here is not a problem. Error recovery: Here we have the following logic: 1. Try to “remove” the error position from the input and see whether the parser can continue. 2. If not, try to insert a single character that the parser “expects” (see reporting) at the error position. If this allows us to continue parsing, great. 3. If no single-char fix “repairs” the input we resynchronise the parser in a similar way that ANTLR does it (IIRC), i.e. we skip ahead in the input until the parser can continue. Cheers, Mathias --- math...@parboiled.org http://www.parboiled.org On 26 May 2014, at 17:38, Terence Parr <pa...@cs.usfca.edu> wrote: > Hi Mathias, Could you summarize quickly how it recovers and reports errors? I > think the basic strategy initially was to simply report an error at the token > following the deepest correctly matched token, but I don’t remember anything > about recovery. > > PEGs are so beautiful and simple it makes one proud to be a computer > scientist! I’ve heard reports however of people backing off to a more > traditional deterministic parser for reasons of side effecting action > execution during the parse and error recovery. For example, the xtext guys > tried to get away from ANTLR by building their own PEG based system but > error recovery and reporting gave them lots of trouble and so they returned > to ANTLR. > > Ter > On May 26, 2014, at 8:35 AM, Mathias Doenitz <math...@parboiled.org> wrote: > >> Terence, >> >> parboiled (http://parboiled.org, http://parboiled2.org) does what I’d >> consider good error reporting. >> The 1.x version also supports error recovery in a nice fashion. >> >> Cheers, >> Mathias >> >> --- >> math...@parboiled.org >> http://www.parboiled.org >> >> On 26 May 2014, at 17:30, Terence Parr <pa...@cs.usfca.edu> wrote: >> >>> Hi. Just curious. Has anyone figured out how to get good error reporting >>> and recovery in PEGs? I.e., competitive with deterministic parsers? >>> >>> Terence >>> >>> >>> _______________________________________________ >>> PEG mailing list >>> PEG@lists.csail.mit.edu >>> https://lists.csail.mit.edu/mailman/listinfo/peg >> > _______________________________________________ PEG mailing list PEG@lists.csail.mit.edu https://lists.csail.mit.edu/mailman/listinfo/peg