lua-users home
lua-l archive

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


On Mon, 21 Feb 2011, Wim Langers wrote:
>
> the first part of below code (recursuve pattern) will print :
>
> input  key  peer
> input  key2  peer2
> input  key2  peer2
> insert key
> insert key2
...
>   Inputs_ = V('Input') * V('_SPC') * V('Inputs_') + V('Input')
...
> Lpeg.match(PATTERN,'(key::peer key2::peer2)')

The reason for this is the match-time capture is exposing LPEG's
backtracking. The first time LPEG sees the second Input it tries to parse
it as Input * _SPC * Inputs_. This fails after matching Input when it
tries to match _SPC against the closing bracket. So it backtracks and
successfully matches against the alternative Input. So it matched the
second Input twice.

Why are you using match-time captures? I didn't see anything in your
grammar that required them.

Tony.
-- 
f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
Dover, Wight: Southeast, backing northeast 3 or 4, occasionally 5. Slight or
moderate. Occasional rain. Moderate or poor.