[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: LPeg: inconsistencies regarding empty captures
- From: Pierre-Yves Gérardy <pygy79@...>
- Date: Wed, 8 May 2013 02:09:23 +0200
/number skips captures with no values, whereas /string counts them. Example:
> (Cg(Cc"foo", "z") * Cb"z" / 1):match"" --> "foo"
> (Cg(Cc"foo", "z") * Cb"z" / "%1"):match""
stdin:2: no values in capture index 1
> (Cg(Cc"foo", "z") * Cb"z" / "%2"):match"" --> "foo"
In a similar vein, while Cf complains if the first capture is empty, a
Cg whose only captures are empty will behave as if there were no
captures in it, and produce his whole match...
> Cg(Cc""/{}*1):match"R" --> "R"
but
> Cf(Cc""/{}*C(1),print):match"R"
stdin:1: no initial value for fold capture
It would be nice if all captures could behave identically. Personally,
I'd rather have them skip these empty captures in all circumstances...
-- Pierre-Yves