rdoc and GNU-indented files

I

Ian Macdonald

Hello,

I've just noticed that running C source files through a default
configuration of GNU indent breaks the ability of rdoc to find classes
and methods in them.

The thing is, I can't figure out what the parser is running aground on?

Has anyone run into this before?

Ian
--
Ian Macdonald | It is far more impressive when others
System Administrator | discover your good qualities without your
(e-mail address removed) | help. -- Miss Manners
http://www.caliban.org |
|
 
G

Garrett Rooney

--------------010405090400070705070908
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Ian said:
Hello,

I've just noticed that running C source files through a default
configuration of GNU indent breaks the ability of rdoc to find classes
and methods in them.

The thing is, I can't figure out what the parser is running aground on?

Has anyone run into this before?

It's quite likely spaces between a function name and the following
parentheses, GNU style recommends that, so I imagine indent might
default to it, and I know it screws up rdoc. I cooked up the following
patch a while back to correct the issue, no idea if it applies to
current releases or not, I think it was against CVS HEAD at the time.

-garrett

--------------010405090400070705070908
Content-Type: text/plain;
name="rdoc-space-before-paren.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="rdoc-space-before-paren.diff"

? rdoc-space-before-paren.diff
Index: lib/rdoc/parsers/parse_c.rb
===================================================================
RCS file: /src/ruby/lib/rdoc/parsers/parse_c.rb,v
retrieving revision 1.25
diff -u -r1.25 parse_c.rb
--- lib/rdoc/parsers/parse_c.rb 9 Sep 2004 02:47:35 -0000 1.25
+++ lib/rdoc/parsers/parse_c.rb 8 Jan 2005 19:17:02 -0000
@@ -249,13 +249,13 @@
############################################################

def do_classes
- @body.scan(/(\w+)\s* = \s*rb_define_module\(\s*"(\w+)"\s*\)/mx) do
+ @body.scan(/(\w+)\s* = \s*rb_define_module\s*\(\s*"(\w+)"\s*\)/mx) do
|var_name, class_name|
handle_class_module(var_name, "module", class_name, nil, nil)
end

# The '.' lets us handle SWIG-generated files
- @body.scan(/([\w\.]+)\s* = \s*rb_define_class
+ @body.scan(/([\w\.]+)\s* = \s*rb_define_class\s*
\(
\s*"(\w+)",
\s*(\w+)\s*
@@ -265,7 +265,7 @@
handle_class_module(var_name, "class", class_name, parent, nil)
end

- @body.scan(/(\w+)\s*=\s*boot_defclass\(\s*"(\w+?)",\s*(\w+?)\)/) do
+ @body.scan(/(\w+)\s*=\s*boot_defclass\s*\(\s*"(\w+?)",\s*(\w+?)\)/) do
|var_name, class_name, parent|
parent = nil if parent == "0"
handle_class_module(var_name, "class", class_name, parent, nil)
@@ -281,7 +281,7 @@
handle_class_module(var_name, "module", class_name, nil, in_module)
end

- @body.scan(/([\w\.]+)\s* = \s*rb_define_class_under
+ @body.scan(/([\w\.]+)\s* = \s*rb_define_class_under\s*
\(
\s*(\w+),
\s*"(\w+)",
@@ -304,7 +304,7 @@
method |
module_function |
private_method
- )
+ )\s*
\(\s*([\w\.]+),
\s*"([^"]+)",
\s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\()?(\w+)\)?,
@@ -325,7 +325,7 @@
meth_body, param_count, source_file)
end

- @body.scan(%r{rb_define_global_function\(
+ @body.scan(%r{rb_define_global_function\s*\(
\s*"([^"]+)",
\s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\()?(\w+)\)?,
\s*(-?\w+)\s*\)
@@ -336,7 +336,7 @@
meth_body, param_count, source_file)
end

- @body.scan(/define_filetest_function\(
+ @body.scan(/define_filetest_function\s*\(
\s*"([^"]+)",
\s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\()?(\w+)\)?,
\s*(-?\w+)\s*\)/xm) do #"
@@ -350,7 +350,7 @@
############################################################

def do_aliases
- @body.scan(%r{rb_define_alias\(\s*(\w+),\s*"([^"]+)",\s*"([^"]+)"\s*\)}m) do
+ @body.scan(%r{rb_define_alias\s*\(\s*(\w+),\s*"([^"]+)",\s*"([^"]+)"\s*\)}m) do
|var_name, new_name, old_name|
@stats.num_methods += 1
class_name = @known_classes[var_name] || var_name
@@ -482,7 +482,7 @@
# Look for includes of the form
# rb_include_module(rb_cArray, rb_mEnumerable);
def do_includes
- @body.scan(/rb_include_module\(\s*(\w+?),\s*(\w+?)\s*\)/) do |c,m|
+ @body.scan(/rb_include_module\s*\(\s*(\w+?),\s*(\w+?)\s*\)/) do |c,m|
if cls = @classes[c]
m = KNOWN_CLASSES[m] || m
cls.add_include(Include.new(m, ""))

--------------010405090400070705070908--
 
I

Ian Macdonald

It's quite likely spaces between a function name and the following
parentheses, GNU style recommends that, so I imagine indent might
default to it, and I know it screws up rdoc. I cooked up the following
patch a while back to correct the issue, no idea if it applies to
current releases or not, I think it was against CVS HEAD at the time.

If I'd actually waited for an answer to my question, I could have saved
myself the work. :)

