lua-users home
lua-l archive

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




On Tuesday, May 13, 2014, Dirk Laurie <dirk.laurie@gmail.com> wrote:
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.


I read through your document. I like the idea of a promise to refrain from editing, once you're smarter. :)

I use Cg with Ct and Cb every now-and-again. I was speaking more to anonymous version and the meaning of "grouping the values of multiple captures into a single capture" and what it's good for.

-Andrew