[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: PegDebug: trace debugger for LPeg
- From: Paul K <paul@...>
- Date: Wed, 24 Sep 2014 02:04:38 +0000
On Tue, Sep 23, 2014 at 5:54 PM, Daurnimator <quae@daurnimator.com> wrote:
> Check the rest of the arguments to your fold function :)
The fold function is not even called as there is only one capture.
local lpeg = require('lpeg')
local grammar = { "Sum";
Number = lpeg.R"09"^1 / tonumber;
List = lpeg.V("Number") * ("," * lpeg.V("Number"))^0
/ function(...) print(select('#', ...)) return ... end
;
Sum = lpeg.Cf(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"))
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?
Paul.