[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: adding match state to Lpeg
- From: Roberto Ierusalimschy <roberto@...>
- Date: Thu, 24 Jan 2008 18:04:45 -0200
> 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