It was thus said that the Great 'Scott Morgan' via lua-l once stated:
Yes you are (and it's a nice bit of code---certainly better than what I
came up with). I modified the code a bit to show you what's going on:
Pi = function(pat)
local lpat = pat:lower()
local len = pat:len()
return Cmt(P(len), function(subj, pos)
print(">>>",subj,pos)
return subj:lower() == lpat and pos
end)
end
foo = P"aaa "
bar = foo * Pi"test" * P"="
print(bar:match "aaa test=")
>>> aaa test= 9
nil
The subj parameter of Cmt() gets the entire string you are matching, not
just what P(len) returns. Instead, if you change the function to:
Pi = function(pat)
local lpat = pat:lower()
local len = pat:len()
return Cmt(P(len), function(subj, pos, capture)
print(">>>",subj,pos,capture)
return capture:lower() == lpat and pos
end)
end
>>> aaa test= 9 test
10
it works as intended. Despite the wording of the description of Cmt():
The given function gets as arguments the entire subject, the current
position (after the match of patt), plus any capture values produced
by patt.
you don't actually have to explicitly capture values in the pattern.
-spc