From 4b93d732e406957e094e848093517359b9ffecf4 Mon Sep 17 00:00:00 2001 From: drbrain Date: Mon, 7 Jan 2008 06:56:46 +0000 Subject: Convert RDoc to OptionParser, clean up -h output, namespace Options under RDoc. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14927 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rdoc/parsers/parse_c.rb | 12 ++++++------ lib/rdoc/parsers/parse_rb.rb | 32 ++++++++++++++++---------------- 2 files changed, 22 insertions(+), 22 deletions(-) (limited to 'lib/rdoc/parsers') diff --git a/lib/rdoc/parsers/parse_c.rb b/lib/rdoc/parsers/parse_c.rb index 98f4b3f02e..07d65bc9d8 100644 --- a/lib/rdoc/parsers/parse_c.rb +++ b/lib/rdoc/parsers/parse_c.rb @@ -3,7 +3,6 @@ require "rdoc/code_objects" require "rdoc/parsers/parserfactory" -require "rdoc/options" require "rdoc/rdoc" module RDoc @@ -37,6 +36,7 @@ module RDoc "rb_cTime" => "Time", "rb_cTrueClass" => "TrueClass", "rb_cStruct" => "Struct", + "rb_cVM" => "VM", "rb_eException" => "Exception", "rb_eStandardError" => "StandardError", "rb_eSystemExit" => "SystemExit", @@ -177,13 +177,13 @@ module RDoc # prepare to parse a C file def initialize(top_level, file_name, body, options, stats) @known_classes = KNOWN_CLASSES.dup - @body = handle_tab_width(handle_ifdefs_in(body)) @options = options + @body = handle_tab_width(handle_ifdefs_in(body)) @stats = stats @top_level = top_level @classes = Hash.new @file_dir = File.dirname(file_name) - @progress = $stderr unless options.quiet + @progress = $stderr unless @options.quiet end # Extract the classes/modules and methods from a C file @@ -627,8 +627,8 @@ module RDoc # Find the C code corresponding to a Ruby method def find_body(meth_name, meth_obj, body, quiet = false) case body - when %r{((?>/\*.*?\*/\s*))(?:static\s+)?VALUE\s+#{meth_name} - \s*(\([^)]*\))\s*\{.*?^\}}xm + when %r"((?>/\*.*?\*/\s*))(?:static\s+)?VALUE\s+#{meth_name} + \s*(\([^)]*\))\s*\{.*?^\}"xm comment, params = $1, $2 body_text = $& @@ -752,7 +752,7 @@ module RDoc def handle_tab_width(body) if /\t/ =~ body - tab_width = Options.instance.tab_width + tab_width = @options.tab_width body.split(/\n/).map do |line| 1 while line.gsub!(/\t+/) { ' ' * (tab_width*$&.length - $`.length % tab_width)} && $~ #` line diff --git a/lib/rdoc/parsers/parse_rb.rb b/lib/rdoc/parsers/parse_rb.rb index 04fac7dcd7..42256b2523 100644 --- a/lib/rdoc/parsers/parse_rb.rb +++ b/lib/rdoc/parsers/parse_rb.rb @@ -305,8 +305,6 @@ module RubyToken end - - # Lexical analyzer for Ruby source class RubyLex @@ -345,9 +343,11 @@ class RubyLex attr_reader :line_num - def initialize(content) + def initialize(content, options) + @options = options + if /\t/ =~ content - tab_width = Options.instance.tab_width + tab_width = @options.tab_width content = content.split(/\n/).map do |line| 1 while line.gsub!(/\t+/) { ' ' * (tab_width*$&.length - $`.length % tab_width)} && $~ #` line @@ -444,10 +444,12 @@ class RubyLex false end - def initialize(content) + def initialize(content, options) lex_init - @reader = BufferedReader.new(content) + @options = options + + @reader = BufferedReader.new content, @options @exp_line_no = @line_no = 1 @base_char_no = 0 @@ -1353,10 +1355,9 @@ class RubyLex end end - - -# Extract code elements from a source file, returning a TopLevel -# object containing the constituent file elements. +## +# Extract code elements from a source file, returning a TopLevel object +# containing the constituent file elements. # # This file is based on rtags @@ -1389,7 +1390,7 @@ module RDoc @size = 0 @token_listeners = nil @input_file_name = file_name - @scanner = RubyLex.new(content) + @scanner = RubyLex.new content, @options @scanner.exception_on_syntax_error = false @top_level = top_level @progress = $stderr unless options.quiet @@ -2325,13 +2326,11 @@ module RDoc throw :enddoc when "main" - options = Options.instance - options.main_page = param - "" + @options.main_page = param + "" when "title" - options = Options.instance - options.title = param + @options.title = param "" when "section" @@ -2605,3 +2604,4 @@ module RDoc end end + -- cgit v1.2.3