lua-users home
lua-l archive

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

I'm trying to understand the motivating design behind lpeg's captures
(for my Python port of the library). The basic capture mechanism is
fairly straightforward - I follow the mechanics of what's going on,
and with a little thought, the intent behind the capture process
clicked for me (or at least, *an* intent which made sense to me - I
don't want to presume to know Roberto's original thoughts!)

However, I'm still a little unclear on the reasoning behind match-time
captures. There is only one example (Lua long strings) in the
documentation, and I've not found many others on the web. The code
required to implement match-time captures is non-trivial, so I have to
assume that it was worth the effort to implement, but I'm not entirely
sure why.

It seems to me that the point of match-time captures is to allow
matching of constructions which would not otherwise be expressible
with a "pure" PEG. Is that fair? If so, then (1) why is this
particular form of non-pure construct more useful than any other, and
(b) isn't this the same sort of compromise that led from regular
expressions to the non-regular languages that we have today under that
name? If it's not the case, then what is the reason for having
match-time captures?

Can anyone help me with a really strong motivating example of why Cmt
is important enough to have earned its place as the one exceptional
case in lpeg?

(On a related note, are there any papers available on the theory of
captures in PEGs? I found Roberto's papers on the implementation of
lpeg fascinating to read, but they omit any serious discussion of
captures. I'd love to have a similar reference which addressed the
area of captures, from both a theoretical and an implementation point
of view).