lua-users home
lua-l archive

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


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.
Something like

	case <expr>
		of <intconst> <statements>
		of <stringconst> statements>
		of <regexp> <statements>    # regexp i.e. /[0-9]*/
	end

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?
Don't know.

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

Ciao, ET.