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
|
@ -1,3 +1,10 @@
|
|||
Sat Apr 10 15:18:26 2010 Eric Hodel <drbrain@segment7.net>
|
||||
|
||||
* 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.
|
||||
|
||||
Sat Apr 10 13:14:22 2010 Yusuke Endoh <mame@tsg.ne.jp>
|
||||
|
||||
* ext/openssl/ossl_ssl.c (Init_ossl_ssl): add SSLContext#ssl_timeout=,
|
||||
|
|
4
NEWS
4
NEWS
|
@ -199,6 +199,10 @@ with all sufficient information, see the ChangeLog file.
|
|||
|
||||
http://www.ruby-lang.org/en/news/2008/08/23/dos-vulnerability-in-rexml/
|
||||
|
||||
* RDoc
|
||||
|
||||
* Updated to RDoc 2.5.2
|
||||
|
||||
* logger
|
||||
|
||||
* imported upstream version (logger/1.2.7)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
# -*- mode: rdoc; coding: utf-8; fill-column: 74; -*-
|
||||
=begin rdoc
|
||||
|
||||
Regular expressions (<i>regexp</i>s) are patterns which describe the
|
||||
contents of a string. They're used for testing whether a string contains a
|
||||
|
@ -580,5 +579,4 @@ backtracking needed.
|
|||
|
||||
Regexp.new('\A' 'a?' * 29 + 'a' * 29).match('a' * 29)
|
||||
#=> #<MatchData "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa">
|
||||
=end
|
||||
class Regexp; end
|
||||
|
||||
|
|
|
@ -383,7 +383,7 @@ module RDoc
|
|||
##
|
||||
# RDoc version you are using
|
||||
|
||||
VERSION = '2.5'
|
||||
VERSION = '2.5.2'
|
||||
|
||||
##
|
||||
# Name of the dotfile that contains the description of files to be processed
|
||||
|
|
|
@ -6,7 +6,7 @@ require 'rdoc/tokenstream'
|
|||
|
||||
class RDoc::AnyMethod < RDoc::CodeObject
|
||||
|
||||
MARSHAL_VERSION = 0 # :nodoc:
|
||||
MARSHAL_VERSION = 1 # :nodoc:
|
||||
|
||||
include Comparable
|
||||
|
||||
|
@ -58,7 +58,7 @@ class RDoc::AnyMethod < RDoc::CodeObject
|
|||
##
|
||||
# Parameters for this method
|
||||
|
||||
attr_overridable :params, :param, :parameters, :parameter
|
||||
attr_accessor :params
|
||||
|
||||
##
|
||||
# Different ways to call this method
|
||||
|
@ -87,6 +87,7 @@ class RDoc::AnyMethod < RDoc::CodeObject
|
|||
@call_seq = nil
|
||||
@dont_rename_initialize = false
|
||||
@is_alias_for = nil
|
||||
@params = nil
|
||||
@parent_name = nil
|
||||
@singleton = nil
|
||||
@token_stream = nil
|
||||
|
@ -110,6 +111,19 @@ class RDoc::AnyMethod < RDoc::CodeObject
|
|||
@aliases << method
|
||||
end
|
||||
|
||||
##
|
||||
# The call_seq or the param_seq with method name, if there is no call_seq.
|
||||
#
|
||||
# Use this for displaying a method's argument lists.
|
||||
|
||||
def arglists
|
||||
if @call_seq then
|
||||
@call_seq
|
||||
elsif @params then
|
||||
"#{name}#{param_seq}"
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# HTML id-friendly method name
|
||||
|
||||
|
@ -151,6 +165,7 @@ class RDoc::AnyMethod < RDoc::CodeObject
|
|||
@call_seq,
|
||||
@block_params,
|
||||
aliases,
|
||||
@params,
|
||||
]
|
||||
end
|
||||
|
||||
|
@ -162,7 +177,6 @@ class RDoc::AnyMethod < RDoc::CodeObject
|
|||
# * #parent_name
|
||||
|
||||
def marshal_load(array)
|
||||
@aliases = []
|
||||
@dont_rename_initialize = nil
|
||||
@is_alias_for = nil
|
||||
@token_stream = nil
|
||||
|
@ -174,6 +188,8 @@ class RDoc::AnyMethod < RDoc::CodeObject
|
|||
@comment = array[5]
|
||||
@call_seq = array[6]
|
||||
@block_params = array[7]
|
||||
@aliases = array[8]
|
||||
@params = array[9]
|
||||
|
||||
@parent_name = if @full_name =~ /#/ then
|
||||
$`
|
||||
|
@ -201,16 +217,16 @@ class RDoc::AnyMethod < RDoc::CodeObject
|
|||
# Pretty parameter list for this method
|
||||
|
||||
def param_seq
|
||||
params = params.gsub(/\s*\#.*/, '')
|
||||
params = @params.gsub(/\s*\#.*/, '')
|
||||
params = params.tr("\n", " ").squeeze(" ")
|
||||
params = "(#{params})" unless p[0] == ?(
|
||||
params = "(#{params})" unless params[0] == ?(
|
||||
|
||||
if block = block_params then # yes, =
|
||||
if @block_params then
|
||||
# If this method has explicit block parameters, remove any explicit
|
||||
# &block
|
||||
params.sub!(/,?\s*&\w+/)
|
||||
params.sub!(/,?\s*&\w+/, '')
|
||||
|
||||
block.gsub!(/\s*\#.*/, '')
|
||||
block = @block_params.gsub(/\s*\#.*/, '')
|
||||
block = block.tr("\n", " ").squeeze(" ")
|
||||
if block[0] == ?(
|
||||
block.sub!(/^\(/, '').sub!(/\)/, '')
|
||||
|
|
|
@ -56,6 +56,12 @@ class RDoc::Attr < RDoc::CodeObject
|
|||
##
|
||||
# Returns nil, for duck typing with RDoc::AnyMethod
|
||||
|
||||
def arglists
|
||||
end
|
||||
|
||||
##
|
||||
# Returns nil, for duck typing with RDoc::AnyMethod
|
||||
|
||||
def block_params
|
||||
end
|
||||
|
||||
|
@ -132,6 +138,13 @@ class RDoc::Attr < RDoc::CodeObject
|
|||
@parent_name || super
|
||||
end
|
||||
|
||||
##
|
||||
# For duck typing with RDoc::AnyMethod, returns nil
|
||||
|
||||
def params
|
||||
nil
|
||||
end
|
||||
|
||||
##
|
||||
# URL path for this attribute
|
||||
|
||||
|
|
|
@ -146,10 +146,11 @@ class RDoc::ClassModule < RDoc::Context
|
|||
|
||||
def merge class_module
|
||||
comment = class_module.comment
|
||||
|
||||
if comment then
|
||||
document = parse @comment
|
||||
|
||||
comment.parts.concat(document.parts)
|
||||
comment.parts.concat document.parts
|
||||
|
||||
@comment = comment
|
||||
end
|
||||
|
|
|
@ -53,25 +53,6 @@ class RDoc::CodeObject
|
|||
|
||||
attr_accessor :viewer
|
||||
|
||||
##
|
||||
# There's a wee trick we pull. Comment blocks can have directives that
|
||||
# override the stuff we extract during the parse. So, we have a special
|
||||
# class method, attr_overridable, that lets code objects list those
|
||||
# directives. When a comment is assigned, we then extract out any matching
|
||||
# directives and update our object
|
||||
|
||||
def self.attr_overridable(name, *aliases)
|
||||
@overridables ||= {}
|
||||
|
||||
attr_accessor name
|
||||
|
||||
aliases.unshift name
|
||||
|
||||
aliases.each do |directive_name|
|
||||
@overridables[directive_name.to_s] = name
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# Creates a new CodeObject that will document itself and its children
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
# -*- mode: ruby; ruby-indent-level: 2; tab-width: 2 -*-
|
||||
# vim: noet ts=2 sts=8 sw=2
|
||||
|
||||
require 'pp'
|
||||
require 'pathname'
|
||||
require 'fileutils'
|
||||
require 'erb'
|
||||
|
@ -11,46 +10,46 @@ require 'rdoc/generator/markup'
|
|||
$DARKFISH_DRYRUN = false # TODO make me non-global
|
||||
|
||||
#
|
||||
# Darkfish RDoc HTML Generator
|
||||
#
|
||||
# $Id: darkfish.rb 52 2009-01-07 02:08:11Z deveiant $
|
||||
# Darkfish RDoc HTML Generator
|
||||
#
|
||||
# $Id: darkfish.rb 52 2009-01-07 02:08:11Z deveiant $
|
||||
#
|
||||
# == Author/s
|
||||
# * Michael Granger (ged@FaerieMUD.org)
|
||||
#
|
||||
# == Contributors
|
||||
# * Mahlon E. Smith (mahlon@martini.nu)
|
||||
# * Eric Hodel (drbrain@segment7.net)
|
||||
#
|
||||
# == License
|
||||
#
|
||||
# Copyright (c) 2007, 2008, Michael Granger. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
#
|
||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
#
|
||||
# * Neither the name of the author/s, nor the names of the project's
|
||||
# contributors may be used to endorse or promote products derived from this
|
||||
# software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
# == Author/s
|
||||
# * Michael Granger (ged@FaerieMUD.org)
|
||||
#
|
||||
# == Contributors
|
||||
# * Mahlon E. Smith (mahlon@martini.nu)
|
||||
# * Eric Hodel (drbrain@segment7.net)
|
||||
#
|
||||
# == License
|
||||
#
|
||||
# Copyright (c) 2007, 2008, Michael Granger. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
#
|
||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
#
|
||||
# * Neither the name of the author/s, nor the names of the project's
|
||||
# contributors may be used to endorse or promote products derived from this
|
||||
# software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
class RDoc::Generator::Darkfish
|
||||
|
||||
RDoc::RDoc.add_generator( self )
|
||||
|
|
|
@ -463,7 +463,7 @@ class RDoc::Markup::Parser
|
|||
token
|
||||
when s.scan(/ +/) then
|
||||
[:INDENT, s.matched_size, *token_pos(pos)]
|
||||
when s.scan(/(=+)\s+/) then
|
||||
when s.scan(/(=+)\s*/) then
|
||||
level = s[1].length
|
||||
level = 6 if level > 6
|
||||
@tokens << [:HEADER, level, *token_pos(pos)]
|
||||
|
|
|
@ -41,14 +41,13 @@ class RDoc::Markup::PreProcess
|
|||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
##
|
||||
# Include a file, indenting it correctly.
|
||||
|
||||
def include_file(name, indent)
|
||||
if full_name = find_include_file(name) then
|
||||
content = File.read full_name
|
||||
content = content.sub(/\A# .*coding[=:].*$/, '').lstrip
|
||||
|
||||
# strip leading '#'s, but only if all lines start with them
|
||||
if content =~ /^[^#]/ then
|
||||
|
@ -57,7 +56,7 @@ class RDoc::Markup::PreProcess
|
|||
content.gsub(/^#?/, indent)
|
||||
end
|
||||
else
|
||||
$stderr.puts "Couldn't find file to include '#{name}' from #{@input_file_name}"
|
||||
warn "Couldn't find file to include '#{name}' from #{@input_file_name}"
|
||||
''
|
||||
end
|
||||
end
|
||||
|
@ -67,7 +66,7 @@ class RDoc::Markup::PreProcess
|
|||
# and then in each of the directories specified in the RDOC_INCLUDE path
|
||||
|
||||
def find_include_file(name)
|
||||
to_search = [ File.dirname(@input_file_name) ].concat @include_path
|
||||
to_search = [File.dirname(@input_file_name)].concat @include_path
|
||||
to_search.each do |dir|
|
||||
full_name = File.join(dir, name)
|
||||
stat = File.stat(full_name) rescue next
|
||||
|
|
|
@ -73,10 +73,10 @@ class RDoc::Parser
|
|||
true
|
||||
elsif file =~ /erb\.rb$/ then
|
||||
false
|
||||
elsif s.scan(/<%|%>/).length >= 4 then
|
||||
elsif s.scan(/<%|%>/).length >= 4 || s.index("\x00") then
|
||||
true
|
||||
else
|
||||
s.count("^ -~\t\r\n").fdiv(s.size) > 0.3 || s.index("\x00")
|
||||
s.count("^ -~\t\r\n").fdiv(s.size) > 0.3
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -102,7 +102,9 @@ class RDoc::Parser
|
|||
return if parser == RDoc::Parser::Simple and zip? file_name
|
||||
|
||||
# The default parser must not parse binary files
|
||||
return if parser == RDoc::Parser::Simple and file_name !~ /\.(txt|rdoc)$/
|
||||
ext_name = File.extname file_name
|
||||
return parser if ext_name.empty?
|
||||
return if parser == RDoc::Parser::Simple and ext_name !~ /txt|rdoc/
|
||||
|
||||
parser
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -135,17 +135,17 @@ class RDoc::RDoc
|
|||
def setup_output_dir(op_dir, force)
|
||||
flag_file = output_flag_file op_dir
|
||||
|
||||
last = @last_created
|
||||
last = {}
|
||||
|
||||
if File.exist? op_dir then
|
||||
unless File.directory? op_dir then
|
||||
error "'#{op_dir}' exists, and is not a directory"
|
||||
end
|
||||
begin
|
||||
open(flag_file) do |f|
|
||||
open flag_file do |io|
|
||||
unless force
|
||||
Time.parse(f.gets)
|
||||
f.each do |line|
|
||||
Time.parse f.gets
|
||||
io.each do |line|
|
||||
file, time = line.split(/\t/, 2)
|
||||
time = Time.parse(time) rescue next
|
||||
last[file] = time
|
||||
|
@ -225,19 +225,20 @@ class RDoc::RDoc
|
|||
stat = File.stat rel_file_name rescue next
|
||||
|
||||
case type = stat.ftype
|
||||
when "file"
|
||||
next if last_created = @last_created[rel_file_name] and stat.mtime <= last_created
|
||||
when "file" then
|
||||
next if last_created = @last_created[rel_file_name] and
|
||||
stat.mtime <= last_created
|
||||
|
||||
if force_doc or RDoc::Parser.can_parse(rel_file_name) then
|
||||
file_list << rel_file_name.sub(/^\.\//, '')
|
||||
@last_created[rel_file_name] = stat.mtime
|
||||
end
|
||||
when "directory"
|
||||
when "directory" then
|
||||
next if rel_file_name == "CVS" || rel_file_name == ".svn"
|
||||
|
||||
dot_doc = File.join rel_file_name, RDoc::DOT_DOC_FILENAME
|
||||
|
||||
if File.file?(dot_doc) then
|
||||
if File.file? dot_doc then
|
||||
file_list << parse_dot_doc_file(rel_file_name, dot_doc)
|
||||
else
|
||||
file_list << list_files_in_directory(rel_file_name)
|
||||
|
@ -355,7 +356,7 @@ The internal error was:
|
|||
|
||||
@exclude = @options.exclude
|
||||
|
||||
setup_output_dir @options.op_dir, @options.force_update
|
||||
@last_created = setup_output_dir @options.op_dir, @options.force_update
|
||||
|
||||
start_time = Time.now
|
||||
|
||||
|
|
|
@ -657,21 +657,13 @@ Options may also be set in the 'RI' environment variable.
|
|||
end
|
||||
out << RDoc::Markup::Rule.new(1)
|
||||
|
||||
if method.call_seq then
|
||||
call_seq = method.call_seq.chomp.split "\n"
|
||||
call_seq = call_seq.map { |line| [' ', line, "\n"] }
|
||||
out << RDoc::Markup::Verbatim.new(*call_seq.flatten)
|
||||
if method.arglists then
|
||||
arglists = method.arglists.chomp.split "\n"
|
||||
arglists = arglists.map { |line| [' ', line, "\n"] }
|
||||
out << RDoc::Markup::Verbatim.new(*arglists.flatten)
|
||||
out << RDoc::Markup::Rule.new(1)
|
||||
end
|
||||
|
||||
if method.block_params then
|
||||
out << RDoc::Markup::BlankLine.new if method.call_seq
|
||||
params = "yields: #{method.block_params}"
|
||||
out << RDoc::Markup::Verbatim.new(' ', params, "\n")
|
||||
end
|
||||
|
||||
out << RDoc::Markup::Rule.new(1) if
|
||||
method.call_seq or method.block_params
|
||||
|
||||
out << RDoc::Markup::BlankLine.new
|
||||
out << method.comment
|
||||
out << RDoc::Markup::BlankLine.new
|
||||
|
@ -793,7 +785,7 @@ Options may also be set in the 'RI' environment variable.
|
|||
end
|
||||
|
||||
methods.each do |item|
|
||||
yield(*item)
|
||||
yield(*item) # :yields: store, klass, ancestor, types, method
|
||||
end
|
||||
|
||||
self
|
||||
|
|
|
@ -13,8 +13,7 @@ module RDoc::RI::Paths
|
|||
base = File.join RbConfig::CONFIG['ridir'], version
|
||||
SYSDIR = File.join base, "system"
|
||||
SITEDIR = File.join base, "site"
|
||||
HOMEDIR = (File.expand_path("~/.rdoc") rescue nil)
|
||||
|
||||
HOMEDIR = (File.expand_path('~/.rdoc') rescue nil)
|
||||
#:startdoc:
|
||||
|
||||
@gemdirs = nil
|
||||
|
|
|
@ -359,6 +359,8 @@ class RDoc::RubyLex
|
|||
"(" => ")"
|
||||
}
|
||||
|
||||
PERCENT_PAREN_REV = PERCENT_PAREN.invert
|
||||
|
||||
Ltype2Token = {
|
||||
"\'" => TkSTRING,
|
||||
"\"" => TkSTRING,
|
||||
|
@ -1120,7 +1122,12 @@ class RDoc::RubyLex
|
|||
def identify_string(ltype, quoted = ltype)
|
||||
@ltype = ltype
|
||||
@quoted = quoted
|
||||
str = @ltype.dup
|
||||
|
||||
str = if ltype == quoted then
|
||||
ltype.dup
|
||||
else
|
||||
"%#{PERCENT_PAREN_REV[quoted]}"
|
||||
end
|
||||
|
||||
subtype = nil
|
||||
begin
|
||||
|
@ -1136,6 +1143,7 @@ class RDoc::RubyLex
|
|||
subtype = true
|
||||
if ch == "{" then
|
||||
str << ch << skip_inner_expression
|
||||
next
|
||||
else
|
||||
ungetc
|
||||
end
|
||||
|
@ -1179,7 +1187,7 @@ class RDoc::RubyLex
|
|||
def skip_inner_expression
|
||||
res = ""
|
||||
nest = 0
|
||||
while (ch = getc)
|
||||
while ch = getc
|
||||
res << ch
|
||||
if ch == '}'
|
||||
break if nest.zero?
|
||||
|
|
|
@ -160,24 +160,28 @@ class RDoc::Task < Rake::TaskLib
|
|||
# Create the tasks defined by this task lib.
|
||||
|
||||
def define
|
||||
desc "Build the RDoc HTML files"
|
||||
desc "Build RDoc HTML files"
|
||||
task rdoc_task_name
|
||||
|
||||
desc "Force rebuild RDoc HTML files"
|
||||
desc "Rebuild RDoc HTML files"
|
||||
task rerdoc_task_name => [clobber_task_name, rdoc_task_name]
|
||||
|
||||
desc "Remove RDoc HTML files"
|
||||
task clobber_task_name do
|
||||
rm_r rdoc_dir rescue nil
|
||||
rm_r @rdoc_dir rescue nil
|
||||
end
|
||||
|
||||
task :clobber => [clobber_task_name]
|
||||
|
||||
directory @rdoc_dir
|
||||
|
||||
rdoc_target_deps = [
|
||||
@rdoc_files,
|
||||
Rake.application.rakefile
|
||||
].flatten.compact
|
||||
|
||||
task rdoc_task_name => [rdoc_target]
|
||||
file rdoc_target => @rdoc_files + [Rake.application.rakefile] do
|
||||
rm_r @rdoc_dir rescue nil
|
||||
file rdoc_target => rdoc_target_deps do
|
||||
@before_running_rdoc.call if @before_running_rdoc
|
||||
args = option_list + @rdoc_files
|
||||
|
||||
|
|
4
re.c
4
re.c
|
@ -3456,9 +3456,7 @@ re_warn(const char *s)
|
|||
* <code>%r{...}</code> literals, and by the <code>Regexp::new</code>
|
||||
* constructor.
|
||||
*
|
||||
* A comprehensive reference for regexp syntax and usage is available as
|
||||
* +Doc::Regexp+.
|
||||
*
|
||||
* :include: doc/re.rdoc
|
||||
*/
|
||||
|
||||
void
|
||||
|
|
1
test/rdoc/README
Normal file
1
test/rdoc/README
Normal file
|
@ -0,0 +1 @@
|
|||
you don't have to
|
|
@ -2,25 +2,42 @@ require File.expand_path '../xref_test_case', __FILE__
|
|||
|
||||
class RDocAnyMethodTest < XrefTestCase
|
||||
|
||||
def test_arglists
|
||||
m = RDoc::AnyMethod.new nil, 'method'
|
||||
|
||||
assert_nil m.arglists
|
||||
|
||||
m.params = "(a, b)"
|
||||
m.block_params = "c, d"
|
||||
|
||||
assert_equal "method(a, b) { |c, d| ... }", m.arglists
|
||||
|
||||
call_seq = <<-SEQ
|
||||
method(a) { |c| ... }
|
||||
method(a, b) { |c, d| ... }
|
||||
SEQ
|
||||
|
||||
m.call_seq = call_seq.dup
|
||||
|
||||
assert_equal call_seq, m.arglists
|
||||
end
|
||||
|
||||
def test_full_name
|
||||
assert_equal 'C1::m', @c1.method_list.first.full_name
|
||||
end
|
||||
|
||||
def test_parent_name
|
||||
assert_equal 'C1', @c1.method_list.first.parent_name
|
||||
assert_equal 'C1', @c1.method_list.last.parent_name
|
||||
end
|
||||
|
||||
def test_marshal_load
|
||||
instance_method = Marshal.load Marshal.dump(@c1.method_list.last)
|
||||
|
||||
assert_equal 'C1#m', instance_method.full_name
|
||||
assert_equal 'C1', instance_method.parent_name
|
||||
assert_equal 'C1#m', instance_method.full_name
|
||||
assert_equal 'C1', instance_method.parent_name
|
||||
assert_equal '(foo)', instance_method.params
|
||||
|
||||
class_method = Marshal.load Marshal.dump(@c1.method_list.first)
|
||||
|
||||
assert_equal 'C1::m', class_method.full_name
|
||||
assert_equal 'C1', class_method.parent_name
|
||||
assert_equal '()', class_method.params
|
||||
end
|
||||
|
||||
def test_name
|
||||
|
@ -29,5 +46,30 @@ class RDocAnyMethodTest < XrefTestCase
|
|||
assert_nil m.name
|
||||
end
|
||||
|
||||
def test_param_seq
|
||||
m = RDoc::AnyMethod.new nil, 'method'
|
||||
m.parent = @c1
|
||||
m.params = 'a'
|
||||
|
||||
assert_equal '(a)', m.param_seq
|
||||
|
||||
m.params = '(a)'
|
||||
|
||||
assert_equal '(a)', m.param_seq
|
||||
|
||||
m.params = "(a,\n b)"
|
||||
|
||||
assert_equal '(a, b)', m.param_seq
|
||||
|
||||
m.block_params = "c,\n d"
|
||||
|
||||
assert_equal '(a, b) { |c, d| ... }', m.param_seq
|
||||
end
|
||||
|
||||
def test_parent_name
|
||||
assert_equal 'C1', @c1.method_list.first.parent_name
|
||||
assert_equal 'C1', @c1.method_list.last.parent_name
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -8,6 +8,10 @@ class TestRDocAttr < MiniTest::Unit::TestCase
|
|||
@a = RDoc::Attr.new nil, 'attr', 'RW', ''
|
||||
end
|
||||
|
||||
def test_arglists
|
||||
assert_nil @a.arglists
|
||||
end
|
||||
|
||||
def test_block_params
|
||||
assert_nil @a.block_params
|
||||
end
|
||||
|
@ -20,6 +24,10 @@ class TestRDocAttr < MiniTest::Unit::TestCase
|
|||
assert_equal '(unknown)#attr', @a.full_name
|
||||
end
|
||||
|
||||
def test_params
|
||||
assert_nil @a.params
|
||||
end
|
||||
|
||||
def test_singleton
|
||||
refute @a.singleton
|
||||
end
|
||||
|
|
|
@ -1004,6 +1004,24 @@ the time
|
|||
assert_equal expected, @RMP.tokenize(str)
|
||||
end
|
||||
|
||||
def test_tokenize_heading_no_space
|
||||
str = <<-STR
|
||||
=Heading
|
||||
==Heading 2
|
||||
STR
|
||||
|
||||
expected = [
|
||||
[:HEADER, 1, 0, 0],
|
||||
[:TEXT, 'Heading', 1, 0],
|
||||
[:NEWLINE, "\n", 8, 0],
|
||||
[:HEADER, 2, 0, 1],
|
||||
[:TEXT, 'Heading 2', 2, 1],
|
||||
[:NEWLINE, "\n", 11, 1],
|
||||
]
|
||||
|
||||
assert_equal expected, @RMP.tokenize(str)
|
||||
end
|
||||
|
||||
def test_tokenize_label
|
||||
str = <<-STR
|
||||
[cat] l1
|
||||
|
|
42
test/rdoc/test_rdoc_markup_pre_process.rb
Normal file
42
test/rdoc/test_rdoc_markup_pre_process.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
require 'tempfile'
|
||||
require 'rubygems'
|
||||
require 'minitest/autorun'
|
||||
require 'rdoc/markup/preprocess'
|
||||
|
||||
class TestRDocMarkupPreProcess < MiniTest::Unit::TestCase
|
||||
|
||||
def setup
|
||||
@tempfile = Tempfile.new 'test_rdoc_markup_pre_process'
|
||||
@name = File.basename @tempfile.path
|
||||
@dir = File.dirname @tempfile.path
|
||||
|
||||
@pp = RDoc::Markup::PreProcess.new __FILE__, [@dir]
|
||||
end
|
||||
|
||||
def teardown
|
||||
@tempfile.close
|
||||
end
|
||||
|
||||
def test_include_file
|
||||
@tempfile.write <<-INCLUDE
|
||||
# -*- mode: rdoc; coding: utf-8; fill-column: 74; -*-
|
||||
|
||||
Regular expressions (<i>regexp</i>s) are patterns which describe the
|
||||
contents of a string.
|
||||
INCLUDE
|
||||
|
||||
@tempfile.flush
|
||||
@tempfile.rewind
|
||||
|
||||
content = @pp.include_file @name, ''
|
||||
|
||||
expected = <<-EXPECTED
|
||||
Regular expressions (<i>regexp</i>s) are patterns which describe the
|
||||
contents of a string.
|
||||
EXPECTED
|
||||
|
||||
assert_equal expected, content
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -55,7 +55,10 @@ class TestRDocParser < MiniTest::Unit::TestCase
|
|||
assert_equal @RP::Simple, @RP.can_parse(jtest_file_name)
|
||||
|
||||
jtest_rdoc_file_name = File.expand_path '../test.ja.rdoc', __FILE__
|
||||
assert_equal @RP::Ruby, @RP.can_parse(jtest_rdoc_file_name)
|
||||
assert_equal @RP::Simple, @RP.can_parse(jtest_rdoc_file_name)
|
||||
|
||||
readme_file_name = File.expand_path '../README', __FILE__
|
||||
assert_equal @RP::Simple, @RP.can_parse(readme_file_name)
|
||||
end
|
||||
|
||||
##
|
||||
|
|
|
@ -201,6 +201,26 @@ Multiline comment goes here because this comment spans multiple lines.
|
|||
assert constants.empty?, constants.inspect
|
||||
end
|
||||
|
||||
def test_find_class_comment_include
|
||||
@options.rdoc_include << File.dirname(__FILE__)
|
||||
|
||||
content = <<-EOF
|
||||
/*
|
||||
* a comment for class Foo
|
||||
*
|
||||
* :include: test.txt
|
||||
*/
|
||||
void
|
||||
Init_Foo(void) {
|
||||
VALUE foo = rb_define_class("Foo", rb_cObject);
|
||||
}
|
||||
EOF
|
||||
|
||||
klass = util_get_class content, 'foo'
|
||||
|
||||
assert_equal "a comment for class Foo\n\ntest file", klass.comment
|
||||
end
|
||||
|
||||
def test_find_class_comment_init
|
||||
content = <<-EOF
|
||||
/*
|
||||
|
|
|
@ -1246,11 +1246,19 @@ end
|
|||
|
||||
# If you're writing code like this you're doing it wrong
|
||||
|
||||
def x_test_sanity_interpolation_crazy
|
||||
def test_sanity_interpolation_crazy
|
||||
last_tk = nil
|
||||
util_parser '"#{"#{"a")}" if b}"'
|
||||
|
||||
assert_equal RDoc::RubyToken::TkDSTRING, tk.class
|
||||
assert_equal '"#{"#{"a")}" if b}"', @parser.get_tk.text
|
||||
assert_equal RDoc::RubyToken::TkNL, @parser.get_tk.class
|
||||
end
|
||||
|
||||
def test_sanity_interpolation_curly
|
||||
last_tk = nil
|
||||
util_parser '%{ #{} }'
|
||||
|
||||
assert_equal '%{ #{} }', @parser.get_tk.text
|
||||
assert_equal RDoc::RubyToken::TkNL, @parser.get_tk.class
|
||||
end
|
||||
|
||||
|
|
|
@ -22,6 +22,25 @@ class TestRDocParserSimple < MiniTest::Unit::TestCase
|
|||
@tempfile.close
|
||||
end
|
||||
|
||||
def test_remove_coding_comment
|
||||
parser = util_parser <<-TEXT
|
||||
# -*- mode: rdoc; coding: utf-8; fill-column: 74; -*-
|
||||
|
||||
Regular expressions (<i>regexp</i>s) are patterns which describe the
|
||||
contents of a string.
|
||||
TEXT
|
||||
|
||||
parser.scan
|
||||
|
||||
expected = <<-TEXT.strip
|
||||
|
||||
Regular expressions (<i>regexp</i>s) are patterns which describe the
|
||||
contents of a string.
|
||||
TEXT
|
||||
|
||||
assert_equal expected, @top_level.comment
|
||||
end
|
||||
|
||||
def test_remove_private_comments
|
||||
parser = util_parser ''
|
||||
text = "foo\n\n--\nbar\n++\n\nbaz\n"
|
||||
|
|
|
@ -15,8 +15,8 @@ class TestRDocRDoc < MiniTest::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_gather_files
|
||||
file = File.expand_path("../../../lib/rdoc.rb", __FILE__)
|
||||
assert_equal([file], @rdoc.gather_files([file, file]))
|
||||
file = File.expand_path __FILE__
|
||||
assert_equal [file], @rdoc.gather_files([file, file])
|
||||
end
|
||||
|
||||
def test_read_file_contents
|
||||
|
|
|
@ -366,7 +366,6 @@ class TestRDocRIDriver < MiniTest::Unit::TestCase
|
|||
assert_match %r%Foo::Bar#blah%, out
|
||||
assert_match %r%blah.5%, out
|
||||
assert_match %r%blah.6%, out
|
||||
assert_match %r%yields: stuff%, out
|
||||
end
|
||||
|
||||
def test_display_method_attribute
|
||||
|
@ -425,6 +424,16 @@ Foo::Bar#bother
|
|||
assert_equal expected, out
|
||||
end
|
||||
|
||||
def test_display_method_params
|
||||
util_store
|
||||
|
||||
out, err = capture_io do
|
||||
@driver.display_method 'Foo::Bar#bother'
|
||||
end
|
||||
|
||||
assert_match %r%things.*stuff%, out
|
||||
end
|
||||
|
||||
def test_expand_class
|
||||
util_store
|
||||
|
||||
|
@ -511,7 +520,7 @@ Foo::Bar#bother
|
|||
util_store
|
||||
|
||||
out, err = capture_io do
|
||||
@driver.list_known_classes
|
||||
@driver.list_known_classes
|
||||
end
|
||||
|
||||
assert_equal "Ambiguous\nFoo\nFoo::Bar\nFoo::Baz\nInc\n", out
|
||||
|
@ -675,7 +684,7 @@ Foo::Bar#bother
|
|||
def test_setup_pager
|
||||
@driver.use_stdout = false
|
||||
|
||||
pager = with_dummy_pager {@driver.setup_pager}
|
||||
pager = with_dummy_pager do @driver.setup_pager end
|
||||
|
||||
skip "couldn't find a standard pager" unless pager
|
||||
|
||||
|
@ -776,9 +785,10 @@ Foo::Bar#bother
|
|||
|
||||
@blah = RDoc::AnyMethod.new nil, 'blah'
|
||||
@blah.call_seq = "blah(5) => 5\nblah(6) => 6\n"
|
||||
@blah.block_params = "stuff"
|
||||
|
||||
@bother = RDoc::AnyMethod.new nil, 'bother'
|
||||
@bother.params = "(things)"
|
||||
@bother.block_params = "stuff"
|
||||
|
||||
@new = RDoc::AnyMethod.new nil, 'new'
|
||||
@new.singleton = true
|
||||
|
|
|
@ -11,7 +11,7 @@ class C1
|
|||
def self.m
|
||||
end
|
||||
|
||||
def m
|
||||
def m foo
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue