rdoc and C files again

Discussion in 'Ruby' started by Charles Mills, Oct 5, 2004.

  1. 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
     
    Charles Mills, Oct 5, 2004
    #1
    1. Advertising

  2. 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
     
    Charles Mills, Oct 5, 2004
    #2
    1. Advertising

  3. Charles Mills

    Dave Thomas Guest

    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
     
    Dave Thomas, Oct 6, 2004
    #3
  4. 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
     
    Charles Mills, Oct 6, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Schwarz
    Replies:
    6
    Views:
    253
    Randy W. Sims
    Jan 1, 2004
  2. Brian Schröder
    Replies:
    5
    Views:
    140
    Dave Thomas
    Sep 18, 2004
  3. Daniel Berger
    Replies:
    1
    Views:
    144
    Dave Thomas
    Nov 2, 2004
  4. Iwan van der Kleyn

    rdoc: how to add readme.rdoc as index.html?

    Iwan van der Kleyn, Apr 26, 2005, in forum: Ruby
    Replies:
    1
    Views:
    234
    Stefan Lang
    Apr 26, 2005
  5. Paul Van Delst

    How to use rdoc parsers outside of rdoc?

    Paul Van Delst, Jul 27, 2006, in forum: Ruby
    Replies:
    0
    Views:
    105
    Paul Van Delst
    Jul 27, 2006
Loading...

Share This Page