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

Ruby flavor #48

Open
achikin opened this issue Jun 17, 2014 · 24 comments
Open

Ruby flavor #48

achikin opened this issue Jun 17, 2014 · 24 comments

Comments

@achikin
Copy link

achikin commented Jun 17, 2014

Please add ruby support.

@firasdib
Copy link
Owner

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

@Ajedi32
Copy link

Ajedi32 commented Jul 9, 2014

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

@Ajedi32
Copy link

Ajedi32 commented Jul 9, 2014

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

@firasdib
Copy link
Owner

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
Copy link

Ajedi32 commented Jul 22, 2014

@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
Copy link
Owner

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
Copy link

Ajedi32 commented Jul 22, 2014

@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
Copy link
Owner

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

@bryc
Copy link

bryc commented Aug 31, 2014

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
Copy link
Owner

@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
Copy link

+1

@jpalumickas
Copy link

👍 Waiting for Ruby support

@MattDMo
Copy link

MattDMo commented Sep 9, 2015

@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
Copy link

👍

1 similar comment
@mrslain
Copy link

mrslain commented Mar 20, 2016

👍

@firasdib
Copy link
Owner

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!

@Zarthus Zarthus changed the title Ruby support Ruby flavor Mar 30, 2017
@maxime-lenne
Copy link

👍

@facekapow
Copy link

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
Copy link

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

@Doqnach
Copy link
Collaborator

Doqnach commented Aug 26, 2019

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
Copy link
Owner

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
Copy link

scodeman commented Mar 25, 2021

This PR seems to address that point: k-takata/Onigmo#153

Got it compiled with below

git clone [email protected]:interscript/Onigmo.git
cd Onigmo
git remote set-url origin [email protected]: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
Copy link
Owner

firasdib commented Feb 9, 2022

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

Fwiw, Onigmo seems quite similar to PCRE.

@noraj
Copy link

noraj commented Jul 2, 2022

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?

@OnlineCop OnlineCop mentioned this issue Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests