lua-users home
lua-l archive

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


> The description of lpeg.Cb():
> 
>         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.
> 
> seems to indicate that indeed, the use of lpeg.Cg() within the context of
> lpeg.Cs() means it is ignored when using lpeg.Cb() to retrieve the value (if
> I read everything right), and that even using lpeg.Cmt() (which forces
> evaluations of all captures at that time) won't work either.

If I understand you correctly, I guess the answer to your question
is the definition of Outermost capture:

    An Outermost capture means that the capture is not inside another
    complete capture.

So, if a group capture is inside lpeg.Cs() (or any other capture!), it is
not an outermost capture. Therefore, it is not considered as "the most
recent group capture named name".

(Informally, Cb and Cg must be sibblings; Cb cannot be an uncle of Cg.)

-- Roberto