From 23863ff75d3ec9205d5f365b98b6608e38a93749 Mon Sep 17 00:00:00 2001 From: hsbt Date: Mon, 5 Sep 2016 10:35:30 +0000 Subject: * lib/rdoc/*, test/rdoc/*: Update rdoc/rdoc master(f191513) https://github.com/rdoc/rdoc/blob/master/History.rdoc#423--2016-- https://github.com/rdoc/rdoc/blob/master/History.rdoc#422--2016-02-09 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56072 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rdoc/parser/c.rb | 108 ++++++++++++++++++++++++++++++------------- lib/rdoc/parser/changelog.rb | 7 ++- 2 files changed, 81 insertions(+), 34 deletions(-) (limited to 'lib/rdoc/parser') diff --git a/lib/rdoc/parser/c.rb b/lib/rdoc/parser/c.rb index cd139441ba..087d56f7b9 100644 --- a/lib/rdoc/parser/c.rb +++ b/lib/rdoc/parser/c.rb @@ -606,18 +606,46 @@ class RDoc::Parser::C < RDoc::Parser RDoc::Comment.new comment, @top_level end + ## + # Generate a Ruby-method table + + def gen_body_table file_content + table = {} + file_content.scan(%r{ + ((?>/\*.*?\*/\s*)?) + ((?:(?:\w+)\s+)? + (?:intern\s+)?VALUE\s+(\w+) + \s*(?:\([^)]*\))(?:[^;]|$)) + | ((?>/\*.*?\*/\s*))^\s*(\#\s*define\s+(\w+)\s+(\w+)) + | ^\s*\#\s*define\s+(\w+)\s+(\w+) + }xm) do + case + when $1 + table[$3] = [:func_def, $1, $2, $~.offset(2)] if !table[$3] || table[$3][0] != :func_def + when $4 + table[$6] = [:macro_def, $4, $5, $~.offset(5), $7] if !table[$6] || table[$6][0] == :macro_alias + when $8 + table[$8] ||= [:macro_alias, $9] + end + end + table + end + ## # Find the C code corresponding to a Ruby method def find_body class_name, meth_name, meth_obj, file_content, quiet = false - case file_content - when %r%((?>/\*.*?\*/\s*)?) - ((?:(?:\w+)\s+)? - (?:intern\s+)?VALUE\s+#{meth_name} - \s*(\([^)]*\))([^;]|$))%xm then - comment = RDoc::Comment.new $1, @top_level - body = $2 - offset, = $~.offset(2) + if file_content + @body_table ||= {} + @body_table[file_content] ||= gen_body_table file_content + type, *args = @body_table[file_content][meth_name] + end + + case type + when :func_def + comment = RDoc::Comment.new args[0], @top_level + body = args[1] + offset, = args[2] comment.remove_private if comment @@ -646,12 +674,12 @@ class RDoc::Parser::C < RDoc::Parser meth_obj.line = file_content[0, offset].count("\n") + 1 body - when %r%((?>/\*.*?\*/\s*))^\s*(\#\s*define\s+#{meth_name}\s+(\w+))%m then - comment = RDoc::Comment.new $1, @top_level - body = $2 - offset = $~.offset(2).first + when :macro_def + comment = RDoc::Comment.new args[0], @top_level + body = args[1] + offset, = args[2] - find_body class_name, $3, meth_obj, file_content, true + find_body class_name, args[3], meth_obj, file_content, true comment.normalize find_modifiers comment, meth_obj @@ -665,11 +693,11 @@ class RDoc::Parser::C < RDoc::Parser meth_obj.line = file_content[0, offset].count("\n") + 1 body - when %r%^\s*\#\s*define\s+#{meth_name}\s+(\w+)%m then + when :macro_alias # with no comment we hope the aliased definition has it and use it's # definition - body = find_body(class_name, $1, meth_obj, file_content, true) + body = find_body(class_name, args[0], meth_obj, file_content, true) return body if body @@ -764,28 +792,42 @@ class RDoc::Parser::C < RDoc::Parser class_mod.add_comment comment, @top_level end + ## + # Generate a const table + + def gen_const_table file_content + table = {} + @content.scan(%r{ + ((?>^\s*/\*.*?\*/\s+)) + rb_define_(\w+)\((?:\s*(?:\w+),)?\s* + "(\w+)"\s*, + .*?\)\s*; + | Document-(?:const|global|variable):\s + ((?:\w+::)*\w+) + \s*?\n((?>.*?\*/)) + }mxi) do + case + when $1 then table[[$2, $3]] = $1 + when $4 then table[$4] = "/*\n" + $5 + end + end + table + end + ## # Finds a comment matching +type+ and +const_name+ either above the # comment or in the matching Document- section. def find_const_comment(type, const_name, class_name = nil) - comment = if @content =~ %r%((?>^\s*/\*.*?\*/\s+)) - rb_define_#{type}\((?:\s*(\w+),)?\s* - "#{const_name}"\s*, - .*?\)\s*;%xmi then - $1 - elsif class_name and - @content =~ %r%Document-(?:const|global|variable):\s - #{class_name}::#{const_name} - \s*?\n((?>.*?\*/))%xm then - "/*\n#{$1}" - elsif @content =~ %r%Document-(?:const|global|variable): - \s#{const_name} - \s*?\n((?>.*?\*/))%xm then - "/*\n#{$1}" - else - '' - end + @const_table ||= {} + @const_table[@content] ||= gen_const_table @content + table = @const_table[@content] + + comment = + table[[type, const_name]] || + (class_name && table[class_name + "::" + const_name]) || + table[const_name] || + '' RDoc::Comment.new comment, @top_level end @@ -841,7 +883,7 @@ class RDoc::Parser::C < RDoc::Parser comment = find_attr_comment var_name, attr_name comment.normalize - name = attr_name.gsub(/rb_intern\("([^"]+)"\)/, '\1') + name = attr_name.gsub(/rb_intern(?:_const)?\("([^"]+)"\)/, '\1') attr = RDoc::Attr.new '', name, rw, comment diff --git a/lib/rdoc/parser/changelog.rb b/lib/rdoc/parser/changelog.rb index 92c8d94ad6..c6c2d2bb23 100644 --- a/lib/rdoc/parser/changelog.rb +++ b/lib/rdoc/parser/changelog.rb @@ -102,9 +102,11 @@ class RDoc::Parser::ChangeLog < RDoc::Parser # Groups +entries+ by date. def group_entries entries + @time_cache ||= {} entries.group_by do |title, _| begin - Time.parse(title).strftime '%Y-%m-%d' + time = @time_cache[title] + (time || Time.parse(title)).strftime '%Y-%m-%d' rescue NoMethodError, ArgumentError time, = title.split ' ', 2 Time.parse(time).strftime '%Y-%m-%d' @@ -128,6 +130,7 @@ class RDoc::Parser::ChangeLog < RDoc::Parser # 'README.EXT.ja: ditto']] def parse_entries + @time_cache ||= {} entries = [] entry_name = nil entry_body = [] @@ -143,6 +146,7 @@ class RDoc::Parser::ChangeLog < RDoc::Parser begin time = Time.parse entry_name + @time_cache[entry_name] = time # HACK Ruby 1.8 does not raise ArgumentError for Time.parse "Other" entry_name = nil unless entry_name =~ /#{time.year}/ rescue NoMethodError @@ -185,6 +189,7 @@ class RDoc::Parser::ChangeLog < RDoc::Parser # Converts the ChangeLog into an RDoc::Markup::Document def scan + @time_cache = {} entries = parse_entries grouped_entries = group_entries entries -- cgit v1.2.3