Hi Henri, One approach would be to keep track of the position of the error closest to the end of the string. Every time a character matching expression fails, if the failure position is greater or equal to the current best error position, then record what failed to be matched (character class, single character within a string, any character) and the context of the error (non-terminal name, user defined error string).
You might need to be careful when matching within PEG's positive and negative look-ahead expressions. You could look at a parser generated by PEG.js, for an example. The function peg$fail is the most relevant one. https://github.com/dmajda/pegjs/blob/master/lib/parser.js On Thu, Nov 21, 2013 at 1:15 PM, Henri Tuhola <henri.tuh...@gmail.com>wrote: > Hello > > How could I extend my simple parser generator such that parsers provide > error reports that show precisely what went wrong? > > I thought it was a nice idea to write myself a parser generator, > specifically tailored for the language I'm going to parse: > https://github.com/cheery/kickrat > > It was quite fun, clean and exciting to create such library but now I've > been prototyping my language for few hours. It was enough for noticing that > when I do an error in describing the grammar it is really hard to figure > out what's wrong with just plain 'syntax error' -message. Overall it would > be nice to get detailed syntax errors for language, even if it's a > prototype. > > _______________________________________________ > 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