lua-users home
lua-l archive

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


This is maybe relating to Sean Conner's recent post "Proposal for new
LPeg function: lpeg.Ctab()".

I found that for some reason LPeg is evaluating a pattern in a group
capture multiple times:

local patt = lpeg.Cg(lpeg.Ct"", "foo") * lpeg.Cb "foo" * lpeg.Cb "foo";
print(patt:match "") --> table: 0x1634280        table: 0x16342c0

(two unique tables!) Or:

local patt = lpeg.P {
    lpeg.Cg(lpeg.V "v", "foo") * lpeg.Cb "foo" * lpeg.Cb "foo";
    v = lpeg.Ct "" / function(...) print(...) return ... end,
}
print(patt:match "") --> table: 0x233d4a0 \n table: 0x22f0ab0 \n
table: 0x233d4a0        table: 0x22f0ab0

Whereas:

local patt = lpeg.Cg(lpeg.Cmt("", function(s,p) return p, {} end),
"foo") * lpeg.Cb "foo" * lpeg.Cb "foo";
print(patt:match "") --> table: 0x87a950 table: 0x87a950

(one table!)

Is this a bug?

-- 
Patrick Donnelly