Adds constant comments. By providing some_value: at the start ofthe
comment you can override the C value of the comment to give a friendly
definition.
/* 300: The perfect score in bowling */rb_define_const(cFoo,"PERFECT",INT2FIX(300);
Will override +INT2FIX(300)+ with the value 300 in the output RDoc. Values may include quotes and escaped colons
(:).
# File lib/rdoc/parsers/parse_c.rb, line 477
def handle_constants(type, var_name, const_name, definition)
#@stats.num_constants += 1
class_name = @known_classes[var_name]
return unless class_name
class_obj = find_class(var_name, class_name)
unless class_obj
warn("Enclosing class/module '#{const_name}' for not known")
return
end
comment = find_const_comment(type, const_name)
# 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