lua-users home
lua-l archive

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


Op Wo., 31 Okt. 2018 om 23:16 het Albert Chan <albertmcchan@yahoo.com> geskryf:
>
>
> On Oct 31, 2018, at 3:48 PM, Sean Conner <sean@conman.org> wrote:
> >
> >  Because the pattern, the empty string, is being matched twice by the two
> > calls.  If you change it to:
> >
> >    patt = lpeg.P(lpeg.P(1) * fct)
> >
> > it will work.
>
> With this patt, the check for empty string in fct is not needed
> Since P(fct) does not capture anything, argument capture is not needed.

I'll be using P(fct)/action in the application, which translates a
script to Lua.

> patt is just a 1 liner:
>
> patt = 1 * P(function(s, i) return i, s:sub(i-1, i-1) end)

This is a toy pattern, illustrating the problem I had at first, which
Sean has cleared up for me. The actual pattern I wish to capture is
based on a Lua pattern involving "%b", which in LPEG requires
techniques I have not mastered.