Skip to content

Percent array heredoc continuation#3778

Merged
kddnewton merged 2 commits into
ruby:mainfrom
Earlopain:percent-array-heredoc-continuation
Dec 3, 2025
Merged

Percent array heredoc continuation#3778
kddnewton merged 2 commits into
ruby:mainfrom
Earlopain:percent-array-heredoc-continuation

Conversation

@Earlopain

Copy link
Copy Markdown
Collaborator

See https://bugs.ruby-lang.org/issues/21756. Ripper fails to parse this but prism actually also doesn't handle it correctly.

When heredocs are used, even in lowercase percent arays there can be
multiple STRING_CONTENT tokens. We need to concat them.

Luckily we don't need to handle as many cases as in uppercase arrays where interpolation is allowed. Mostly inspired by how uppercase arrays are handled.

%q strings seem to work ok already.

Second commit is a pretty small fix I noticed while I was poking around. Probably a copy-paste error.

See https://bugs.ruby-lang.org/issues/21756. Ripper fails to parse this,
but prism actually also doesn't handle it correctly.

When heredocs are used, even in lowercase percent arays there can be
multiple `STRING_CONTENT` tokens. We need to concat them.

Luckily we don't need to handle as many cases as in uppercase arrays where interpolation is allowed.
Not so sure how to trigger it but this is definitly more correct.
@Earlopain
Earlopain force-pushed the percent-array-heredoc-continuation branch 2 times, most recently from 3497ea8 to 1bc8ec5 Compare December 3, 2025 08:20
@Earlopain
Earlopain marked this pull request as ready for review December 3, 2025 08:32
Comment thread src/prism.c
pm_array_node_t *array = pm_array_node_create(parser, &opening);

// skip all leading whitespaces
accept1(parser, PM_TOKEN_WORDS_SEP);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This was not needed, the loop already consumsed the separator. Removed because it was already not present in %i handling

@kddnewton kddnewton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks right to me!

@kddnewton
kddnewton merged commit 81051c1 into ruby:main Dec 3, 2025
64 checks passed
@Earlopain
Earlopain deleted the percent-array-heredoc-continuation branch February 20, 2026 12:41
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