lua-users home
lua-l archive

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


>  I think I've come upon a bug or maybe I'm just violating a parsing
> precept here. I've distilled the issue down to the following simple
> snippet. Using LPeg 0.9
> 
> -----------------------------------
> local lp = require 'lpeg'
> 
> local xs = lp.C(lp.P('x')^1)
> local os = lp.C(lp.P('o')^1)
> local ps = lp.C(lp.P('p')^1)
> 
> local code = xs * os^-1 * ps
> local patt = code * (':' * code)^0
> 
> print(patt:match("xxxoopp:xxpp:xxxxooopp"))
> 
> -----------------------------------
> 
>  The idea is to capture each part of the code, with the 'o' part
> being optional.  With this snippet, I'm expecting the results:
> 
> xxx    oo    pp    xx    pp    xxxx    ooo    pp
> 
> but it stops at:
> 
> xxx    oo    pp    xx

This is a bug. This example works correctly both with version 0.8 and
version 0.10 (yet to be released). I guess the following patch in lpeg.c
should fix it:

82,84c82,84
<   /* IAny */		ISCHECK,
<   /* IChar */		ISCHECK,
<   /* ISet */		ISCHECK | HASCHARSET,
---
>   /* IAny */		ISCHECK | ISJMP,
>   /* IChar */		ISCHECK | ISJMP,
>   /* ISet */		ISCHECK | ISJMP | HASCHARSET,
128c128
< #define isjmp(op)	isprop(op, ISJMP)
---
> #define isjmp(op)	(isprop(op, ISJMP) && (op)->i.offset != 0)


-- Roberto