lua-users home
lua-l archive

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


2013/6/5 Roberto Ierusalimschy <roberto@inf.puc-rio.br>:
>> The attached module (a JSON parser) works fine with LPeg 0.10.2.
>> After a upgrade to LPeg 0.12, an error occurs at load time :
>>         $ lua -e "print(require'parser_peg'.parse'{}')"
>>         lua: ./parser_peg.lua:61: empty loop in rule 'object'
>
> The problem is related to a match-time capture (Cmt).  You have a
> loop over a Cmt pattern. LPeg has no way to know whether such pattern
> consumes any input. Older versions of LPeg were "optimistic" in those
> cases, and blindly assumed that the pattern consumes something (and
> therefore that the loop is valid). The new version is more strict and
> refuses such loops.
>
> The correction involves making the pattern associated with the Cmt
> non empty. In your case, the problem seems to be this loop:
>
>           ((V'value_separator'
>           + Cmt(Cp() * -V'end_object', function (s, pos)
>                                           error("',' expected at " .. pos)
>                                        end))
>          * V'member')^0
>
> A simple solution is this:
>
>           ((V'value_separator'
>           + Cmt(Cp() * -V'end_object', function (s, pos)
>                                           error("',' expected at " .. pos)
>                                        end) * 1)     --<<<<<<<
>          * V'member')^0
>
> The "* 1" after the error does not affect the matching, but it tells
> LPeg that the pattern cannot accept an empty string.
>
> (You will have a similar problem in rule 'array', with a similar
> solution.)
>
> -- Roberto

Many thanks.

François

>