lua-users home
lua-l archive

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


> I noticed that when matching the following pattern:
> 
>   patt1 / func1 * lpeg.P(func2) * patt2 * patt3
> 
> func2 is called before func1, moreover, if func2() returns nil,
> then func1 isn't called at all. While this behavior seems
> reasonable, I fail to find it mentioned somewhere in the manual.

All captures are "executed" only after the match succeeds (if it
succeeds). I will add something about this to the manual.


> And the question is: how to make results of func2() depend on
> the captures of patt1 ?

Currently you can't. Because captures are "executed" only after the
match succeeds, patt1 captures do not exist when func2 is called. I am
still thinking how to improve this relationship in a consistent way.
(It would be nice if func2 could make its own captures too, or at least
control what captures from patt1 to keep...)

(Anyway, maybe in your example you are stretching a little too much
the use of lpeg; lpeg is for parsing a program, not for running it.)

-- Roberto