From a86d4eef4b4551a48a5329bb993c3c6c39a1b1f3 Mon Sep 17 00:00:00 2001 From: aycabta Date: Tue, 22 Jan 2019 04:46:46 +0900 Subject: [ruby/rdoc] Normalization of comment should check language RDoc::Text#normalize_comment that is included RDoc::Comment always remove Ruby style comment indicator "#" and C style comment indicator "/**/", but should check language and remove only the language's comment indicator. https://github.com/ruby/rdoc/commit/ca68ba1e73 --- lib/rdoc/comment.rb | 3 ++- lib/rdoc/parser/c.rb | 18 +++++++++--------- lib/rdoc/parser/ruby.rb | 2 +- lib/rdoc/text.rb | 10 ++++++++-- 4 files changed, 20 insertions(+), 13 deletions(-) (limited to 'lib/rdoc') diff --git a/lib/rdoc/comment.rb b/lib/rdoc/comment.rb index 0f643c45b9..35cacdd087 100644 --- a/lib/rdoc/comment.rb +++ b/lib/rdoc/comment.rb @@ -48,9 +48,10 @@ class RDoc::Comment # Creates a new comment with +text+ that is found in the RDoc::TopLevel # +location+. - def initialize text = nil, location = nil + def initialize text = nil, location = nil, language = nil @location = location @text = text.nil? ? nil : text.dup + @language = language @document = nil @format = 'rdoc' diff --git a/lib/rdoc/parser/c.rb b/lib/rdoc/parser/c.rb index c51e2f6365..5cc009e499 100644 --- a/lib/rdoc/parser/c.rb +++ b/lib/rdoc/parser/c.rb @@ -446,7 +446,7 @@ class RDoc::Parser::C < RDoc::Parser next unless cls = @classes[c] m = @known_classes[m] || m - comment = RDoc::Comment.new '', @top_level + comment = RDoc::Comment.new '', @top_level, :c incl = cls.add_include RDoc::Include.new(m, comment) incl.record_location @top_level end @@ -564,7 +564,7 @@ class RDoc::Parser::C < RDoc::Parser \s*"#{Regexp.escape new_name}"\s*, \s*"#{Regexp.escape old_name}"\s*\);%xm - RDoc::Comment.new($1 || '', @top_level) + RDoc::Comment.new($1 || '', @top_level, :c) end ## @@ -603,7 +603,7 @@ class RDoc::Parser::C < RDoc::Parser '' end - RDoc::Comment.new comment, @top_level + RDoc::Comment.new comment, @top_level, :c end ## @@ -643,7 +643,7 @@ class RDoc::Parser::C < RDoc::Parser case type when :func_def - comment = RDoc::Comment.new args[0], @top_level + comment = RDoc::Comment.new args[0], @top_level, :c body = args[1] offset, = args[2] @@ -673,7 +673,7 @@ class RDoc::Parser::C < RDoc::Parser body when :macro_def - comment = RDoc::Comment.new args[0], @top_level + comment = RDoc::Comment.new args[0], @top_level, :c body = args[1] offset, = args[2] @@ -780,7 +780,7 @@ class RDoc::Parser::C < RDoc::Parser comment = '' end - comment = RDoc::Comment.new comment, @top_level + comment = RDoc::Comment.new comment, @top_level, :c comment.normalize look_for_directives_in class_mod, comment @@ -825,7 +825,7 @@ class RDoc::Parser::C < RDoc::Parser table[const_name] || '' - RDoc::Comment.new comment, @top_level + RDoc::Comment.new comment, @top_level, :c end ## @@ -856,7 +856,7 @@ class RDoc::Parser::C < RDoc::Parser return unless comment - RDoc::Comment.new comment, @top_level + RDoc::Comment.new comment, @top_level, :c end ## @@ -990,7 +990,7 @@ class RDoc::Parser::C < RDoc::Parser new_comment = "#{$1}#{new_comment.lstrip}" - new_comment = RDoc::Comment.new new_comment, @top_level + new_comment = RDoc::Comment.new new_comment, @top_level, :c con = RDoc::Constant.new const_name, new_definition, new_comment else diff --git a/lib/rdoc/parser/ruby.rb b/lib/rdoc/parser/ruby.rb index 97399f87ff..8da19cf2e2 100644 --- a/lib/rdoc/parser/ruby.rb +++ b/lib/rdoc/parser/ruby.rb @@ -667,7 +667,7 @@ class RDoc::Parser::Ruby < RDoc::Parser # Creates a comment with the correct format def new_comment comment - c = RDoc::Comment.new comment, @top_level + c = RDoc::Comment.new comment, @top_level, :ruby c.format = @markup c end diff --git a/lib/rdoc/text.rb b/lib/rdoc/text.rb index 22c3777ff9..c3218fdb2f 100644 --- a/lib/rdoc/text.rb +++ b/lib/rdoc/text.rb @@ -10,6 +10,8 @@ require 'strscan' module RDoc::Text + attr_accessor :language + ## # Maps markup formats to classes that can parse them. If the format is # unknown, "rdoc" format is used. @@ -111,8 +113,12 @@ module RDoc::Text def normalize_comment text return text if text.empty? - text = strip_stars text - text = strip_hashes text + case language + when :ruby + text = strip_hashes text + when :c + text = strip_stars text + end text = expand_tabs text text = flush_left text text = strip_newlines text -- cgit v1.2.3