lua-users home
lua-l archive

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


There seems to be a bug in lpeglist whereby the repetition patterns
patt^N when the subject is tables behaves differently than when the
subject is strings.  A test script is below and produces the following
output:

3
5
5
-----------------------------------------
3
3  <---- should be 5
2  <---- should be 5


Basically, the last P(1)^1 aborts after the first match instead of
matching agains 1 or more elements when matching against tables.  I'm
using the latest version from the git repo.





local listlpeg = require("listlpeg")
local P = listlpeg.P
local L = listlpeg.L
local C = listlpeg.C
local Cmt = listlpeg.Cmt

-----------------------------------------
-- test string array
local t1 = {
	"A", "B", "C", "D"
}

print("-----------------------------------------")
local patt = P"A" * P"B"
print(patt:match(t1))

local patt = P"A" * P(1)^1
print(patt:match(t1))

local patt = P(1)^1
print(patt:match(t1))


-----------------------------------------
-- test table array
local t2 = {
	{ val = "A"}, { val = "B" }, { val = "C" }, { val = "D" }
}

local
function Pval(name)
	return Cmt(C(1), function(s, i, t)
		--print("Pval", i, t.val, name)
		return t.val == name
	end)
end

print("-----------------------------------------")

local patt = Pval"A" * Pval"B"
print(patt:match(t2))

local patt = Pval"A" * P(1)^1
print(patt:match(t2))

local patt = P(1)^1
print(patt:match(t2))

--[[
local patt = Pval"A" * Pval"B" * P(1)
print(patt:match(t2))

local patt = Pval"A" * P(1)^0
print(patt:match(t2))
--]]