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

Fix line continuations in literals #3362

Merged
merged 2 commits into from
Sep 11, 2020

Conversation

Morriar
Copy link
Collaborator

@Morriar Morriar commented Aug 13, 2020

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`

<<-HERE
a\
b
HERE

Are now correctly parsed as s(:str, "ab\n") instead of s(:str, "a\nb\n").

This apply also for the squiggly heredoc non-plain variations:

<<~HERE
  a\
  b
HERE

That is now parsed as s(:str, "a b\n") instead of s(: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{ }:

a\
b

Now returns s(:str, "ab") instead of s(:str, "a\nb\n").

Plain strings with ' ' and %q{ } are unchanged.

Literal symbols changes

Lines continuations are correctly parsed for symbols:

:a\
b

Now returns s(:sym, :ab) instead of s(:sym, :a\nb).

Literal arrays of symbols (interpolated or not) are unchanged.

Literal shell commands changes

Lines continuations are correctly parsed for shell commands:

`a\
b`

Now returns s(:xstr, s(:str, "ab"))) instead of s(:xstr, s(:str, "a\nb"))).

Test plan

See included automated tests.

@Morriar Morriar requested a review from a team as a code owner August 13, 2020 18:01
@Morriar Morriar requested review from jez and removed request for a team August 13, 2020 18:01
@Morriar Morriar mentioned this pull request Aug 13, 2020
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
@jez
Copy link
Collaborator

jez commented Sep 11, 2020

We have a policy of testing changes to Sorbet against Stripe's codebase before
merging them. I've kicked off a test run for the current PR. When the build
finishes, I'll share with you whether or how it failed. Thanks!

Stripe employees can see the build result here:

https://go/builds/bui_HzznrNppbUr6A5

@jez jez merged commit dd082f4 into sorbet:master Sep 11, 2020
@Morriar Morriar deleted the at-fix-line-continuations branch September 11, 2020 14:16
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.

None yet

2 participants