lua-users home
lua-l archive

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


> I also have a suggestion for Lpeg, an optional parameter to match, a Lua
> object that gets passed as the first argument in any function captures, if
> present:
> 
> lpeg.match(expression, subject, idx, state)
> 
> If state is nil the function captures receive only the captures, as usual.
> This lets you write Lpeg parsers that have match-local state, instead of
> having to fake this with closures. It is specially useful with re-based
> parsers.

The next version of Lpeg has a somewhat similar mechanism: the so-called
argument capture. lpeg.Carg(i) captures the value of the i-th extra
argument passed to lpeg.match. This captured value can be used like any
other captured value (in particular, as an argument to an enclosing
function capture).

-- Roberto