|
The fold function is not even called as there is only one capture.
I slightly modified the example to add print("folding"...). If I
comment out the function capture, everything works; if it's
uncommented, then the fold function is not called. Am I missing
something?
local lpeg = require('lpeg')local grammar = { "Sum";Number = lpeg.R"09"^1 / tonumber;List = lpeg.V("Number") * ("," * lpeg.V("Number"))^0/ function(...) print("S",select('#', ...)) return ... end;Sum = lpeg.Cf(lpeg.Cc(0)*lpeg.V("List"),function(acc, newvalue, ...) print("folding", acc, newvalue, ...)return newvalue and acc + newvalue end);}print(lpeg.match(lpeg.P(grammar),"10,30,43"))
S 3
folding 0 10 30 43
10
local lpeg = require('lpeg')local grammar = { "Sum";Number = lpeg.R"09"^1 / tonumber;List = lpeg.V("Number") * ("," * lpeg.V("Number"))^0 ;Sum = lpeg.Cf(lpeg.Cc(0)*lpeg.V("List"),function(acc, newvalue, ...) print("folding", acc, newvalue, ...)return newvalue and acc + newvalue end);}print(lpeg.match(lpeg.P(grammar),"10,30,43"))
folding 0 10folding 10 30folding 40 4383