[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

rdoc and C files again

Charles Mills

10/5/2004 9:50:00 PM

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



3 Answers

Charles Mills

10/5/2004 10:32:00 PM

0

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

On Oct 5, 2004, at 2:50 PM, Charles Mills wrote:

> 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



Dave Thomas

10/6/2004 2:18:00 AM

0


On Oct 5, 2004, at 16:50, Charles Mills wrote:

> 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)

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



Charles Mills

10/6/2004 4:56:00 AM

0

On Oct 5, 2004, at 7:17 PM, Dave Thomas wrote:
>
> On Oct 5, 2004, at 16:50, Charles Mills wrote:
>>
>> < 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

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