-
Notifications
You must be signed in to change notification settings - Fork 55
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 RegEx supports using RE2 to sjsonnet #244
base: master
Are you sure you want to change the base?
Conversation
the reg2j's performance is better? |
It's also what's used in scala native. |
Seems like we could have a scala port from it ,t hen the scala-js and scala-native can use it too. |
Is there a test suit for regex?, maybe this will change some behavior or result, eg with default behavior changed. |
I added a test suite. Is there something else you are thinking about? |
671a764
to
df59fee
Compare
With this PR, I'm adding a handful of methods to expose regular expressions in jsonnet, through std.native()
I'm modeling them after this open PR from jsonnet, which was ported to jrsonnet.
For now, they are in std.native() as they are not part of the default std package and use RE2 instead of the native regexp package (for performance and compatibility reasons with a future go-jsonnet implementation).
and the utility function:
Those functions return a object:
This PR does not add support for the "namedCaptures" return field due to some complications with scalajs and scalanative. Those language both use the JDK Pattern class (js being powered by ECMA regex and Native being powered by RE2(!)), but JDK<20 Pattern class does not have a straightforward way to list the names of groups without some additional hacks. This will be dealt with in a follow up PR.
This PR also adds the ability to cache patterns, and refactors all users of regexes to use it.