firasdib / Regex101

This repository is currently only used for issue tracking for www.regex101.com
3.29k stars 199 forks source link

Ruby flavor #48

Open achikin opened 10 years ago

achikin commented 10 years ago

Please add ruby support.

firasdib commented 10 years ago

I'd love to, but I would need to look into a good way of doing this without incorporating a server..

Ajedi32 commented 10 years ago

How do you currently do it with Python and PHP? Don't those need a server?

Ajedi32 commented 10 years ago

Maybe you could try compiling Rubinius's implementation of Regex with Opal?

firasdib commented 10 years ago

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.

Ajedi32 commented 10 years ago

@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.

firasdib commented 10 years ago

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.

Ajedi32 commented 10 years ago

@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).

firasdib commented 10 years ago

Keep me posted! As long as you can get a basic working sample I can finish the rest.

bryc commented 10 years ago

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.

firasdib commented 10 years ago

@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.

stefanahman commented 10 years ago

+1

jpalumickas commented 10 years ago

:+1: Waiting for Ruby support

MattDMo commented 9 years ago

@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).

margaritis commented 8 years ago

:+1:

mrslain commented 8 years ago

:+1:

firasdib commented 8 years ago

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!

maxime-lenne commented 6 years ago

👍

facekapow commented 5 years ago

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.

facekapow commented 5 years ago

I also found onigasm, which is Oniguruma compiled to WebAssembly, and that is in a usable state.

Doqnach commented 5 years ago

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.

firasdib commented 3 years ago

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.

scodeman commented 3 years ago

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>

firasdib commented 2 years ago

@scodeman The PR looks stale, do you know if there is any progress?

Fwiw, Onigmo seems quite similar to PCRE.

noraj commented 2 years ago

I just wanted to highlight that Ruby 3.2.0 will come with WASM / WASI support. I wrote an article (in french) talking about that. There are WebAssembly runtime for Ruby like wasmer-ruby. Some people already made Ruby in the browser projects using WASM like runrb.io (source) or try ruby. So maybe the better way would be to compile Ruby to webassembly?