[ruby/rdoc] Fix support for rb_file_const and rb_curses_define_const

Constant definitions using these functions have been supported, but
since RDoc::Parser::C#gen_const_table did not consider other than
`rb_define_const` the documents for them have not been found, without
`Document-const` direvtive.

Fixes https://github.com/ruby/rdoc/issues/1067

https://github.com/ruby/rdoc/commit/cdad51a60b
This commit is contained in:
Nobuyoshi Nakada 2023-12-19 16:21:50 +09:00 committed by Hiroshi SHIBATA
parent e55a57af1e
commit e324953090
2 changed files with 19 additions and 12 deletions

View File

@ -756,17 +756,27 @@ class RDoc::Parser::C < RDoc::Parser
def gen_const_table file_content def gen_const_table file_content
table = {} table = {}
@content.scan(%r{ @content.scan(%r{
((?>^\s*/\*.*?\*/\s+)) (?<doc>(?>^\s*/\*.*?\*/\s+))
rb_define_(\w+)\((?:\s*(?:\w+),)?\s* rb_define_(?<type>\w+)\(\s*(?:\w+),\s*
"(\w+)"\s*, "(?<name>\w+)"\s*,
.*?\)\s*; .*?\)\s*;
| (?<doc>(?>^\s*/\*.*?\*/\s+))
rb_file_(?<type>const)\(\s*
"(?<name>\w+)"\s*,
.*?\)\s*;
| (?<doc>(?>^\s*/\*.*?\*/\s+))
rb_curses_define_(?<type>const)\(\s*
(?<name>\w+)
\s*\)\s*;
| Document-(?:const|global|variable):\s | Document-(?:const|global|variable):\s
((?:\w+::)*\w+) (?<name>(?:\w+::)*\w+)
\s*?\n((?>.*?\*/)) \s*?\n(?<doc>(?>.*?\*/))
}mxi) do }mxi) do
case name, doc, type = $~.values_at(:name, :doc, :type)
when $1 then table[[$2, $3]] = $1 if type
when $4 then table[$4] = "/*\n" + $5 table[[type, name]] = doc
else
table[name] = "/*\n" + doc
end end
end end
table table

View File

@ -583,8 +583,6 @@ void Init_curses(){
mCurses = rb_define_module("Curses"); mCurses = rb_define_module("Curses");
/* /*
* Document-const: Curses::COLOR_BLACK
*
* Value of the color black * Value of the color black
*/ */
rb_curses_define_const(COLOR_BLACK); rb_curses_define_const(COLOR_BLACK);
@ -609,8 +607,7 @@ void Init_curses(){
def test_do_constants_file def test_do_constants_file
content = <<-EOF content = <<-EOF
void Init_File(void) { void Init_File(void) {
/* Document-const: LOCK_SH /*
*
* Shared lock * Shared lock
*/ */
rb_file_const("LOCK_SH", INT2FIX(LOCK_SH)); rb_file_const("LOCK_SH", INT2FIX(LOCK_SH));