Would it make sense to add a way to tell LPEG "do not backtrack past
this point" – e.g. by 'lpeg.cut( )'? (I'm taking the name from Prolog –
maybe there's a better name?) With cuts, there *would* be hard known
information that could be printed: The position in the input when LPEG
attempted to backtrack over the cut.
Going a step further, `lpeg.cut( [name] )` could (maybe) be used to
produce something like a stack trace? (I haven't looked at the LPEG
internals, don't know how hard/easy this would be.)
With cut, I could have
entity = lpeg.P "<entity" * WS^1 * lpeg.cut( "tag:entity" ) * "id=" …
and then LPEG has enough information to tell me that in 'tag:entity' at
position 12345 (in 'tag:state' at position 123 in 'tag:savegame' at
position 10) no alternative matched, and by using the position I can
grab the next couple of lexemes (or bytes) from the file, and then I
know that there was 'ref=' instead of 'id=' and debugging would be *so*
much easier.
At least that's the dream… Would that actually work? And is this
sufficiently compatible with LPEG's internals? Or is that maybe
possible already?