Skip to content

Conversation

@takaram
Copy link
Member

@takaram takaram commented Feb 15, 2024

Ruby 3.3 introduced Prism parser, and it is also released as a gem.
The latest version of Prism includes Prism::Tarnslaion::Parser, a wrapper class to make Prism compatible with parser gem (whitequark/parser).

This PR tries to replace the current parser (Parser::Ruby32) with Prism::Tranlation::Parser.
Since this is just an experiment, the default parser remains to be that of parser gem. Instead I added --prism CLI option to switch the parser.

Here are some advantages with Prism:

Todo:

  • Support using Prism in opalopal
    • Prism can be run in JavaScript through wasm
  • Run tests with Prism

cc: @kddnewton

Copy link

@kddnewton kddnewton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing!

@hmdne
Copy link
Member

hmdne commented Feb 15, 2024

There's a small issue for opalopal as of now which regards loading of WASM modules - they can be only loaded async (at least in Chromium). I have a plan to support such workflow, but it will take some time.

Other than that, before we flip the default, we will also have to check regressions in source maps.

Thanks to recent improvement of Prism, we no longer need workaround code
@davispuh
Copy link
Contributor

So what's the current status of using Prism parser in Opal?
Basically I want browser based REPL that uses Prism WASM.

@hmdne
Copy link
Member

hmdne commented Dec 20, 2025

@davispuh This PR is mostly about experimenting with Prism to work under MRI. And it mostly works.

We have a long term goal to migrate from whitequark/parser to prism, but there are multiple issues as of now:

  • As I mentioned above, we have to streamline WASM loading. This process has recently stalled, but I plan to go back to it.
  • The prism WASM module is quite large IIRC. Much larger than whitequark/parser compiled using Opal to JS (which is what we do whenever you do require "opal-parser")
  • Since the last supported Ruby release, there haven't been many syntax changes, so for many cases it's enough

@kddnewton
Copy link

My bad, I didn't know it had gotten so big. I've lowered its size now ruby/prism#3824 and it could probably get quite a bit smaller if I'm honest. How big is the built whitequark/parser? I can aim to be smaller than that.

@kddnewton
Copy link

@davispuh Is https://github.com/kateinoigakukun/irb.wasm what you're looking for? That's kind of orthogonal to this PR, which is more about supporting eval.

@hmdne
Copy link
Member

hmdne commented Dec 22, 2025

@kddnewton I think you managed it :). I have tried to isolate Opal-compiled parser (with no other parts of Opal, ie. compiler):

[user@localhost opal]$ bin/opal -sopal/rewriter -ropal/parser -e '#' -Oc --no-source-map | wc -c
1313404
[user@localhost opal]$ bin/opal -sopal/rewriter -ropal/parser -e '#' -Oc --no-source-map | npx terser -cm | wc -c
862924
[user@localhost opal]$ 

The second number is what we should compare against, since most of the time we want to ship Opal-generated code minified.

@kddnewton
Copy link

Oh yeah nice, we're now < half that size.

@janbiedermann
Copy link
Member

Is that including the support code for serialization?

@kddnewton
Copy link

Yes! I just added the flags for ignoring the other optional features like JSON support/pack support/etc.

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.

5 participants