Skip to content

Commit

Permalink
Allow any single-word token upto 2 before C method implementation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nobu committed Dec 5, 2023
1 parent 9b27b08 commit 01b82e9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/rdoc/parser/c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions test/rdoc/test_rdoc_parser_c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 01b82e9

Please sign in to comment.