lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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
> patterns.
> 
> Are there any good techniques for handling this in a sensible way?

Hello,

I've presented my approach to LPeg error handling here:
<http://lua-users.org/lists/lua-l/2012-01/msg00012.html>

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
<http://dkolf.de/src/dkjson-lua.fsl/>.

Best regards,

David Kolf