Re: Matching a fixed number of repetitions in LPeG
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Matching a fixed number of repetitions in LPeG
- From: Peter Cawley <lua@...>
- Date: 2012年6月19日 20:39:32 +0100
On Tue, Jun 19, 2012 at 8:21 PM, Patrick Donnelly <batrick@batbytes.com> 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.