[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: LPeg and function capture
- From: Philippe Lhoste <PhiLho@...>
- Date: Mon, 21 May 2012 07:00:00 +0200
On 20/05/2012 16:11, Roberto Ierusalimschy wrote:
But the following doesn't, the function gets all chars, not only the
capital ones (those supposed to be captured):
local patt = (findCap / function (a) return string.lower(a) end)^0
Why the behavior of the pattern is changed by the associated function?
In all cases, the function is called once everytime there is a match.
Aah, that's something that totally escaped me when reading the
description of the function capture.
In the second case, there is match for each character (because of the
(1 - cap) in 'findCap').
When the pattern of a function capture
produces no captures, the entire match is given as the captured value.
Maybe this is what you whant:
local findCap = (1 - cap) + m.C(cap) / string.lower
Now the function is called only when 'm.C(cap)' matches.
Ah, yes, the final pattern would then be:
local patt = ((1 - cap) + m.C(cap) / string.lower)^0
I understand the nuance now, thanks!
-- (near) Paris -- France
-- -- -- -- -- -- -- -- -- -- -- -- -- --