lua-users home
lua-l archive

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


> I have been fascinated by Lpeg. One thing, though, that I have
> found difficult is how to use Lpeg in a way that reports
> useful error messages when a pattern fails. I would like to see
> some educational recipes that cope with this.
> When lpeg.match succeeds on its arguments it may return all
> sorts of non-nil values, depending on what capture facilities
> the pattern-argument has been endowed with. But when it fails
> it returns nil. What else does it return after the nil? It
> would be useful for error handling if as much of the lpeg-vm
> state as possible was also returned. The manual does not say
> anything about this as far as I can see.

You may have a look at the "re" module (for version 0.8). My technique
was to provide extra alternatives in specific places, which match
anything as long as nothing else match (that is, an error). Look for
"patt_error".

-- Roberto