summaryrefslogtreecommitdiff
path: root/lib/rdoc
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-12-31 21:13:27 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-12-31 21:13:27 +0000
commit4e6f681b40d237c70671c6b3e831a9ad1e7fb26d (patch)
tree9f23562f891ebff723ccb8060361907210717b98 /lib/rdoc
parenta3e1b1ce7ed7e7ffac23015fc2fde56511b30681 (diff)
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
Diffstat (limited to 'lib/rdoc')
-rw-r--r--lib/rdoc/parsers/parse_c.rb31
1 files changed, 28 insertions, 3 deletions
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