rdoc and C files again

C

Charles Mills

Looks like rdoc doesn't replace tabs in .c files like expected (when
using the -w option).
I added a handle_tab_width() function to parse_c.rb and it seems to
work fine.
Here is the diff <myversion> <1.9version> output:

$ diff parse_c.rb
/Users/boson/local/lib/ruby/1.9/rdoc/parsers/parse_c.rb
177c177
< @body = handle_tab_width(handle_ifdefs_in(body))
---
@body = handle_ifdefs_in(body)
514,527d513
<
< def handle_tab_width(body)
< if /\t/ =~ body
< tab_str = ' ' *
Options.instance.tab_width
< body.gsub(/\t/, tab_str)
< #tab_width = Options.instance.tab_width
< #content = content.split(/\n/).map do
|line|
< #1 while line.gsub!(/\t+/) { ' ' *
(tab_width*$&.length - $`.length % tab_width)} && $~ #`
< # line
< #end .join("\n")
< else
< body
< end
< end

The commented out code is copied from parse_rb.rb, is that a better way
to do it?

-Charlie
 
C

Charles Mills

I also added support for rb_define_attr(). New diff is below...

Looks like rdoc doesn't replace tabs in .c files like expected (when
using the -w option).
I added a handle_tab_width() function to parse_c.rb and it seems to
work fine.
Here is the diff <myversion> <1.9version> output:

177c177
< @body = handle_tab_width(handle_ifdefs_in(body))
---
@body = handle_ifdefs_in(body)
328,344d327
< @body.scan(%r{rb_define_attr\(
< \s*([\w\.]+),
< \s*"([^"]+)",
< \s*(\d+),
< \s*(\d+)\s*\)
< (?:;\s*/[*/]\s+in\s+(\w+?\.[cy]))?
< }xm) do #"
< |var_name, meth_name, attr_reader, attr_writer, source_file|
<
< #var_name = "rb_cObject" if var_name == "rb_mKernel"
<
< handle_method("method", var_name, meth_name,
< nil, 0, source_file) unless attr_reader.to_i ==
0
< handle_method("method", var_name, meth_name + '=',
< nil, 1, source_file) unless attr_writer.to_i ==
0
< end
<
417c400
< find_body(meth_body, meth_obj, body) if meth_body
---
find_body(meth_body, meth_obj, body)
531,544d513
<
< def handle_tab_width(body)
< if /\t/ =~ body
< tab_str = ' ' *
Options.instance.tab_width
< body.gsub(/\t/, tab_str)
< #tab_width = Options.instance.tab_width
< #content = content.split(/\n/).map do
|line|
< #1 while line.gsub!(/\t+/) { ' ' *
(tab_width*$&.length - $`.length % tab_width)} && $~ #`
< # line
< #end .join("\n")
< else
< body
< end
< end

-Charlie
 
D

Dave Thomas

Looks like rdoc doesn't replace tabs in .c files like expected (when
using the -w option).
I added a handle_tab_width() function to parse_c.rb and it seems to
work fine.
Here is the diff <myversion> <1.9version> output:

$ diff parse_c.rb
/Users/boson/local/lib/ruby/1.9/rdoc/parsers/parse_c.rb
177c177
< @body = handle_tab_width(handle_ifdefs_in(body))
---
514,527d513
<
< def handle_tab_width(body)
< if /\t/ =~ body
< tab_str = ' ' *
Options.instance.tab_width
< body.gsub(/\t/, tab_str)

This doesn't work if you have

abc<tab>def

That's why we have the somewhat uglier:
< #tab_width = Options.instance.tab_width
< #content = content.split(/\n/).map do
|line|
< #1 while line.gsub!(/\t+/) { ' ' *
(tab_width*$&.length - $`.length % tab_width)} && $~ #`
< # line
< #end .join("\n")
< else


Cheers

Dave
 
C

Charles Mills

This doesn't work if you have

abc<tab>def

That's why we have the somewhat uglier:

OK, changed it. I just added support for documenting global variables
and constants in .c files. Tested it on my own stuff and it works.
The patch is getting pretty big and it sounds like your busy so let me
know when you want me to send it over.

-Charlie
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top