[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: precompiled regex's to lua
- From: Edgar Toernig <froese@...>
- Date: Fri, 10 Nov 2006 00:24:02 +0100
Asko Kauppi wrote:
> I didn't find any reference to discussing precompiled regular
> expressions, and Lua.
It may sound weird by I was thinking about that when I was
looking for a nice and powerful case statement: precompiled
lex-like finite automatons as a super case statement.
of <intconst> <statements>
of <stringconst> statements>
of <regexp> <statements> # regexp i.e. /[0-9]*/
The compiler could precompile and optimize _all_ regexps of a case
statement into a _single_ NFA. I couldn't find a sane method
though how to pass the semantic data (captures, start/end pos) to
the bodies of the 'of' statements. The lex/awk way of $1, $2 etc
doesn't look very appealing (and doesn't work well for nested
case statements either).
And then naturally comes the next step: one wants to regard the
case-expression as a stream of data. So a start position is
required. "case <expr> [<startpos>]"? Not so nice. Or a "continue"
or "again" statement to restart the case at the current end-pos?
But IMHO the basic idea is tempting - grouping multiple regexps
via a case statement to allow better optimization and getting the
simple regexp matching as a by-product:
case foo of /^[0-9]/ dosomething end