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

Now if I remove the capture for the optional 'o' part, I get expected results:

xxx    pp    xx    pp    xxxx    pp

Also, if I change the code definition line to read:

local code = xs * os^-1 * ps^0

then I get the results that I'd originally expected. The ps pattern matches here when it's allowed not to.

Thanks for any feedback,

Jon