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

add builtin regex function #120

Merged
merged 9 commits into from
Oct 15, 2023
Merged

Conversation

billy-yoyo
Copy link
Contributor

Context

This adds the Rust Regex package as a dependency and adds a simple regex function (without a glyph alias) which executes a pattern and returns a list of boxed strings representing each of the matching groups.

I also added a hashmap cache to the Uiua environment, which we use as a pattern cache.

Let me know if you'd like any changes.

@billy-yoyo
Copy link
Contributor Author

billy-yoyo commented Oct 10, 2023

actually just realized this might not handle error situations very well, will add some more tests later

@kaikalii
Copy link
Member

Great work!
I'd like to request one change.
Rather than having the cache as part of the Uiua struct, can you make it a thread-local?.
That way calling regex won't have to lock anything.

@billy-yoyo
Copy link
Contributor Author

Will do, probs won't have time tonight but maybe tomorrow

@billy-yoyo
Copy link
Contributor Author

@kaikalii changed the cache to use a thread local and also added some recovery code (invalid pattern, 0 matches) so it should be more stable now.

@billy-yoyo
Copy link
Contributor Author

looks like build is failing for using an unstable feature, will look into implementing around it tomorrow

@billy-yoyo
Copy link
Contributor Author

billy-yoyo commented Oct 11, 2023

That's slightly annoying, the feature it's erroring for because it's unstable has been all but approved: rust-lang/rust#92122

Not sure if there's a way to disable this error as it's not really important based on that rust Lang pr

E: can just add the feature flag to the crate flag, will do it tomorrow

@kaikalii
Copy link
Member

Why not just use .with(...)?

@billy-yoyo
Copy link
Contributor Author

@kaikalii changed with_borrow_mut to with followed by a borrow_mut

@kaikalii kaikalii merged commit dc16747 into uiua-lang:main Oct 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants