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.

Certainly some captures are equivalent to others:

- Cc(K)  --> ""/function () return K end

- pat/table:  --> pat/function (k) return table[k] end

- pat/string  --> pat/function (s) return doreplacement(s, string) end
                  (for a proper definition of doreplacement)

- Ct(patt)   --> function (...) return {...} end
                 (except that there is a somewhat small limit on the
                  size of such table)


I guess pat/func itself can be defined in terms of folding:

- pat/func  --> Cf(C("") * Cg(pat), function (x, ...) return func(...) end)
(I am not sure this is correct...)

- Cs and C are very similar, but I do not think one can emulate the
exact behavior of the other.

-- Roberto