mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/rdoc: Import RDoc 2.5.2
* lib/rdoc/parser/ruby.rb (RDoc::Parser::Ruby): Don't parse rdoc files, reverts r24976 in favor of include directive support in C parser. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27283 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ce2b574017
commit
1325437297
33 changed files with 395 additions and 162 deletions
|
@ -227,8 +227,8 @@ class RDoc::Parser::C < RDoc::Parser
|
|||
next if var_name == "argf" # it'd be nice to handle this one
|
||||
|
||||
var_name = "rb_cObject" if var_name == "rb_mKernel"
|
||||
handle_method(type, var_name, meth_name,
|
||||
meth_body, param_count, source_file)
|
||||
handle_method(type, var_name, meth_name, meth_body, param_count,
|
||||
source_file)
|
||||
end
|
||||
|
||||
@content.scan(%r{rb_define_attr\(
|
||||
|
@ -304,7 +304,7 @@ class RDoc::Parser::C < RDoc::Parser
|
|||
|
||||
find_modifiers comment, meth_obj if comment
|
||||
|
||||
# meth_obj.params = params
|
||||
#meth_obj.params = params
|
||||
meth_obj.start_collecting_tokens
|
||||
tk = RDoc::RubyToken::Token.new nil, 1, 1
|
||||
tk.set_text body_text
|
||||
|
@ -397,7 +397,13 @@ class RDoc::Parser::C < RDoc::Parser
|
|||
comment = $1
|
||||
end
|
||||
|
||||
class_mod.comment = strip_stars comment if comment
|
||||
return unless comment
|
||||
|
||||
comment = strip_stars comment
|
||||
|
||||
comment = look_for_directives_in class_mod, comment
|
||||
|
||||
class_mod.comment = comment
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -479,7 +485,7 @@ class RDoc::Parser::C < RDoc::Parser
|
|||
end
|
||||
|
||||
unless enclosure then
|
||||
warn("Enclosing class/module '#{in_module}' for #{type} #{class_name} not known")
|
||||
warn "Enclosing class/module '#{in_module}' for #{type} #{class_name} not known"
|
||||
return
|
||||
end
|
||||
else
|
||||
|
@ -601,9 +607,9 @@ class RDoc::Parser::C < RDoc::Parser
|
|||
meth_obj = RDoc::AnyMethod.new '', meth_name
|
||||
meth_obj.singleton = %w[singleton_method module_function].include? type
|
||||
|
||||
p_count = (Integer(param_count) rescue -1)
|
||||
p_count = Integer(param_count) rescue -1
|
||||
|
||||
if p_count < 0
|
||||
if p_count < 0 then
|
||||
meth_obj.params = "(...)"
|
||||
elsif p_count == 0
|
||||
meth_obj.params = "()"
|
||||
|
@ -611,10 +617,14 @@ class RDoc::Parser::C < RDoc::Parser
|
|||
meth_obj.params = "(" + (1..p_count).map{|i| "p#{i}"}.join(", ") + ")"
|
||||
end
|
||||
|
||||
if source_file and File.exist?(file_name = File.join(@file_dir, source_file)) then
|
||||
body = (@@known_bodies[source_file] ||= File.read(file_name))
|
||||
elsif source_file then
|
||||
warn "unknown source file #{source_file}"
|
||||
if source_file then
|
||||
file_name = File.join @file_dir, source_file
|
||||
|
||||
if File.exist? file_name then
|
||||
body = (@@known_bodies[file_name] ||= File.read(file_name))
|
||||
else
|
||||
warn "unknown source #{source_file} for #{meth_name} in #{@file_name}"
|
||||
end
|
||||
else
|
||||
body = @content
|
||||
end
|
||||
|
@ -639,6 +649,34 @@ class RDoc::Parser::C < RDoc::Parser
|
|||
end
|
||||
end
|
||||
|
||||
##
|
||||
# Look for directives in a normal comment block:
|
||||
#
|
||||
# /*
|
||||
# * :title: My Awesome Project
|
||||
# */
|
||||
#
|
||||
# This routine modifies it's parameter
|
||||
|
||||
def look_for_directives_in(context, comment)
|
||||
preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
|
||||
|
||||
preprocess.handle comment do |directive, param|
|
||||
case directive
|
||||
when 'main' then
|
||||
@options.main_page = param
|
||||
''
|
||||
when 'title' then
|
||||
@options.title = param
|
||||
''
|
||||
else
|
||||
warn "Unrecognized directive :#{directive}:"
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
comment
|
||||
end
|
||||
##
|
||||
# Removes lines that are commented out that might otherwise get picked up
|
||||
# when scanning for classes and methods
|
||||
|
@ -648,8 +686,8 @@ class RDoc::Parser::C < RDoc::Parser
|
|||
end
|
||||
|
||||
def remove_private_comments(comment)
|
||||
comment.gsub!(/\/?\*--\n(.*?)\/?\*\+\+/m, '')
|
||||
comment.sub!(/\/?\*--\n.*/m, '')
|
||||
comment.gsub!(/\/?\*--\n(.*?)\/?\*\+\+/m, '')
|
||||
comment.sub!(/\/?\*--\n.*/m, '')
|
||||
end
|
||||
|
||||
##
|
||||
|
|
|
@ -146,7 +146,7 @@ $TOKEN_DEBUG ||= nil
|
|||
|
||||
class RDoc::Parser::Ruby < RDoc::Parser
|
||||
|
||||
parse_files_matching(/\.(?:rbw?|rdoc)\z/)
|
||||
parse_files_matching(/\.rbw?$/)
|
||||
|
||||
include RDoc::RubyToken
|
||||
include RDoc::TokenStream
|
||||
|
@ -212,7 +212,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|||
def error(msg)
|
||||
msg = make_message msg
|
||||
$stderr.puts msg
|
||||
exit(false)
|
||||
exit false
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -377,10 +377,9 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|||
# This routine modifies it's parameter
|
||||
|
||||
def look_for_directives_in(context, comment)
|
||||
preprocess = RDoc::Markup::PreProcess.new(@file_name,
|
||||
@options.rdoc_include)
|
||||
preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
|
||||
|
||||
preprocess.handle(comment) do |directive, param|
|
||||
preprocess.handle comment do |directive, param|
|
||||
case directive
|
||||
when 'enddoc' then
|
||||
throw :enddoc
|
||||
|
@ -391,7 +390,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|||
'attr', 'attr_accessor', 'attr_reader', 'attr_writer' then
|
||||
false # handled elsewhere
|
||||
when 'section' then
|
||||
context.set_current_section(param, comment)
|
||||
context.set_current_section param, comment
|
||||
comment.replace ''
|
||||
break
|
||||
when 'startdoc' then
|
||||
|
@ -405,7 +404,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|||
@options.title = param
|
||||
''
|
||||
else
|
||||
warn "Unrecognized directive '#{directive}'"
|
||||
warn "Unrecognized directive :#{directive}:"
|
||||
false
|
||||
end
|
||||
end
|
||||
|
@ -1405,16 +1404,12 @@ class RDoc::Parser::Ruby < RDoc::Parser
|
|||
end
|
||||
end
|
||||
|
||||
def parse_yield_parameters
|
||||
parse_method_or_yield_parameters
|
||||
end
|
||||
|
||||
def parse_yield(context, single, tk, method)
|
||||
if method.block_params.nil?
|
||||
get_tkread
|
||||
@scanner.instance_eval{@continue = false}
|
||||
method.block_params = parse_yield_parameters
|
||||
end
|
||||
return if method.block_params
|
||||
|
||||
get_tkread
|
||||
@scanner.instance_eval { @continue = false }
|
||||
method.block_params = parse_method_or_yield_parameters
|
||||
end
|
||||
|
||||
##
|
||||
|
|
|
@ -24,7 +24,10 @@ class RDoc::Parser::Simple < RDoc::Parser
|
|||
# Extract the file contents and attach them to the TopLevel as a comment
|
||||
|
||||
def scan
|
||||
@top_level.comment = remove_private_comments(@content)
|
||||
comment = remove_coding_comment @content
|
||||
comment = remove_private_comments comment
|
||||
|
||||
@top_level.comment = comment
|
||||
@top_level.parser = self.class
|
||||
@top_level
|
||||
end
|
||||
|
@ -33,5 +36,9 @@ class RDoc::Parser::Simple < RDoc::Parser
|
|||
comment.gsub(/^--\n.*?^\+\+/m, '').sub(/^--\n.*/m, '')
|
||||
end
|
||||
|
||||
def remove_coding_comment text
|
||||
text.sub(/\A# .*coding[=:].*$/, '')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue