jasoncharnes / run.rb

Run Ruby in the browser using WebAssembly
https://runrb.io
MIT License
598 stars 31 forks source link

Using Ripper with run.rb #9

Open AlanFoster opened 5 years ago

AlanFoster commented 5 years ago

Hey, love the project. I was just wondering if it would ever be possible to call off to Ruby's ripper module with run.rb ?

I was looking into integrating run.rb with the prettier plugin for Ruby - which requires access to the Ruby runtime and Ripper. I just want to rule out whether it's possible to use this project for that or not as it would allow Ruby code to be formatted directly in the browser without ever making external calls to a web server.

Some extra context here:

https://github.com/prettier/plugin-ruby/issues/138

Any insights would be appreciated! 🏆

jasoncharnes commented 5 years ago

Thanks, Alan! I currently use Prettier for JavaScript, so I've kept my eye on the Ruby implementation. 😎

I would love to answer this question, but my contribution to this project was more the idea and the interface for it. 😅 My friend Will came up with the idea for the WASM implementation (and subsequently wrote the implementation).

We're currently using the Ruby runtime, be we don't have the standard library loaded. I believe it's possible and I know long term we'd like to add stdlib to the project. So speaking ignorantly, I think it's possible?

@willglynn if you have time, would you know (and be willing to share) the answer to this?

willglynn commented 5 years ago

@jasoncharnes Yeah, the WebAssembly module interacts with the filesystem via the Emscripten filesystem interface, which lets us ship files inside or alongside the WebAssembly module. A reasonable solution might be to bundle the standard library as part of the build process and expose a JS interface for other files.

AlanFoster commented 5 years ago

@jasoncharnes + @willglynn Cool - thanks for the context!

It's worth noting that the module we're after is Ripper - which I think might add an extra level of complexity as it's the interface to ruby's parser. Let me know if this would change the approach or not :+1: