[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: new version of Lpeg
- From: Mike Pall <mikelu-0701@...>
- Date: Fri, 12 Jan 2007 00:48:37 +0100
Hi,
Roberto Ierusalimschy wrote:
> - Several new captures (maybe too many...). Now we can not only
> build syntax trees, but also perform generic semantic actions, do
> substitutions (gsub), etc.
Well, the substitution feature sure looks nice. But when I
experimented with it, I found that its rather slow and nearly
unusable when you've got a large number of substitutions in a
long string (~1M). It first creates a giant capture table for
every matching position and only then goes on to construct the
resulting string.
When I proposed the substitution operator, I was more thinking
along the lines of a one-pass streaming approach. As it is now,
even calling lpeg.match() in a loop seems more efficient ... :-/
> Now I think its main functionallity is in place. But I am considering a
> few changes:
>
> - Remove (or redesign) the "label" stuff. It does not mix well with the
> rest of the capture mechanisms.
Umm, you want to completely remove them? I found named captures
rather convenient. And how would I decide which of the captures
matched in an alternative without labels? Maybe I misunderstood.
A feature request: Make lpeg.R() accept any number of string
arguments and collect ranges from all of its chars. I.e.
(lpeg.R("A", "Z") + lpeg.R("a", "z") + lpeg.R("0", "9"))
could be shortened to:
lpeg.R("AZaz09")
Which is much more compact and readable (IMHO).
Collecting ranges from all chars also allows R("AZ", "az", "09")
or even R("A", "Z") for backwards compatibility. Or if you want
to feed it variables as operands.
About the code:
- lua_pushvalue(L, 1) => lua_pushvalue(L, SUBJIDX)
- lua_equal() => lua_rawequal()
Bye,
Mike