Skip to content

Split some tokens - #4199

Merged
kddnewton merged 3 commits into
mainfrom
split-tokens
Aug 5, 2026
Merged

Split some tokens#4199
kddnewton merged 3 commits into
mainfrom
split-tokens

Conversation

@kddnewton

Copy link
Copy Markdown
Collaborator

Some tokens can represent multiple things depending on context, like (, {, and ```. These tokens are represented in parse.y as different tokens, and therefore have different grammar rules applied to them. This PR mirrors that logic in order to make comparing against the upstream grammar simpler.

It has the added benefit of making it so that we no longer have to rely on any internal state in our translation engines (except for in lex compat).

@Earlopain do you think we could drop the lex state from the public API after this?

This more closely matches parse.y, and simplifies a bit of the lex
state as seen from the outside.
This also more closely matches parse.y, and makes it easier to
delineate which brace belongs to which type.
Now we fully match parse.y, and it is clearer to distinguish
betewen backticks that are used for method names and backticks
that begin xstring literals.
@kddnewton
kddnewton merged commit a33c3ff into main Aug 5, 2026
108 of 110 checks passed
@kddnewton
kddnewton deleted the split-tokens branch August 5, 2026 11:02
@Earlopain

Earlopain commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

I would welcome to remove the state from the lex result. But doing so in a compatible way might be a bit bothersome. When I rewrote syntax_suggest to not use ripper anymore in ruby/syntax_suggest#251 I made an effort to not use it and that mostly worked out ok. For things that were too bothersome (like detecting endless methods just from tokens) I took the AST to help. But I'd want to check what else currently uses the state and why (if any)

BTW, this broke some irb colorizer tests. That's fine and easy to fix though but it now also accepts def f(a,) end when it previously didn't. Can you take a look?

Earlopain added a commit to Earlopain/irb that referenced this pull request Aug 5, 2026
Changed in ruby/prism#4199. Other token changes are irrelevant
since they are already not used.
Earlopain added a commit to Earlopain/irb that referenced this pull request Aug 5, 2026
Changed in ruby/prism#4199. Other token changes are irrelevant
since they are already not used.
@kddnewton

Copy link
Copy Markdown
Collaborator Author

I see you crossed out def f(a,) end when it previously didn't. Can you take a look?. Was that incorrect?

@Earlopain

Copy link
Copy Markdown
Collaborator

That's the new trailing comma syntax. I tested against older irb locally and forgot that this changed. Oops

tompng pushed a commit to ruby/irb that referenced this pull request Aug 5, 2026
Changed in ruby/prism#4199. Other token changes are irrelevant
since they are already not used.
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.

2 participants