Skip to content

Commit cdad51a

Browse files
committed
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 #1067
1 parent 895f1af commit cdad51a

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

lib/rdoc/parser/c.rb

+18-8
Original file line numberDiff line numberDiff line change
@@ -756,17 +756,27 @@ def find_class_comment class_name, class_mod
756756
def gen_const_table file_content
757757
table = {}
758758
@content.scan(%r{
759-
((?>^\s*/\*.*?\*/\s+))
760-
rb_define_(\w+)\((?:\s*(?:\w+),)?\s*
761-
"(\w+)"\s*,
759+
(?<doc>(?>^\s*/\*.*?\*/\s+))
760+
rb_define_(?<type>\w+)\(\s*(?:\w+),\s*
761+
"(?<name>\w+)"\s*,
762762
.*?\)\s*;
763+
| (?<doc>(?>^\s*/\*.*?\*/\s+))
764+
rb_file_(?<type>const)\(\s*
765+
"(?<name>\w+)"\s*,
766+
.*?\)\s*;
767+
| (?<doc>(?>^\s*/\*.*?\*/\s+))
768+
rb_curses_define_(?<type>const)\(\s*
769+
(?<name>\w+)
770+
\s*\)\s*;
763771
| Document-(?:const|global|variable):\s
764-
((?:\w+::)*\w+)
765-
\s*?\n((?>.*?\*/))
772+
(?<name>(?:\w+::)*\w+)
773+
\s*?\n(?<doc>(?>.*?\*/))
766774
}mxi) do
767-
case
768-
when $1 then table[[$2, $3]] = $1
769-
when $4 then table[$4] = "/*\n" + $5
775+
name, doc, type = $~.values_at(:name, :doc, :type)
776+
if type
777+
table[[type, name]] = doc
778+
else
779+
table[name] = "/*\n" + doc
770780
end
771781
end
772782
table

test/rdoc/test_rdoc_parser_c.rb

+1-4
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,6 @@ def test_do_constants_curses
583583
mCurses = rb_define_module("Curses");
584584
585585
/*
586-
* Document-const: Curses::COLOR_BLACK
587-
*
588586
* Value of the color black
589587
*/
590588
rb_curses_define_const(COLOR_BLACK);
@@ -609,8 +607,7 @@ def test_do_constants_curses
609607
def test_do_constants_file
610608
content = <<-EOF
611609
void Init_File(void) {
612-
/* Document-const: LOCK_SH
613-
*
610+
/*
614611
* Shared lock
615612
*/
616613
rb_file_const("LOCK_SH", INT2FIX(LOCK_SH));

0 commit comments

Comments
 (0)