From 4e6f681b40d237c70671c6b3e831a9ad1e7fb26d Mon Sep 17 00:00:00 2001 From: drbrain Date: Sun, 31 Dec 2006 21:13:27 +0000 Subject: Allow RDoc comment to give friendly value for rb_define_const. Patch by Daniel Berger , [ruby-patches-7499]. Fix whitespace handling in constant comments. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11443 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rdoc/parsers/parse_c.rb | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'lib/rdoc') diff --git a/lib/rdoc/parsers/parse_c.rb b/lib/rdoc/parsers/parse_c.rb index a1ea9a5da7..e4c4a4a0f5 100644 --- a/lib/rdoc/parsers/parse_c.rb +++ b/lib/rdoc/parsers/parse_c.rb @@ -95,7 +95,8 @@ require "rdoc/code_objects" require "rdoc/parsers/parserfactory" - +require "rdoc/options" +require "rdoc/rdoc" module RDoc @@ -165,6 +166,7 @@ module RDoc class C_Parser + attr_accessor :progress extend ParserFactory parse_files_matching(/\.(c|cc|cpp|CC)$/) @@ -444,14 +446,37 @@ module RDoc comment = find_const_comment(type, const_name) - con = Constant.new(const_name, definition, mangle_comment(comment)) + # In the case of rb_define_const, the definition and comment are in + # "/* definition: comment */" form. The literal ':' and '\' characters + # can be escaped with a backslash. + if type.downcase == 'const' then + elements = mangle_comment(comment).split(':') + if elements.nil? or elements.empty? then + con = Constant.new(const_name, definition, mangle_comment(comment)) + else + new_definition = elements[0..-2].join(':') + if new_definition.empty? then # Default to literal C definition + new_definition = definition + else + new_definition.gsub!("\:", ":") + new_definition.gsub!("\\", '\\') + end + new_definition.sub!(/\A(\s+)/, '') + new_comment = $1.nil? ? elements.last : "#{$1}#{elements.last.lstrip}" + con = Constant.new(const_name, new_definition, + mangle_comment(new_comment)) + end + else + con = Constant.new(const_name, definition, mangle_comment(comment)) + end + class_obj.add_constant(con) end ########################################################### def find_const_comment(type, const_name) - if @body =~ %r{((?>/\*.*?\*/\s+)) + if @body =~ %r{((?>^\s*/\*.*?\*/\s+)) rb_define_#{type}\((?:\s*(\w+),)?\s*"#{const_name}"\s*,.*?\)\s*;}xmi $1 elsif @body =~ %r{Document-(?:const|global|variable):\s#{const_name}\s*?\n((?>.*?\*/))}m -- cgit v1.2.3