Skip to content

Commit

Permalink
[ruby/rdoc] Fix support for rb_file_const and rb_curses_define_const
Browse files Browse the repository at this point in the history
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 ruby/rdoc#1067

ruby/rdoc@cdad51a60b
  • Loading branch information
nobu authored and hsbt committed Dec 25, 2023
1 parent e55a57a commit e324953
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
26 changes: 18 additions & 8 deletions lib/rdoc/parser/c.rb
Expand Up @@ -756,17 +756,27 @@ def find_class_comment class_name, class_mod
def gen_const_table file_content
table = {}
@content.scan(%r{
((?>^\s*/\*.*?\*/\s+))
rb_define_(\w+)\((?:\s*(?:\w+),)?\s*
"(\w+)"\s*,
(?<doc>(?>^\s*/\*.*?\*/\s+))
rb_define_(?<type>\w+)\(\s*(?:\w+),\s*
"(?<name>\w+)"\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
((?:\w+::)*\w+)
\s*?\n((?>.*?\*/))
(?<name>(?:\w+::)*\w+)
\s*?\n(?<doc>(?>.*?\*/))
}mxi) do
case
when $1 then table[[$2, $3]] = $1
when $4 then table[$4] = "/*\n" + $5
name, doc, type = $~.values_at(:name, :doc, :type)
if type
table[[type, name]] = doc
else
table[name] = "/*\n" + doc
end
end
table
Expand Down
5 changes: 1 addition & 4 deletions test/rdoc/test_rdoc_parser_c.rb
Expand Up @@ -583,8 +583,6 @@ def test_do_constants_curses
mCurses = rb_define_module("Curses");
/*
* Document-const: Curses::COLOR_BLACK
*
* Value of the color black
*/
rb_curses_define_const(COLOR_BLACK);
Expand All @@ -609,8 +607,7 @@ def test_do_constants_curses
def test_do_constants_file
content = <<-EOF
void Init_File(void) {
/* Document-const: LOCK_SH
*
/*
* Shared lock
*/
rb_file_const("LOCK_SH", INT2FIX(LOCK_SH));
Expand Down

0 comments on commit e324953

Please sign in to comment.