lua-users home
lua-l archive

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


On Sun, Apr 22, 2012 at 8:28 PM, Miles Bader <miles@gnu.org> wrote:
> So I'm thinking:  How hard would it be to have some sort of "flush"
> operator in LPEG, that basically says "act as if this pattern and all
> enclosing patterns successfully matched insofar as required to reclaim
> all memory used to store captures or whatever.
>
> E.g. the above grammar would be changed to something like:
>
>   pattern = lpeg.P"begin" * lpeg.flush(ONE_STATEMENT)^0 * lpeg.P"end"
>   final_pos = pattern:match(string, pos)

This sounds like you could use a match-time capture (with an identity function):

function (...) return ... end

Unfortunately I don't think the cleanup in lpeg is handled perfectly
yet such that a failed pattern match (wrapped with lpeg.Cmt) will
leave some stuff on the stack unnecessarily. I think Roberto is
planning on correcting that if he hasn't already.

-- 
- Patrick Donnelly