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

Added Regex Replace node #1893

Merged
merged 2 commits into from
Jun 26, 2023

Conversation

RunDevelopment
Copy link
Member

This adds a Regex Replace node based on Rust's regex crate. I will soon release a new version of chainner_ext with the classes used by this PR.

This node also comes with type support. I added a new builtin function regexReplace that does regex replacements in the type system. This function is implemented using rregex, which we already used. Unfortunately, rregex does not export Rust's capturing groups. This means that we cannot do replacements that reference capturing groups in the type system. This is a huge limitation and I already opened on issue about this (2fd/rregex#32).

image


And now a little rant:
I hate NodeJS. I literally spend a day just getting rregex to work. While NodeJS support WASM just fine, its fucky module system ruined my day once again. You see, WASM files are, well, files, so the atrocious ESM support of NodeJS rears its ugly head again.
No joke, I spend a day on this. I first thought that rregex not working is a webpack thing, but no. In the end, I used require to import a different distribution of rregex depending on whether the main process (NodeJS) or the renderer (Chromium) is importing rregex. That works IF you also manually copy over the actual WASM file. Webpack has a heuristic (that just works™) for which files to include in the distribution since NodeJS packages like to fs.read files. While this heuristic is supposed to be super conservative, so that everything just works™, it failed here. So why did the heuristic fail? NodeJS. It's very hard to statically evaluate the path.joins with __dirname and so on, so I don't blame webpack at all. I do however blame NodeJS for not supporting ESM properly which trivially solves this problem with import.meta.url.

@RunDevelopment RunDevelopment marked this pull request as ready for review June 26, 2023 13:03
@joeyballentine joeyballentine merged commit a4ead65 into chaiNNer-org:main Jun 26, 2023
@RunDevelopment RunDevelopment deleted the regex-replace branch June 26, 2023 16:47
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