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

- dedenter.rb: Fix squiggly heredoc line continuation handling #819

Conversation

mvz
Copy link
Contributor

@mvz mvz commented Sep 24, 2021

Firstly, this fixes an issue with non-interpolating squiggly heredocs, where line continuation characters should be ignored. Two things were broken:

  • The line continuation backslash would be removed, as well as the subsequent carriage return
  • The subsequent line would not be dedented.

For example, the following source:

<<~'END'
  foo \
  bar
END

Would be parsed as follows:

(dstr
  (str "foo ")
  (str "  bar\n"))

With the change, the result is:

(dstr
  (str "foo \\\n")
  (str "bar\n"))

This also fixes an issue with interpolating squiggly heredocs, where an escaped backslash followed by a newline would be interpreted as a line continuation. This is issue #789.

In that case, the following source:

<<~END
  foo \\
  bar
END

Would (again) be parsed as follows:

(dstr
  (str "foo ")
  (str "  bar\n"))

With the change, the result is:

(dstr
  (str "foo \\\n")
  (str "bar\n"))

Firstly, this fixes an issue with non-interpolating squiggly heredocs,
where line continuation characters should be ignored. Two things were
broken:

- The line continuation backslash would be removed, as well as the
  subsequent carriage return
- The subsequent line would not be dedented.

For example, the following source:

<<~'END'
  foo \
  bar
END

Would be parsed as follows:

(dstr
  (str "foo ")
  (str "  bar\n"))

With the change, the result is:

(dstr
  (str "foo \\\n")
  (str "bar\n"))

This also fixes an issue with interpolating squiggly heredocs, where an
escaped backslash followed by a newline would be interpreted as a line
continuation.

In that case, the following source:

<<~END
  foo \\
  bar
END

Would (again) be parsed as follows:

(dstr
  (str "foo ")
  (str "  bar\n"))

With the change, the result is:

(dstr
  (str "foo \\\n")
  (str "bar\n"))
Copy link
Collaborator

@iliabylich iliabylich left a comment

Choose a reason for hiding this comment

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

👍

@iliabylich iliabylich changed the title Fix squiggly heredoc line continuation handling - dedenter.rb: Fix squiggly heredoc line continuation handling Sep 24, 2021
@iliabylich iliabylich merged commit 61bf873 into whitequark:master Sep 24, 2021
@iliabylich
Copy link
Collaborator

@mvz Thanks!

@mvz mvz deleted the fix-non-interpolating-squiggly-heredoc-interpolation branch September 24, 2021 14:46
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