lua-users home
lua-l archive

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


On Thu, Aug 28, 2014 at 11:42 PM, Paul K <paul@zerobrane.com> wrote:
> Hi All,
>
> I have this small issue with an LPEG capture pattern I'm working with
> and hope someone can explain what may be going on. I'm missing
> something simple here, but I can't figure out why I only get one
> capture with the following:
>
> lpeg.match(((lpeg.Cp() * lpeg.R('04')) / print)^1, "4123")
>
> This prints 1 2 3 4 (four lines), which is what the positions of the
> matches are. If I remove Cp, I get 4 1 2 3 (four lines), which is what
> I expect. Why don't I get
> 1 4
> 2 1
> 3 2
> 4 3
> from the first example? I expect "print" to get "all captures made by
> patt as arguments", which are 1 (from Cp) and 4 from R('04'), no?
> Thank you.
>
> Paul.
>

I'm not sure but I think you are currently matching the range of
characters "lpeg.R('04')" but not capturing them?  lpeg isn't
available through homebrew and I don't feel like going through the
work of installing it :(

try this?  lpeg.match(((lpeg.Cp() * lpeg.C(lpeg.R('04'))) / print)^1, "4123")