From e1799974f0393d5b49d92279fcc23936474a5603 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 19 Dec 2023 16:21:50 +0900 Subject: [PATCH] [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 --- lib/rdoc/parser/c.rb | 26 ++++++++++++++++++-------- test/rdoc/test_rdoc_parser_c.rb | 5 +---- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/rdoc/parser/c.rb b/lib/rdoc/parser/c.rb index d668507dc201af..f8f238fd74906b 100644 --- a/lib/rdoc/parser/c.rb +++ b/lib/rdoc/parser/c.rb @@ -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*, + (?(?>^\s*/\*.*?\*/\s+)) + rb_define_(?\w+)\(\s*(?:\w+),\s* + "(?\w+)"\s*, .*?\)\s*; + | (?(?>^\s*/\*.*?\*/\s+)) + rb_file_(?const)\(\s* + "(?\w+)"\s*, + .*?\)\s*; + | (?(?>^\s*/\*.*?\*/\s+)) + rb_curses_define_(?const)\(\s* + (?\w+) + \s*\)\s*; | Document-(?:const|global|variable):\s - ((?:\w+::)*\w+) - \s*?\n((?>.*?\*/)) + (?(?:\w+::)*\w+) + \s*?\n(?(?>.*?\*/)) }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 diff --git a/test/rdoc/test_rdoc_parser_c.rb b/test/rdoc/test_rdoc_parser_c.rb index 10bd7f55244e83..ab4f149869c3c8 100644 --- a/test/rdoc/test_rdoc_parser_c.rb +++ b/test/rdoc/test_rdoc_parser_c.rb @@ -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); @@ -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));