Skip to content

Conversation

@kddnewton
Copy link
Collaborator

@kddnewton kddnewton force-pushed the leading-logical branch 2 times, most recently from 263df49 to 877f497 Compare December 21, 2024 20:56
@kddnewton kddnewton force-pushed the leading-logical branch 3 times, most recently from 75236a8 to a10344c Compare February 14, 2025 14:57
Comment on lines +10856 to +10849
(peek_at(parser, following) == '.') ||
(peek_at(parser, following) == '&' && peek_at(parser, following + 1) == '.')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be better to use store peek_at(parser, following) into an intermediate variable?

Comment on lines +10871 to +10866
(peek_at(parser, following) == '&' && peek_at(parser, following + 1) == '&') ||
(peek_at(parser, following) == '|' && peek_at(parser, following + 1) == '|') ||
(peek_at(parser, following) == 'a' && peek_at(parser, following + 1) == 'n' && peek_at(parser, following + 2) == 'd' && !char_is_identifier(parser, following + 3, parser->end - (following + 3))) ||
(peek_at(parser, following) == 'o' && peek_at(parser, following + 1) == 'r' && !char_is_identifier(parser, following + 2, parser->end - (following + 2)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same question here about all the peek_at(parser, following)

Earlopain added a commit to Earlopain/prism that referenced this pull request Jul 21, 2025
This makes it hard to do version checks against this value. The current version checks work because there are so few possible values at the moment.

As an example, ruby#3337 introduces new syntax for ruby 3.5 and uses `PM_OPTIONS_VERSION_LATEST` as its version guard. Because what is considered the latest changes every year, it must later be changed to `parser->version == parser->version == PM_OPTIONS_VERSION_CRUBY_3_5 || parser->version == PM_OPTIONS_VERSION_LATEST`, with one extra version each year.

With this change, the PR can instead write `parser->version >= PM_OPTIONS_VERSION_CRUBY_3_5` which is self-explanatory
and works for future versions.
Earlopain added a commit to Earlopain/prism that referenced this pull request Jul 21, 2025
This makes it hard to do version checks against this value. The current version checks work because there are so few possible values at the moment.

As an example, ruby#3337 introduces new syntax for ruby 3.5 and uses `PM_OPTIONS_VERSION_LATEST` as its version guard. Because what is considered the latest changes every year, it must later be changed to `parser->version == parser->version == PM_OPTIONS_VERSION_CRUBY_3_5 || parser->version == PM_OPTIONS_VERSION_LATEST`, with one extra version each year.

With this change, the PR can instead write `parser->version >= PM_OPTIONS_VERSION_CRUBY_3_5` which is self-explanatory
and works for future versions.
src/prism.c Outdated
(peek_at(parser, following) == '.') ||
(peek_at(parser, following) == '&' && peek_at(parser, following + 1) == '.')
))
(parser->version == PM_OPTIONS_VERSION_LATEST) &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

I found this version check a bit strange since LATEST is a moving target and openend #3605 to talk about it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

PR above was merged, this should now be this

Suggested change
(parser->version == PM_OPTIONS_VERSION_LATEST) &&
(parser->version >= PM_OPTIONS_VERSION_CRUBY_3_5) &&

src/prism.c Outdated
(peek_at(parser, following) == '.') ||
(peek_at(parser, following) == '&' && peek_at(parser, following + 1) == '.')
))
(parser->version == PM_OPTIONS_VERSION_LATEST) &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

PR above was merged, this should now be this

Suggested change
(parser->version == PM_OPTIONS_VERSION_LATEST) &&
(parser->version >= PM_OPTIONS_VERSION_CRUBY_3_5) &&

src/prism.c Outdated
LEX(PM_TOKEN_AMPERSAND_DOT);
}

if (parser->version == PM_OPTIONS_VERSION_LATEST) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (parser->version == PM_OPTIONS_VERSION_LATEST) {
if (parser->version >= PM_OPTIONS_VERSION_CRUBY_3_5) {

@XrXr
Copy link
Member

XrXr commented Aug 27, 2025

FYI Matz approved this feature a week ago in https://bugs.ruby-lang.org/issues/20925#note-11

@kddnewton kddnewton merged commit 8955403 into main Sep 12, 2025
60 checks passed
@kddnewton kddnewton deleted the leading-logical branch September 12, 2025 17:51
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