lua-users home
lua-l archive

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


On Wed, 16 Aug 2023 at 15:32, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>
> > [...] my priority now is to
> > understand some obscure features and corner cases...
>
> Would you mind repeating what exactly you are not understanding?
> (No graphs, please. :-)
>
> -- Roberto

Hi Roberto,

Mainly "last complete outermost group capture" and "immediate
evaluation of all its nested captures", in:

  lpeg.Cb (name)

  Creates a back capture. This pattern matches the empty string and
  produces the values produced by the most recent group capture named
  name (where name can be any Lua value).

  Most recent means the last complete outermost group capture with the
  given name. A Complete capture means that the entire pattern
  corresponding to the capture has matched. An Outermost capture means
  that the capture is not inside another complete capture.

  In the same way that LPeg does not specify when it evaluates
  captures, it does not specify whether it reuses values previously
  produced by the group or re-evaluates them.

  lpeg.Cmt(patt, function)

  Creates a match-time capture. Unlike all other captures, this one is
  evaluated immediately when a match occurs (even if it is part of a
  larger pattern that fails later). It forces the immediate evaluation
  of all its nested captures and then calls function.

Cheers =/,
  E.