lua-users home
lua-l archive

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



On Oct 31, 2018, at 4:43 PM, Sean Conner <sean@conman.org> wrote:
> 
>> patt=lpeg.P(fct)
>> (patt^-4):match"abc"  --> a b c [as expected, no fourth value]
>> 
>> But:
>> (patt^0):match"abc" --> stdin:1: loop body may accept empty string
>> 
>> I don't understand why I get that.
> 
>  I don't either.  When I get that error, I start making changes to the code
> until the error goes away and the code does what I want.  You could try:
> 
>    (patt^1):match"abc" + lpeg.Cc(false)
> 
>  -spc

that were a lpeg safety feature, by checking fixedlen(patt) > 0
Since patt = P(fct) is matching pattern "", fixedlen = 0

All this check is to avoid patt^n get into infinite loops.

P(fct) does not know fct will skip forward.
To be safe, lpeg assumed no skipping.
To be double safe, P(fct) is not allowed to go "backward".

patt^1 + Cc(false) will not compile. 
Possible infinite loop situation remained.