In other words, I've spent the last half an hour tracing the problem and
constructing the exact same patch you just posted.

Thanks very much.

Ian
--
Ian Macdonald | The biggest mistake you can make is to
System Administrator | believe that you are working for someone
(e-mail address removed) | else.
http://www.caliban.org |
|
 
I

Ian Macdonald

--J2SCkAp4GZ/dPZZf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

If I'd actually waited for an answer to my question, I could have saved
myself the work. :)

In other words, I've spent the last half an hour tracing the problem and
constructing the exact same patch you just posted.

Actually, my patch against 1.8.2 is ever so slightly different, so I
post it here for the convenience of others.

Ian
--
Ian Macdonald | Someday you'll get your big chance -- or
System Administrator | have you already had it?
(e-mail address removed) |
http://www.caliban.org |
|

--J2SCkAp4GZ/dPZZf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="rdoc-space-before-paren.diff"

--- /usr/lib/ruby/1.8/rdoc/parsers/parse_c.rb 2004-09-08 19:48:32.000000000 -0700
+++ parse_c.rb 2005-02-24 17:57:38.602638528 -0800
@@ -249,13 +249,13 @@
############################################################

def do_classes
- @body.scan(/(\w+)\s* = \s*rb_define_module\(\s*"(\w+)"\s*\)/mx) do
+ @body.scan(/(\w+)\s* = \s*rb_define_module\s*\(\s*"(\w+)"\s*\)/mx) do
|var_name, class_name|
handle_class_module(var_name, "module", class_name, nil, nil)
end

# The '.' lets us handle SWIG-generated files
- @body.scan(/([\w\.]+)\s* = \s*rb_define_class
+ @body.scan(/([\w\.]+)\s* = \s*rb_define_class\s*
\(
\s*"(\w+)",
\s*(\w+)\s*
@@ -265,7 +265,7 @@
handle_class_module(var_name, "class", class_name, parent, nil)
end

- @body.scan(/(\w+)\s*=\s*boot_defclass\(\s*"(\w+?)",\s*(\w+?)\)/) do
+ @body.scan(/(\w+)\s*=\s*boot_defclass\s*\(\s*"(\w+?)",\s*(\w+?)\)/) do
|var_name, class_name, parent|
parent = nil if parent == "0"
handle_class_module(var_name, "class", class_name, parent, nil)
@@ -281,7 +281,7 @@
handle_class_module(var_name, "module", class_name, nil, in_module)
end

- @body.scan(/([\w\.]+)\s* = \s*rb_define_class_under
+ @body.scan(/([\w\.]+)\s* = \s*rb_define_class_under\s*
\(
\s*(\w+),
\s*"(\w+)",
@@ -305,7 +305,7 @@
module_function |
private_method
)
- \(\s*([\w\.]+),
+ \s*\(\s*([\w\.]+),
\s*"([^"]+)",
\s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\()?(\w+)\)?,
\s*(-?\w+)\s*\)
@@ -325,7 +325,7 @@
meth_body, param_count, source_file)
end

- @body.scan(%r{rb_define_global_function\(
+ @body.scan(%r{rb_define_global_function\s*\(
\s*"([^"]+)",
\s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\()?(\w+)\)?,
\s*(-?\w+)\s*\)
@@ -336,7 +336,7 @@
meth_body, param_count, source_file)
end

- @body.scan(/define_filetest_function\(
+ @body.scan(/define_filetest_function\s*\(
\s*"([^"]+)",
\s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\()?(\w+)\)?,
\s*(-?\w+)\s*\)/xm) do #"
@@ -350,7 +350,7 @@
############################################################

def do_aliases
- @body.scan(%r{rb_define_alias\(\s*(\w+),\s*"([^"]+)",\s*"([^"]+)"\s*\)}m) do
+ @body.scan(%r{rb_define_alias\s*\(\s*(\w+),\s*"([^"]+)",\s*"([^"]+)"\s*\)}m) do
|var_name, new_name, old_name|
@stats.num_methods += 1
class_name = @known_classes[var_name] || var_name
@@ -482,7 +482,7 @@
# Look for includes of the form
# rb_include_module(rb_cArray, rb_mEnumerable);
def do_includes
- @body.scan(/rb_include_module\(\s*(\w+?),\s*(\w+?)\s*\)/) do |c,m|
+ @body.scan(/rb_include_module\s*\(\s*(\w+?),\s*(\w+?)\s*\)/) do |c,m|
if cls = @classes[c]
m = KNOWN_CLASSES[m] || m
cls.add_include(Include.new(m, ""))

--J2SCkAp4GZ/dPZZf--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top