tl icon indicating copy to clipboard operation
tl copied to clipboard

Feature Request: More magical string.find return types by counting captures

Open FourierTransformer opened this issue 1 year ago • 0 comments

as of now, string.find has the type:

find: function(string, string, ? integer, ? boolean): integer, integer, string...

Where string... takes care of all the potential captures in the pattern. For folks that do a lot of pattern matching, having the return type reflect the exact number of captures could be useful.

An example with pattern matching timestamps:

start, end, full_match, year, month, day, hour, min, sec, extension = value:find("^((%d%d%d%d)%-(%d%d)%-(%d%d)[Tt ](%d%d):(%d%d):(%d%d))(.*)$")

which has a return type of:

(integer, integer, string, string, string, string, string, string, string, string)

If teal could automatically determine the number of captures (by doing some careful parenthesis counting), and warn the developer if there is a mismatch, then someone could know if one of the fields was missing or if there was an issue with the pattern before runtime.

I'm not sure if there are any "dyanmic" return types in Teal today, and what exactly it would entail. But it would be cool!

FourierTransformer avatar Nov 05 '24 00:11 FourierTransformer