[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lpeg.Cb bug (?) with repeated evaluation of group capture pattern
- From: Sean Conner <sean@...>
- Date: Tue, 13 Sep 2016 21:25:12 -0400
It was thus said that the Great Patrick Donnelly once stated:
> This is maybe relating to Sean Conner's recent post "Proposal for new
> LPeg function: lpeg.Ctab()".
No, this doesn't have anything to do with my proposal (although I did try
using lpeg.Cb() before posting).
> 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?
I don't know. It certainly is surprising. I wonder why it appears as if
lpeg.Ct() is being called each time lpeg.Cb() is called?
-spc