Skip to content

Commit 4b690c5

Browse files
authored
Merge pull request #642 from aycabta/support-mutable-immutable-heredoc
Support mutable/immutable heredoc
2 parents 731c541 + a41d9b9 commit 4b690c5

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/rdoc/parser/ripper_state_lex.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,10 @@ def get_squashed_tk
555555
tk[:text] += tk_ahead[:text]
556556
tk[:kind] = tk_ahead[:kind]
557557
tk[:state] = tk_ahead[:state]
558+
when :on_heredoc_beg, :on_tstring, :on_dstring # frozen/non-frozen string literal
559+
tk[:text] += tk_ahead[:text]
560+
tk[:kind] = tk_ahead[:kind]
561+
tk[:state] = tk_ahead[:state]
558562
else
559563
@buf.unshift tk_ahead
560564
end

test/test_rdoc_parser_ruby.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2848,6 +2848,35 @@ def blah()
28482848
assert_equal expected, markup_code
28492849
end
28502850

2851+
def test_parse_mutable_heredocbeg
2852+
@filename = 'file.rb'
2853+
util_parser <<RUBY
2854+
class Foo
2855+
def blah()
2856+
@str = -<<-EOM
2857+
EOM
2858+
end
2859+
end
2860+
RUBY
2861+
2862+
expected = <<EXPECTED
2863+
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">blah</span>()
2864+
<span class="ruby-ivar">@str</span> = <span class="ruby-identifier">-&lt;&lt;-EOM</span>
2865+
<span class="ruby-value"></span><span class="ruby-identifier"> EOM</span>
2866+
<span class="ruby-keyword">end</span>
2867+
EXPECTED
2868+
expected = expected.rstrip
2869+
2870+
@parser.scan
2871+
2872+
foo = @top_level.classes.first
2873+
assert_equal 'Foo', foo.full_name
2874+
2875+
blah = foo.method_list.first
2876+
markup_code = blah.markup_code.sub(/^.*\n/, '')
2877+
assert_equal expected, markup_code
2878+
end
2879+
28512880
def test_parse_statements_method_oneliner_with_regexp
28522881
util_parser <<RUBY
28532882
class Foo

0 commit comments

Comments
 (0)