lua-users home
lua-l archive

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

I'm testing out some ideas using lpeg-list and was wondering how one
could express a recursive search through nested tables.  Using lpeg to
search through a string is pretty straightforward using

(patt + P(1))^0

This works equally well for lists, but doesn't work at all for nested
lists.  For example, I was trying to see how to generalize this

local patt = L"one" * L(L"one" * L(L"one"))

It matches this:

local code = {"one", {"one", {"one"}, }, }

Now let's say I have:

local code = {"something", {"something", {"one"}, }, }

How can I express a recursive search through nested tables to find the
list containing "one"?  My first attempt was:

(patt + L( (patt + P(1))^1 ) + P(1))^0

This only goes one level deep and I need it to exhaustively recurse.
Any ideas on how to do this?