Uh oh!
There was an error while loading. Please reload this page.
Add Ripper :on_sp events for Prism.lex_compat and Prism::Translation::Ripper - #3859
Conversation
eregon
commented
Jan 18, 2026
Failures that were added to excludes: |
And more complex cases like Would there be any way to get the correct state with Prism? |
Earlopain
commented
Jan 19, 2026
I would not bother with comparing state for this. I'm not particularly motivated to understand what is happening in detail here. I doubt anyone is relying on this information being correct. |
eregon
commented
Jan 19, 2026
Yeah it's what I'm doing in test/prism/ruby/ripper_test.rb, I'm ignoring the state of Slightly related, is |
Earlopain
commented
Jan 19, 2026
Just putting in the state from the previous token seems fine. When it lines up, great. If not, oh well. Doesn't really matter in what way it's wrong.
I believe that is what ripper itself does. I haven't benchmarked this in detail yet but there are definitly some hotspots. Much time is spend sorting tokens by location for example. If changing this makes a noticable difference, I wouldn't be opposed to it. Here's what I use to quickly check: require"ripper"require"prism"require"benchmark/ips"codes=Dir["**/*.rb"].map{File.read(it)}Benchmark.ipsdo |x|
x.report("prism"){codes.each{Prism::Translation::Ripper.lex(it)}}x.report("ripper"){codes.each{Ripper.lex(it)}}x.compare!endI was also a bit concerned about the performance of this implementation but it is not so bad. Compared to ripper it goes from 2.3x times slower to 2.6x times slower which seems fine. |
Uh oh!
There was an error while loading. Please reload this page.
Earlopain
left a comment
There was a problem hiding this comment.
Still a draft but this is basically good to me.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
e214296 to
68a45bcCompare
|
Uh oh!
There was an error while loading. Please reload this page.
f9acebf to
b7336e8CompareTaking notes, next failure is # top-100-gems/graphql-2.0.21/lib/generators/graphql/install/mutation_root_generator.rbendend#<trailing space here- [[34, 0], :on_kw, "end", END],- [[34, 3], :on_sp, " ", END]]+ [[34, 0], :on_kw, "end", END]]UPDATE: fixed now |
2541426 to
c29d8a9Compareeregon
commented
Jan 19, 2026
The BOM (byte order mark) edge cases are madness but I think I got them correct now 😅 |
Earlopain
left a comment
There was a problem hiding this comment.
I'm somewhat surprised that this seems to handle all the cases. Nice work.
| sig { params(byte_offset: Integer, length: Integer).returns(String) } | ||
| def slice(byte_offset, length); end | ||
| def slice(...); end |
There was a problem hiding this comment.
I really don't know if this is ok. It typechecks but that's about it about my knowledge. I hate fighting with these tools. I'm just going to revert this and update the two places that pass a range.
There was a problem hiding this comment.
I read some Sorbet docs and asked ChatGPT and basically Sorbet seems to not really support ....
I tried just leaving sig { returns(String) } but it was not happy about it.
Maybe overloads like this would work:
sig{overload.params(a: Integer,b: Integer).void}sig{overload.params(r: T::Range[Integer]).void}defslice(*args);endBut it feels complicated and duplicating the type of byteslice, hence just def slice(...); end felt simpler.
It'd be nice if we could say "this has the exact same type as String#byteslice".
| @@ -0,0 +1 @@ | |||
| p (42) | |||
There was a problem hiding this comment.
Commited the two snapshots as well. Basically they get created when when running bundle exec rake
| --ignore=rakelib/ | ||
| --ignore=Rakefile | ||
| --ignore=top-100-gems/ | ||
| #{Dir.glob("*.rb").map { |f| "--ignore=/#{f}" }.join("\n")} |
…:Ripper * Handle line continuations. * Handle space at the end of file in LexCompat. Co-authored-by: Earlopain <14981592+Earlopain@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.
Earlopain
commented
Jan 20, 2026
This causes test failures in |
It used to not emit this token type, but now it does. So when a newer version of prism is present, we can fall back to the same code that ripper uses. Ref: * ruby/ruby#15914 * ruby/prism#3859
It used to not emit this token type, but now it does. So when a newer version of prism is present, we can fall back to the same code that ripper uses. Ref: * ruby/ruby#15914 * ruby/prism#3859
It used to not emit this token type, but now it does. So when a newer version of prism is present, we can fall back to the same code that ripper uses. Ref: * ruby/ruby#15914 * ruby/prism#3859
eregon
commented
Jan 20, 2026
@Earlopain Oh, sorry about that, I didn't expect that would break. |
It used to not emit this token type, but now it does. So when a newer version of prism is present, we can fall back to the same code that ripper uses. Ref: * ruby/ruby#15914 * ruby/prism#3859
It used to not emit this token type, but now it does. So when a newer version of prism is present, we can fall back to the same code that ripper uses. Ref: * ruby/ruby#15914 * ruby/prism#3859
It used to not emit this token type, but now it does. So when a newer version of prism is present, we can fall back to the same code that ripper uses. Ref: * ruby/ruby#15914 * ruby/prism#3859
It used to not emit this token type, but now it does. So when a newer version of prism is present, we can fall back to the same code that ripper uses. Ref: * ruby#15914 * ruby/prism#3859ruby/syntax_suggest@42a3b8f6cb
It used to not emit this token type, but now it does. So when a newer version of prism is present, we can fall back to the same code that ripper uses. Ref: * ruby#15914 * ruby/prism#3859ruby/syntax_suggest@42a3b8f6cb
It used to not emit this token type, but now it does. So when a newer version of prism is present, we can fall back to the same code that ripper uses. Ref: * ruby#15914 * ruby/prism#3859ruby/syntax_suggest@42a3b8f6cb
It used to not emit this token type, but now it does. So when a newer version of prism is present, we can fall back to the same code that ripper uses. Ref: * #15914 * ruby/prism#3859ruby/syntax_suggest@42a3b8f6cb
It used to not emit this token type, but now it does. So when a newer version of prism is present, we can fall back to the same code that ripper uses. Ref: * #15914 * ruby/prism#3859ruby/syntax_suggest@42a3b8f6cb
It used to not emit this token type, but now it does. So when a newer version of prism is present, we can fall back to the same code that ripper uses. Ref: * #15914 * ruby/prism#3859ruby/syntax_suggest@42a3b8f6cb
Ref: #3838
On top of #3858 should be merged first.