lua-users home
lua-l archive

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


Maybe I am missing something, but your Cp(patt) sounds like this:

(C(patt) * Cp())



On May 11, 2012, at 11:35 AM, Eduardo Ochs wrote:

> Hello list,
> 
> I am trying to reimplement in LPeg a recursive-descent parser that I
> wrote by hand, and - for some reasons that I'll explain in a next
> message if it turns out that my doubts are not too dumb - I had to use
> lpeg.Cmt(f) in several of my sub-patterns, and I realized that my work
> would be much easier if lpeg.Cp accepted a pattern as an argument,
> i.e., if instead of
> 
>  lpeg.C(patt)  the match for patt plus all captures made by patt
>  lpeg.Cp()     the current position (matches the empty string)
> 
> we had:
> 
>  lpeg.C(patt)  the match for patt plus all captures made by patt
>  lpeg.Cp(patt) if patt is nil, then the current position;
>                if patt is a pattern, then the position after
>                matching patt (if the match succeeds), plus all
>                captures made by patt
> 
> Anyone knows a way to simulate the behavior I'm suggesting for lpeg.Cp
> when its `patt' is not nil?
> 
>  Cheers and thanks in advance,
>    Eduardo Ochs
>    eduardoochs@gmail.com
>    http://angg.twu.net/
> 
> 
> P.S.: I _think_ I know two ways for doing that: one is a very, very,
> _very_ ugly hack using the fact that `patt / f' is supposed to
> evaluates f as late as possible (modulo optimizations), and the other
> way involves running table.pack on the captures of patt*lpeg.Cp(),
> then returning the last value in that table plus the unpacking of the
> rest... But there must be better ways! =|
>