From 01b82e9790dbaa0b553ae3566b0a6ae9f9919e56 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 5 Dec 2023 13:22:27 +0900 Subject: [PATCH] Allow any single-word token upto 2 before C method implementation Previously only unknown word `intern` is allowed between a single-word token before a C method. Now any single-word token, such as `inline` which is used for `ArithmeticSequence` in enumerator.c, is allowed instead. --- lib/rdoc/parser/c.rb | 5 ++--- test/rdoc/test_rdoc_parser_c.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/lib/rdoc/parser/c.rb b/lib/rdoc/parser/c.rb index 57d802266b..d4480d0bdd 100644 --- a/lib/rdoc/parser/c.rb +++ b/lib/rdoc/parser/c.rb @@ -575,9 +575,8 @@ def gen_body_table file_content table = {} file_content.scan(%r{ ((?>/\*.*?\*/\s*)?) - ((?:(?:\w+)\s+)? - (?:intern\s+)?VALUE\s+(\w+) - \s*(?:\([^)]*\))(?:[^\);]|$)) + ((?:\w+\s+){0,2} VALUE\s+(\w+) + \s*(?:\([^\)]*\))(?:[^\);]|$)) | ((?>/\*.*?\*/\s*))^\s*(\#\s*define\s+(\w+)\s+(\w+)) | ^\s*\#\s*define\s+(\w+)\s+(\w+) }xm) do diff --git a/test/rdoc/test_rdoc_parser_c.rb b/test/rdoc/test_rdoc_parser_c.rb index ed3a18e45f..4550972034 100644 --- a/test/rdoc/test_rdoc_parser_c.rb +++ b/test/rdoc/test_rdoc_parser_c.rb @@ -1373,6 +1373,36 @@ def test_find_body_macro assert_equal "DLL_LOCAL VALUE\nother_function() {\n}", code end + def test_find_body_static_inline + content = <<-EOF +/* + * a comment for other_function + */ +static inline VALUE +other_function() { +} + +void +Init_Foo(void) { + VALUE foo = rb_define_class("Foo", rb_cObject); + + rb_define_method(foo, "my_method", other_function, 0); +} + EOF + + klass = util_get_class content, 'foo' + other_function = klass.method_list.first + + assert_equal 'my_method', other_function.name + assert_equal "a comment for other_function", + other_function.comment.text + assert_equal '()', other_function.params + + code = other_function.token_stream.first[:text] + + assert_equal "static inline VALUE\nother_function() {\n}", code + end + def test_find_modifiers_call_seq comment = RDoc::Comment.new <<-COMMENT call-seq: