diff --git a/lib/rdoc/parser/ruby.rb b/lib/rdoc/parser/ruby.rb index a90622f0f3..97bb5c279f 100644 --- a/lib/rdoc/parser/ruby.rb +++ b/lib/rdoc/parser/ruby.rb @@ -249,10 +249,11 @@ def collect_first_comment tk = get_tk while tk && (:on_comment == tk[:kind] or :on_embdoc == tk[:kind]) - if first_line and tk[:text] =~ /\A#!/ then + comment_body = retrieve_comment_body(tk) + if first_line and comment_body =~ /\A#!/ then skip_tkspace tk = get_tk - elsif first_line and tk[:text] =~ /\A#\s*-\*-/ then + elsif first_line and comment_body =~ /\A#\s*-\*-/ then first_line = false skip_tkspace tk = get_tk @@ -261,7 +262,7 @@ def collect_first_comment first_comment_tk_kind = tk[:kind] first_line = false - comment << tk[:text] + comment << comment_body tk = get_tk if :on_nl === tk then @@ -1654,6 +1655,17 @@ def parse_rescue end end + ## + # Retrieve comment body without =begin/=end + + def retrieve_comment_body(tk) + if :on_embdoc == tk[:kind] + tk[:text].gsub(/\A=begin.*\n/, '').gsub(/=end\n?\z/, '') + else + tk[:text] + end + end + ## # The core of the Ruby parser. @@ -1707,10 +1719,11 @@ def parse_statements(container, single = NORMAL, current_method = nil, end while tk and (:on_comment == tk[:kind] or :on_embdoc == tk[:kind]) do - comment += tk[:text] - comment += "\n" unless "\n" == tk[:text].chars.to_a.last + comment_body = retrieve_comment_body(tk) + comment += comment_body + comment += "\n" unless "\n" == comment_body.chars.to_a.last - if tk[:text].size > 1 && "\n" == tk[:text].chars.to_a.last then + if comment_body.size > 1 && "\n" == comment_body.chars.to_a.last then skip_tkspace false # leading spaces end tk = get_tk diff --git a/test/test_rdoc_parser_ruby.rb b/test/test_rdoc_parser_ruby.rb index dbe05be704..76bdcf546a 100644 --- a/test/test_rdoc_parser_ruby.rb +++ b/test/test_rdoc_parser_ruby.rb @@ -73,7 +73,7 @@ class C; end comment = parser.collect_first_comment - assert_equal RDoc::Comment.new("=begin\nfirst\n=end\n", @top_level), comment + assert_equal RDoc::Comment.new("first\n", @top_level), comment end def test_get_class_or_module @@ -3349,11 +3349,11 @@ def m() end foo = @top_level.classes.first - assert_equal "=begin rdoc\nFoo comment\n=end", foo.comment.text + assert_equal 'Foo comment', foo.comment.text m = foo.method_list.first - assert_equal "=begin\nm comment\n=end", m.comment.text + assert_equal 'm comment', m.comment.text end def test_scan_block_comment_nested # Issue #41 @@ -3375,7 +3375,7 @@ class Bar foo = @top_level.modules.first assert_equal 'Foo', foo.full_name - assert_equal "=begin rdoc\nfindmeindoc\n=end", foo.comment.text + assert_equal 'findmeindoc', foo.comment.text bar = foo.classes.first @@ -3423,12 +3423,12 @@ def lauren foo = @top_level.classes.first - assert_equal "=begin rdoc\n\n= DESCRIPTION\n\nThis is a simple test class\n\n= RUMPUS\n\nIs a silly word\n\n=end", + assert_equal "= DESCRIPTION\n\nThis is a simple test class\n\n= RUMPUS\n\nIs a silly word", foo.comment.text m = foo.method_list.first - assert_equal "=begin rdoc\nA nice girl\n=end", m.comment.text + assert_equal 'A nice girl', m.comment.text end def test_scan_class_nested_nodoc