[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Distinguishing LPeg match failure reasons
- From: Wesley Smith <wesley.hoke@...>
- Date: Tue, 30 Aug 2011 14:07:00 +0000
> I think I need a way to detect that lpeg tried to match beyond the end of
> the string. If it did (and I did not add lpeg.P(-1) at the end of the main
> rule) then I know that it failed because of too little data.
>
> The problem with most "normal" solutions is that I after a match failure the
> capture is immediately unwound and I do not know anything about it. If I add
> an alternative then it will start from the beginning and a pattern
> concatenation will never be reached when something failes before it.
Hi,
You may find codepeg useful. I made it specifically for this kind of
application. The codepeg parser keeps track of what tokens and rules
have been matched so that when a parsing error occurs, you can use the
stack of tokens and rules to generate good error messages:
https://github.com/weshoke/codepeg
wes