Skip to content

Fix heredoc #479

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

Merged
merged 2 commits into from
Aug 8, 2017
Merged

Fix heredoc #479

merged 2 commits into from
Aug 8, 2017

Conversation

aycabta
Copy link
Member

@aycabta aycabta commented Aug 3, 2017

The here-documents in middle of line are replaced with string literal. It's useful for IRB, but it doesn't fit for documentation.

For example,

def example
  puts [<<~TILDE, <<-HYPHEN, <<~'TILDE', <<-'HYPHEN', <<'AAA', <<"BBB", <<-`CCC`]
    a
      b
      c
    d
  TILDE
    1
      2
      3
    4
  HYPHEN
    w
      x
      y
    z
  TILDE
    1
      2
      3
    4
  HYPHEN
aaa
aa
a
AAA
bbb
bb
b
BBB
echo 'a'
echo 'b'
echo 'c'
CCC
end

MRI processes this code and outputs correctly. This is highlighted below:

<pre>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">example</span>
  <span class="ruby-identifier">puts</span> [<span class="ruby-operator">&lt;&lt;</span><span class="ruby-operator">~</span><span class="ruby-constant">TILDE</span>, <span class="ruby-string">&quot;    a
      b
      c
    d
  TILDE
    1
      2
      3
    4
&quot;</span>, <span class="ruby-operator">&lt;&lt;</span><span class="ruby-operator">~</span><span class="ruby-string">&#39;TILDE&#39;</span>, <span class="ruby-string">&quot;    w
      x
      y
    z
  TILDE
    1
      2
      3
    4
&quot;</span>, <span class="ruby-string">&quot;aaa
aa
a
&quot;</span>, <span class="ruby-string">&quot;bbb
bb
b
&quot;</span>, <span class="ruby-value">&quot;echo &#39;a&#39;
echo &#39;b&#39;
echo &#39;c&#39;
&quot;</span>]
<span class="ruby-keyword">end</span>
</pre>

extracted here-documents

I think this is broken document.

This Pull Request fixes it:

<pre>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">example</span>
  <span class="ruby-identifier">puts</span> [<span class="ruby-identifier">&lt;&lt;~TILDE</span>, <span class="ruby-identifier">&lt;&lt;-HYPHEN</span>, <span class="ruby-identifier">&lt;&lt;~&#39;TILDE&#39;</span>, <span class="ruby-identifier">&lt;&lt;-&#39;HYPHEN&#39;</span>, <span class="ruby-identifier">&lt;&lt;&#39;AAA&#39;</span>, <span class="ruby-identifier">&lt;&lt;&quot;BBB&quot;</span>, <span class="ruby-identifier">&lt;&lt;-`CCC`</span>]
<span class="ruby-value">    a
      b
      c
    d
</span><span class="ruby-identifier">  TILDE
</span><span class="ruby-value">    1
      2
      3
    4
</span><span class="ruby-identifier">  HYPHEN
</span><span class="ruby-value">    w
      x
      y
    z
</span><span class="ruby-identifier">  TILDE
</span><span class="ruby-value">    1
      2
      3
    4
</span><span class="ruby-identifier">  HYPHEN
</span><span class="ruby-value">aaa
aa
a
</span><span class="ruby-identifier">AAA
</span><span class="ruby-value">bbb
bb
b
</span><span class="ruby-identifier">BBB
</span><span class="ruby-value">echo &#39;a&#39;
echo &#39;b&#39;
echo &#39;c&#39;
</span><span class="ruby-identifier">CCC
</span><span class="ruby-keyword">end</span></pre>

correct code quotation

@aycabta aycabta force-pushed the fix-heredoc branch 2 times, most recently from 5dfd738 to cb9af76 Compare August 3, 2017 17:53
aycabta added 2 commits August 4, 2017 02:54
The here-documents in middle of line are replaced with string literal.
It's useful for IRB, but it doesn't fit for documentation.

For example,

def example
  puts [<<~TILDE, <<-HYPHEN, <<~'TILDE', <<-'HYPHEN', <<'AAA', <<"BBB",
<<-`CCC`]
    a
      b
      c
    d
  TILDE
    1
      2
      3
    4
  HYPHEN
    w
      x
      y
    z
  TILDE
    1
      2
      3
    4
  HYPHEN
aaa
aa
a
AAA
bbb
bb
b
BBB
echo 'a'
echo 'b'
echo 'c'
CCC
end

MRI processes this code and outputs correctly.
This is changed in documentation below:

def example
  puts [<<~TILDE, "    a
      b
      c
    d
  TILDE
    1
      2
      3
    4
", <<~'TILDE', "    w
      x
      y
    z
  TILDE
    1
      2
      3
    4
", "aaa
aa
a
", "bbb
bb
b
", "echo 'a'
echo 'b'
echo 'c'
"]
end

I think this is broken document.
This commit fixes it.
@hsbt hsbt self-assigned this Aug 5, 2017
@hsbt
Copy link
Member

hsbt commented Aug 8, 2017

I understood to reason why we need TkHEREDOCBEG and TkHEREDOCEND.

@hsbt hsbt merged commit b8fdc60 into ruby:master Aug 8, 2017
@aycabta aycabta deleted the fix-heredoc branch August 8, 2017 12:55
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