[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: yet another pattern-matching library for Lua
- From: Eric Raible <raible+lua@...>
- Date: Fri, 5 Jan 2007 19:18:51 +0000 (UTC)
Roberto Ierusalimschy <roberto <at> inf.puc-rio.br> writes:
>
> I have just released LPeg 0.2. No big changes for now...
>
> - Several small corrections (thanks for all who sent suggestions!!).
>
> - Handles embedded zeros like any other character.
>
> - Capture "name" can be any Lua value. (Not very exciting per se, but
> sets the tools to embed arbitrary Lua values into patterns.)
>
> - Unlimited number of captures.
>
> - match gets an optional initial position.
>
One other change - detecting infinite loops - might have a small problem.
Wouldn't it normally be the case that if match(e,p) succeeds that match(e,p^0)
should as well?
This code shows that it isn't so, because the second match can fail with
an "infinite loop" error.
- Eric
function startpos( e, p )
local ok, result = pcall( m.match, e, m.I( ) * p )
if not ok then print( result ) end
return ok
end
-- Raising a peg pattern to the 0-th power should be a no-op, no?
function check( e, p )
print( e, startpos( e, p ) == startpos( e, p^0 ) )
end
check( "test1", m.P(1) )
check( "test2", m.P(1)^0 )