comment.rb 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #! /usr/bin/ruby -w
  2. count = 0
  3. while s = gets
  4. if s =~ /(ConsoleMethod|ConsoleFunction)/
  5. count = count + 1
  6. # ConsoleMethod(class, method, void, 2, 3, "(args) Set whether ...\n"
  7. # "@param setting Default is true.\n"
  8. # ...
  9. # break into 3 parts (shown with brackets here)
  10. # [ConsoleMethod(class, method, void, 2, 3, ]"[(args)] [Set whether ...\n" <all lines after>]
  11. if s =~ /([^"]*)"([^\)]*\)) ?(.*)/
  12. found = true
  13. start = $1;
  14. args = $2;
  15. docs = $3;
  16. # parse same as above but missing the (args) (including parens)
  17. elsif s =~ /([^"]*)" ?(.*)/
  18. found = true
  19. start = $1;
  20. args = nil;
  21. docs = $2;
  22. warn "no params found here: '" + s + "'"
  23. else
  24. found = false
  25. end
  26. if found
  27. # seemed that using 'docs' instead of 'cookedDocs' was overwriting internal ($2 or $3) buffers?
  28. cookedDocs = docs;
  29. # remove the dash in front of some brief descriptions, like " - Gets whether picking..."
  30. cookedDocs.sub!(/^\s*-\s*/, '');
  31. while s = gets
  32. if s =~ /^\s*\{/
  33. # done finding comments. ok to eat the "{"
  34. break
  35. else
  36. s.chomp!
  37. cookedDocs = cookedDocs + "\n" + s
  38. end
  39. end
  40. # description string lines start with lots of white space. change to 4 spaces.
  41. cookedDocs.gsub!(/[ \t]{4,}/, ' ');
  42. # remove literal \n from end of comments (in the string)
  43. cookedDocs.gsub!('\n', '');
  44. # remove [")] -- quote then paren -- from the last line of the comments (and any whitespace between).
  45. cookedDocs.gsub!(/"\s*\)/, '');
  46. # finally remove end quotes on the lines
  47. cookedDocs.gsub!('"', '');
  48. cookedStart = start
  49. # remove white space before the string comment begins
  50. cookedStart.sub!(/\s*$/, '')
  51. # sanity check
  52. # puts "start " + cookedStart;
  53. # puts "args " + args if args
  54. # puts "docs " + cookedDocs;
  55. puts '/*! ' + cookedDocs + "\n*/"
  56. puts cookedStart + " " + (args ? args : "(...)") + ')'
  57. puts '{'
  58. else
  59. warn "too dumb to parse '" + s + "'"
  60. end
  61. else
  62. puts s
  63. end
  64. end
  65. warn( "number of lines was " + count.to_s )