[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Error handling/recovery in LPEG?
- From: David Heiko Kolf <david@...>
- Date: Sat, 09 Nov 2013 17:43:19 +0100
David Given wrote:
> I want to write a non-trivial grammar in, hopefully, LPEG. The big
> stumbling block I can see is that handling incorrect input files appears
> to be quite hard in LPEG --- the grammar will just fail to match, rather
> than producing a diagnostic, recovering, and continuing to parse.
> I've seen some references on the mailing list to a few techniques for
> doing error handling, which basically boil down to having a grammar
> which can stop matching before the end of the file; by looking to see
> how much of the grammar matched, you can tell where it failed. But that
> doesn't really work for me, because I'm going to have some deeply nested
> Are there any good techniques for handling this in a sensible way?
I've presented my approach to LPeg error handling here:
This allows you to specify an error message right in the grammar and it
returns the exact position in nested grammars. Just be aware that there
was a small mistake in the code sample, the variable "linepos" should be
initialized to 0. The current version that I am using is at