Guest User

Untitled

a guest
Feb 20th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. def parse_files(options)
  2.  
  3. file_info = []
  4.  
  5. files = options.files
  6. files = ["."] if files.empty?
  7.  
  8. file_list = normalized_file_list(options, files, true)
  9.  
  10. file_list.each do |fn|
  11. $stderr.printf("\n%35s: ", File.basename(fn)) unless options.quiet
  12.  
  13. content = File.open(fn, "r") {|f| f.read}
  14.  
  15. # BEGIN PATCH
  16. # command line option simulation
  17. optparse_help = 'start'#'finish' # 'start' 'override'
  18.  
  19. if optparse_help
  20. # most of this code just determines the start and finish of the very top of rdoc documentation
  21. # then we can place the help_doc before, after, or overriding the top rdoc documentation
  22. rdoc_start, rdoc_finish = nil, nil
  23. content.each_with_index do |line, index|
  24. next if index == 0 and line =~ /^#\!/
  25. if rdoc_start.nil?
  26. case line
  27. when /^\s$/ then next
  28. when /^#/ then rdoc_start = index
  29. else break
  30. end
  31. elsif rdoc_finish.nil?
  32. rdoc_finish = index if line =~ /^[^#]/
  33. elsif line =~ /\s*require|load\s+(['"])[\\\/\w]*optparse(\.rb)*\1/
  34. content = content.to_a
  35.  
  36. # this one line give us our documentation
  37. # do not chomp
  38. help_doc = %x{ruby #{fn} --help}.map{ |line| '#' << line }
  39.  
  40. case optparse_help
  41. when 'start'
  42. content = content[0...rdoc_start] + help_doc + content[rdoc_start..-1]
  43. when 'finish'
  44. content = content[0...rdoc_finish] + help_doc + content[rdoc_finish..-1]
  45. when 'override'
  46. content = help_doc + content[rdoc_finish..-1]
  47. end
  48.  
  49. content = content.to_s
  50. break
  51. end
  52. end
  53. end
  54. puts content
  55. # END PATCH
  56.  
  57. top_level = TopLevel.new(fn)
  58. parser = ParserFactory.parser_for(top_level, fn, content, options, @stats)
  59. file_info << parser.scan
  60. @stats.num_files += 1
  61. end
  62.  
  63. file_info
  64. end
Add Comment
Please, Sign In to add comment