Parsers generated by my "Mouse" have built-in error diagnostics, showing
the failure position farthset down the input, as suggested below. You
can do some tailoring of the messages, as described in Sections 14 and
18.6 of the manual at
http://mousepeg.sourceforge.net/Manual.pdf.
Section 17of the manual shows how to continue after an error in order to
possibly detect more. This of course requires that the text has
well-defined restart points, such as statement end.
The generator is available from http://sourceforge.net/projects/mousepeg .
On 2013-11-21 11:20, Orlando Hill wrote:
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
<mailto: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 <mailto: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
_______________________________________________
PEG mailing list
PEG@lists.csail.mit.edu
https://lists.csail.mit.edu/mailman/listinfo/peg