1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Allow RDoc comment to give friendly value for rb_define_const.

Patch by Daniel Berger <djberg96 at gmail.com>, [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
This commit is contained in:
drbrain 2006-12-31 21:13:27 +00:00
parent a3e1b1ce7e
commit 4e6f681b40
3 changed files with 184 additions and 3 deletions

View file

@ -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