lua-users home
lua-l archive

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

On Tue, Jun 19, 2012 at 8:21 PM, Patrick Donnelly <> wrote:
> I think you're overthinking this (you shouldn't need match-time captures). Try:
> function power (patt, n)
>  local p = lpeg.P(true)
>  for i = 1, n do
>    p = p * patt
>  end
>  return p
> end

An LPEG pattern is a sequence of instructions for a special virtual
machine. Your approach of doing powers results in much longer
programs, whereas the match-time capture approach doesn't. For trivial
patterns, the LPEG optimiser might be able to turn these longer
programs into short ones, but program length will become an issue for
high powers of non-trivial patterns.