Open achikin opened 10 years ago
I'd love to, but I would need to look into a good way of doing this without incorporating a server..
How do you currently do it with Python and PHP? Don't those need a server?
Maybe you could try compiling Rubinius's implementation of Regex
with Opal?
Sorry, missed your reply @Ajedi32. Those libraries have been compiled into Javascript and run within your browser - thus making it responsive. I'm unsure if I could do the same with Ruby's regex engine. Kind of the same problem as with #54.
@firasdib So do you think it would be feasible to compile Rubinius's implementation of Ruby's Regex
library to JavaScript using Opal? That seems like it could work, at least in theory.
I don't have the time to fiddle with it right now, but you're free to. I would suspect Opal would use javascript regex implementation and not rubys own engine.
@firasdib Yeah, Opal's native implementation of Regex
does just use JavaScript's native Regex under the hood. That's why I recommended using Opal to compile Rubinius's implementation of Ruby's Regex
library, which seems to be written in pure Ruby. Then you'd end up with a cross-compiled JavaScript version of Rubinius's regex library which you could run in the browser.
Maybe I'll look into this a bit deeper later. Really there's only so far I can go though without having access to Regex101's source (e.g. I can't do the final step of integrating my solution with Regex101 and sending a pull request).
Keep me posted! As long as you can get a basic working sample I can finish the rest.
No idea how different Ruby's regex is. There is Rubular which is a browser based regex editor/tester. Not sure if it uses a server execution.
Ruby could be a solid addition since you already have python regex. I would have suggested it myself.
@bryc Rubular runs server side, which is something I'm trying to avoid. I agree this would be a great addition, but I need to think of a good way of doing this.
+1
:+1: Waiting for Ruby support
@firasdib I too would really love Ruby support, as while I use Rubular now, the explanations and match information on regex101 are really invaluable to someone like me learning several flavors at once.
Regarding running a Ruby engine server-side: feel free to email me privately if you want, but what sort of server specs would you need (processing capabilities, RAM, monthly data transfer amounts, disk space, etc.), or are you just not interested in a server-side approach at all? I ask because I'm a very happy customer of Webfaction, and I'd be willing to donate some space, or donate money to support a separate account (whatever would work best).
:+1:
:+1:
The new release will feature a code generator for Ruby which might help some. The PCRE engine is still as close as you're going to get, which is likely going to cover it for most of your cases. But so far I have not been able to get the actual engine running. Sorry!
👍
This might be possible now with the emergence of WebAssembly. In fact, there's a project called ruby-wasm that can compile Ruby scripts into WebAssembly modules (technically, it actually compiles a minimal interpreter and embeds the script), and it even allows the use of some gems, such as mruby-onig-regexp, an MRuby version of the Onigmo regex library, the default regex library for Ruby 2.x.
The only issue is that you can't call from Ruby into JavaScript or JavaScript into Ruby, which unfortunately means it can't be used for this project yet. However, it is something to watch and probably the quickest and easiest way of implementing Ruby regexes client-side.
I also found onigasm, which is Oniguruma compiled to WebAssembly, and that is in a usable state.
This is the same method that is currently being tested for .NET flavour. If that goes well, maybe something similar could be done for Ruby.
Has there been any advancements that will allow us to run the ruby regex engine using WASM? If someone can whip up an example and show me how to build it, I can add it to the website.
This PR seems to address that point: https://github.com/k-takata/Onigmo/pull/153
Got it compiled with below
git clone git@github.com:interscript/Onigmo.git
cd Onigmo
git remote set-url origin git@github.com:k-takata/Onigmo.git
git fetch
git pull --no-commit
docker run --rm -e BUILD="stdlib" -v $(pwd):/src emscripten/emsdk bash -c "apt-get up
date; apt-get install wabt;bash build-wasm.sh"
Test import in node
cat << EOF > index.mjs
import * as M from '/onigmo.wasm'
console.log(M);
EOF
docker run --rm -v $(pwd)/onigmo.wasm:/onigmo.wasm -v $(pwd)/index.mjs:/index.mjs node
--experimental-modules --experimental-wasm-modules index.mjs
Or in browser
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Onigmo WebAssembly Example</title>
<script type="application/javascript">
WebAssembly.instantiateStreaming(
fetch('onigmo.wasm'), importObject).then(obj => {
console.log(obj);
})
</script>
</head>
Please add ruby support.