[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Static validation of Lua String Patterns?
- From: Martin <eden_martin_fuhrspam@...>
- Date: Sat, 22 Apr 2017 14:06:10 -0700
On 04/22/2017 12:30 AM, steve donovan wrote:
> On Fri, Apr 21, 2017 at 11:43 PM, Egor Skriptunoff
> <firstname.lastname@example.org> 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,
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
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.