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 escaping handling for all strings in the parser translator #3344

Merged

Conversation

Earlopain
Copy link
Contributor

Builds on top of #3343, which builds on top of #3341. I'll stop here for now until these are all handled, could get very messy otherwise.

This implements more of the escaping rules for all kinds of strings that can appear in:

  • %i/%I
  • %w/%W
  • %q/%Q (and %)

It takes into account that for %downcase notation and single-quoted strings, the delimiter is allowed to be escaped.
It also implements the special rule about symetric delimiters like (, where ) is also allowed.

Leave regexp as is for now, they have their own special rules.

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.
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.
@Earlopain Earlopain force-pushed the parser-translator-escaping-all-kinds-of-strings branch from 01123a1 to b151e09 Compare December 30, 2024 15:03
This implements more of the escaping rules for all kinds of strings that can appear in:
* %i/%I
* %w/%W
* %q/%Q (and %)

It takes into account that for %downcase notation and single-quoted strings, the delimiter is allowed to be escaped.
It also implements the special rule about symetric delimiters like `(`, where `)` is also allowed.

Leave regexp as is for now, they have their own special rules.
@Earlopain Earlopain force-pushed the parser-translator-escaping-all-kinds-of-strings branch from b151e09 to 73aeba6 Compare December 30, 2024 15:20
@kddnewton kddnewton merged commit 5cc71e1 into ruby:main Jan 3, 2025
56 checks passed
@Earlopain Earlopain deleted the parser-translator-escaping-all-kinds-of-strings branch January 7, 2025 20:05
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