lua-users home
lua-l archive

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


2014-05-14 2:40 GMT+02:00 Andrew Starks <andrew.starks@trms.com>:

> I don't have my mind around this, but I'm trying...
>
> Is it something like: "these are still individual captures, but for the
> purposes of numbering, they're grouped, which makes it possible to specify a
> subset of captures from a set."

### Group and back captures

These patterns are useless by themselves. They are always used as
part of a bigger pattern.

The first version of this document said: "The remaining capture
functions: `Cg` and `Cb`, are definitely too advanced for this primer."
That is still basically true, but one application is within reach:
the Group-Back combination allows values to be stored and retrieved.

__`Cg(p,name), p:Cg(name)`__ (Group)
~   Collects all the captures `p` made into a single entity, and gives
    that entity a name for future reference. Does not actually add any
    captured values to the big pattern.

__`Cb(name)`__   (Back)
~   Retrieves the entity with the given name, and supplies
    its captures to the big pattern.

> An example in the LPeg doc or a clarifying disclaimer would have been
> appreciated, but your answer is great too!

The above quote is from
<https://github.com/dlaurie/lua-notes/blob/master/lpeg-brief.txt>
which explains LPeg from the point of a newbie who has just reached
the point where things start to make sense.