Permalink
Browse files

Parse c files for classes defined with rb_struct_define_without_acces…

…sor (like Range).
  • Loading branch information...
1 parent 06cc36d commit dee27a0d509f2563520b848be3f2fa186ca8e2bf @danbernier committed Oct 4, 2011
Showing with 25 additions and 0 deletions.
  1. +11 −0 lib/rdoc/parser/c.rb
  2. +14 −0 test/test_rdoc_parser_c.rb
View
11 lib/rdoc/parser/c.rb
@@ -230,6 +230,17 @@ def do_classes
handle_class_module(var_name, "class", class_name, parent, nil)
end
+ @content.scan(/([\w\.]+)\s* = \s*rb_struct_define_without_accessor\s*
+ \(
+ \s*"(\w+)", # Class name
+ \s*(\w+), # Parent class
+ \s*\w+, # Allocation function
+ (\s*"\w+",)* # Attributes
+ \s*NULL
+ \)/mx) do |var_name, class_name, parent|
+ handle_class_module(var_name, "class", class_name, parent, nil)
+ end
+
@content.scan(/(\w+)\s*=\s*boot_defclass\s*\(\s*"(\w+?)",\s*(\w+?)\s*\)/) do
|var_name, class_name, parent|
parent = nil if parent == "0"
View
14 test/test_rdoc_parser_c.rb
@@ -263,6 +263,20 @@ def test_do_classes_class
assert_equal "this is the Foo class", klass.comment.text
end
+ def test_do_classes_struct
+ content = <<-EOF
+/* Document-class: Foo
+ * this is the Foo class
+ */
+VALUE cFoo = rb_struct_define_without_accessor(
+ "Foo", rb_cObject, foo_alloc,
+ "some", "various", "fields", NULL);
+ EOF
+
+ klass = util_get_class content, 'cFoo'
+ assert_equal "this is the Foo class", klass.comment.text
+ end
+
def test_do_classes_class_under
content = <<-EOF
/* Document-class: Kernel::Foo

0 comments on commit dee27a0

Please sign in to comment.