lua-users home
lua-l archive

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



On 04/22/2017 12:30 AM, steve donovan wrote:
> On Fri, Apr 21, 2017 at 11:43 PM, Egor Skriptunoff
> <egor.skriptunoff@gmail.com> wrote:
>> "(.)%2" is an invalid pattern, but it could be applied to empty string
>> without an error.
> 
> Yes, exactly. There are a number of these which go beyond simple
> mechanical validation (brackets matching up etc).
> 
> My feeling is that it is possible to do this (after all, regexps can
> be compiled) but not without going through a similar, recursive
> process to existing matching - so you know how many captures you have,
> etc.

I've implemented Lua regexps parser some months ago. Just to have a
mechanized way to get meaning of tricky regexps strings. It parses
string to folded table where keys are strings with structure names
or sequence integers. And values are strings or tables with same
structure.

This AST may be used to detect usage of invalid reference in "(.)%2".
(Are there are cases of "incorrect" pattern strings?)

Below is a link to code describing regexp structure. It uses my own
generic parser which gets structure to parse in form of lua table,
not string (which is very handy in passing self-linked structures).
There is no frontend for this code (as I saw no need in this).

If you need function that gets regexp string and returns folded table
in described format I may implement it.

https://github.com/martin-eden/workshop/blob/master/formats/lua_regexps/load/syntax.lua#L76

-- Martin