Fix line continuations in literals #3362
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Port of whitequark/parser#539.
This PR introduces a few changes in how literal with the
\\\n
continuation are parsed.Heredoc changes
All variations of the non-plain heredoc like
HERE
,"HERE"
,`HERE`
Are now correctly parsed as
s(:str, "ab\n")
instead ofs(:str, "a\nb\n")
.This apply also for the squiggly heredoc non-plain variations:
That is now parsed as
s(:str, "a b\n")
instead ofs(:str, "a\n b\n")
(note that we still have a bug in the dedenting of the heredoc but this can be fixed independently from this PR).Plain
'HERE"
is unchanged.Literal strings changes
Lines continuations are correctly parsed for interpolated strings,
" "
,%{ }
and%Q{ }
:Now returns
s(:str, "ab")
instead ofs(:str, "a\nb\n")
.Plain strings with
' '
and%q{ }
are unchanged.Literal symbols changes
Lines continuations are correctly parsed for symbols:
Now returns
s(:sym, :ab)
instead ofs(:sym, :a\nb)
.Literal arrays of symbols (interpolated or not) are unchanged.
Literal shell commands changes
Lines continuations are correctly parsed for shell commands:
Now returns
s(:xstr, s(:str, "ab")))
instead ofs(:xstr, s(:str, "a\nb")))
.Test plan
See included automated tests.