Skip to content

Conversation

@Earlopain
Copy link
Collaborator

@Earlopain Earlopain commented Jan 9, 2025

'foo\
bar\\
baz
'

Before:

  0...1: tSTRING_BEG     => "'"
 1...12: tSTRING_CONTENT => "foobar\\\n"
12...16: tSTRING_CONTENT => "baz\n"
16...17: tSTRING_END     => "'"
17...18: tNL             => nil

After:

  0...1: tSTRING_BEG     => "'"
  1...6: tSTRING_CONTENT => "foo\\\n"
 6...12: tSTRING_CONTENT => "bar\\\n"
12...16: tSTRING_CONTENT => "baz\n"
16...17: tSTRING_END     => "'"
17...18: tNL             => nil

Additionally, a trailing backslash in a word array is not a line continuation, but rather makes the following newline part of the string/symbol.

@Earlopain Earlopain force-pushed the parser-translator-tokens-line-cont-single-quotes branch from 387ae75 to 5bc3727 Compare January 9, 2025 18:29
@Earlopain Earlopain changed the title Don't consider non-interpolated strings in the parse translator to have line continuations Fix parser translator tokens for backslashes in single-quoted strings and word arrays Jan 9, 2025
end

# Determine if the string is part of a %-style array.
def word_array?(quote)
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
def word_array?(quote)
def percent_literal?(quote)

If you don't mind, can you change this? CRuby internally calls %w a word array, so I want to make sure it's clear that this includes symbol lists as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, no problem

… and word arrays

These are not line continuations. They either should be taken literally,
or allow the word array to contain the following whitespace (newlines in this case)

Before:
```
  0...1: tSTRING_BEG     => "'"
 1...12: tSTRING_CONTENT => "foobar\\\n"
12...16: tSTRING_CONTENT => "baz\n"
16...17: tSTRING_END     => "'"
17...18: tNL             => nil
```

After:
```
  0...1: tSTRING_BEG     => "'"
  1...6: tSTRING_CONTENT => "foo\\\n"
 6...12: tSTRING_CONTENT => "bar\\\n"
12...16: tSTRING_CONTENT => "baz\n"
16...17: tSTRING_END     => "'"
17...18: tNL             => nil
```
@Earlopain Earlopain force-pushed the parser-translator-tokens-line-cont-single-quotes branch from 5bc3727 to b6554ad Compare January 10, 2025 15:19
@kddnewton kddnewton merged commit 47c17b4 into ruby:main Jan 11, 2025
57 of 58 checks passed
@Earlopain Earlopain deleted the parser-translator-tokens-line-cont-single-quotes branch January 16, 2025 10:17
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