lua-users home
lua-l archive

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


On Oct 31, 2018, at 3:48 PM, Sean Conner <sean@conman.org> wrote:
>   
>  Because the pattern, the empty string, is being matched twice by the two
> calls.  If you change it to:
> 
>    patt = lpeg.P(lpeg.P(1) * fct)
> 
> it will work.

With this patt, the check for empty string in fct is not needed
Since P(fct) does not capture anything, argument capture is not needed.

patt is just a 1 liner:

patt = 1 * P(function(s, i) return i, s:sub(i-1, i-1) end)