lua-users home
lua-l archive

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

Each m.C is a single capture in LPeg. If you have nested captures, their values are returned after this one. The pseudocode below shows the order of captures, I named the first capture m.C as C1, second capture m.C as C2 and so on.

C1( C2('a') * C3( C4('b') * C5( C6('c') * C7( )  ) ) )

C1 -> abc
C2 -> a
C3 -> bc
C4 -> b
C5 -> c
C6 -> c
C7 -> ""

To understand the second example you just need to do the same thing.

2010/3/10 leeya <>
I read test.lua script from lpeg-0.9 and had a little confusion to code snippet below:
t = {m.match({[1] = m.C(m.C(1) * m.V(1) + -1)}, "abc")}
checkeq(t, {"abc", "a", "bc", "b", "c", "c", ""})
Who could give me some comments of above code? Why the output is {"abc", "a", "bc", "b", "c", "c", ""} sequence?
The same question was given as following too,
t = m.match(m.Ct(m.C(m.C(1) * 1 * m.C(1))), "alo")
checkeq(t, {"alo", "a", "o"}) 
Thanks a lot.

Marcelo Oikawa