[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

rdoc and GNU-indented files

Ian Macdonald

2/25/2005 1:15:00 AM

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
ian@caliban.org | help. -- Miss Manners
http://www.c... |
|


3 Answers

Garrett Rooney

2/25/2005 1:21:00 AM

0

Ian Macdonald wrote:
> 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
? 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, ""))

Ian Macdonald

2/25/2005 1:44:00 AM

0

On Fri 25 Feb 2005 at 10:20:40 +0900, Garrett Rooney wrote:

> Ian Macdonald wrote:
> >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.

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
ian@caliban.org | else.
http://www.c... |
|


Ian Macdonald

2/25/2005 2:00:00 AM

0

On Fri 25 Feb 2005 at 10:43:53 +0900, Ian Macdonald wrote:

> 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?
ian@caliban.org |
http://www.c... |
|