prism icon indicating copy to clipboard operation
prism copied to clipboard

Deprecate `Prism::Translation::Parser`

Open Earlopain opened this issue 9 months ago • 5 comments

and not Prism::Translation::Parser34 etc.

Prism::Translation::Parser declares no version in its name and always parses code like Ruby 3.4. I've seen it used twice now as a replacement for Parser::CurrentRuby (https://github.com/Shopify/packwerk/pull/388 and https://github.com/widefix/actual_db_schema/pull/152).

This may work fine for the projects but they really should be using Prism::Translation::Parser34 instead if that is the case. I believe the version-less parser class is a remnant from when prism was only able to parse a single ruby version.

So, is it worth the trouble to add a deprecation for it?

Earlopain avatar Mar 27 '25 09:03 Earlopain

What if Prism::Translation::Parser was like Parser::CurrentRuby, i.e. use the syntax version based on RUBY_VERSION?

eregon avatar Mar 27 '25 10:03 eregon

I added Prism::Translation::ParserCurrent in https://github.com/ruby/prism/pull/3508 so theoretically it could become an alias for that I suppose.

But personally, I'd prefer it not to since it's very ambiguous from the name alone what it actually does.

Earlopain avatar Mar 27 '25 10:03 Earlopain

Ah OK, I missed Prism::Translation::ParserCurrent then agreed deprecating/removing seems best.

eregon avatar Mar 27 '25 11:03 eregon

Hm, this is akward actually. I was planning on emitting the deprecation on require/autload because there are both class and instance methods available.

But there are other classes nested under it like Prism::Translation::Parser::Lexer, so the autoload is always triggered. Is there a simple solution I am missing to this? Moving the nested classes somewhere else would work but Prism::Translation::Parser::Builder is part of the public interface.

Earlopain avatar Mar 27 '25 12:03 Earlopain

Something like this could work https://github.com/ruby/prism/commit/62c9fb1f659e0209f286e424737af73193ea3932 I will give it some more though later.

Earlopain avatar Mar 27 '25 13:03 Earlopain

Sorry I'm just now coming back to this. My idea was that we would always update this class to be the latest released version, so that people wouldn't need to go back into their code whenever they want to update it. I think this is mainly a documentation thing, because I'd like to be able to write "just give me the latest version of the parser" and not have to go back in and update my code.

kddnewton avatar Aug 19 '25 15:08 kddnewton

Personally I don't really see the point of such a thing (parsing as the currently latest released ruby version). The parser gem has gone a long time without needing something like that (based solely on the fact that that it is currently lacking it). But, prism itself also can parse that way by ommiting the version so it makes sense for parity.

I didn't really think that it's supposed to be used in such a way. I'll close my PR and come back to better document it later.

Earlopain avatar Aug 20 '25 09:08 Earlopain

Maybe it should Prism::Translation::ParserLatest or so to be more explicit? Prism::Translation::Parser from the name is pretty ambiguous, I would also assume it uses the current Ruby version for syntax version, given the parser gem's main usage is that, -rparser/current.

eregon avatar Aug 20 '25 20:08 eregon