lua-users home
lua-l archive

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


Lpeg has a significant number of capture constructs:

- Captures matching the empty string: Cp, Cc, Carg and Cb
- Captures of the string matching a subpattern: C and Cs
- Captures manipulating the captures of a subpattern: Cg, Cf, Ct,
pat/str, pat/table, pat/func

I suspect (although I haven't yet done the hard work of proving this
:-)) that some of these can be implemented in terms of others - in
particular, Cf and pat/func are probably generic enough to implement
many of the others.

Have any studies been done on which of the various captures are more
or less useful/fundamental in real code?

The reason I ask is that for my Python implementation, I'm considering
omitting some of the Lua constructs have semantics that are difficult
to emulate (specifically, ones where tables are involved, as the
semantics of Lua's tables and Python's dictionaries differ in subtle
but significant ways). As calculating the matches based on the
information generated internally by the matching engine is not
generally time-critical (except when Cmt is involved) and so writing
high-level Python wrappers round, say, pat/func should be acceptable
(and allows for more experimentation).

Paul.