Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
FourierTransformer opened this issue Nov 5, 2024 · 0 comments
Labels
feature request New feature or request

Comments

@FourierTransformer
Copy link
Contributor

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!

@hishamhm hishamhm added the feature request New feature or request label Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants