Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better handle heredoc escaping in the parser translator #3343

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Earlopain
Copy link
Contributor

@Earlopain Earlopain commented Dec 24, 2024

Builds on top of #3341, will fix rubocop/rubocop#12878

This does a few things:

  • After a line continuation in a heredoc, emit only a single token
  • Dedent ` heredocs
  • Properly handle escapes in single and doublequoted heredocs

Some of the heredoc escaping logic should be applied to strings as well,
but I'll leave that for a different PR.

Also, if the heredoc consists only of literal string content, this new escaping branch is not yet taken. It only works if interpolation is used.

In parser, the string content is dedented. This implements these rules
as far as I was able to understand them. It's all a bit confusing with
spaces/tabs, always learning more funny things about them.

I refered to the prism implementation, parser seems to adhere to it very closely.
@Earlopain Earlopain force-pushed the parser-translator-escaping-heredoc-strings branch 2 times, most recently from a350495 to b751c75 Compare December 24, 2024 09:27
This does a few things:
* After a line continuation in a heredoc, emit only a single token
* Dedent ` heredocs
* Properly handle escapes in single and doublequoted heredocs

Some of the heredoc escaping logic should be applied to strings as well,
but I'll leave that for a different PR.
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.

False Positive for Lint/ImplicitStringConcatenation with prism
1 participant