[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: how to translate lua pattern "(.*)and(.*)" with lpeg re ?
- From: Albert Chan <albertmcchan@...>
- Date: Mon, 22 Jan 2018 12:56:03 -0500
> On Jan 22, 2018, at 12:33 PM, Sean Conner <sean@conman.org> wrote:
>
> It was thus said that the Great albertmcchan once stated:
>> during testing, lpeg backtracking can only handle max string length of 199:
>> is this a lpeg bug ? only 199 chars limit ?
>
> Nope. It's documented. From the LPeg documentation:
>
> lpeg.setmaxstack (max)
>
> Sets a limit for the size of the backtrack stack used by
> LPeg to track calls and choices. (The default limit is 400.)
> Most well-written patterns need little backtrack levels and
> therefore you seldom need to change this limit; before
> changing it you should try to rewrite your pattern to avoid
> the need for extra space. Nevertheless, a few useful
> patterns may overflow. Also, with recursive grammars,
> subjects with deep recursion may also need larger limits.
>
> And this is exactly what you are hitting:
>
> lua: a.lua:18: backtrack stack overflow (current limit is 400)
but my example only need 4 backtracks, not 400 !
And it never say anything about max string length of 199
pat = re.compile "{g <- .g / &'and'} 'and' {.*}"
str = 'and*'
= pat:match( str:rep(50) ) -- string length = 4 * 50 = 200
backtrack stack overflow (current limit is 400)