Skip to content

Commit

Permalink
Import RDoc 2.5.4
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27396 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
drbrain committed Apr 19, 2010
1 parent 37e59f5 commit 75ef9e7
Show file tree
Hide file tree
Showing 14 changed files with 169 additions and 77 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Mon Apr 19 13:58:04 2010 Eric Hodel <[email protected]>

* lib/rdoc: Update to RDoc 2.5.4. Fixes #3169, #3160, #3023.

Mon Apr 19 12:46:15 2010 Nobuyoshi Nakada <[email protected]>

* lib/timeout.rb (Timeout#timeout): propagate errors to the
Expand Down
2 changes: 1 addition & 1 deletion lib/rdoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def self.const_missing const_name # :nodoc:
##
# RDoc version you are using

VERSION = '2.5.3'
VERSION = '2.5.4'

##
# Name of the dotfile that contains the description of files to be processed
Expand Down
29 changes: 11 additions & 18 deletions lib/rdoc/any_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ class RDoc::AnyMethod < RDoc::CodeObject

attr_reader :aliases

##
# Fragment reference for this method

attr_reader :aref

##
# The method we're aliasing

Expand All @@ -67,21 +62,13 @@ class RDoc::AnyMethod < RDoc::CodeObject

include RDoc::TokenStream

##
# Resets method fragment reference counter

def self.reset
@@aref = 'M000000'
end

reset

def initialize(text, name)
super()

@text = text
@name = name

@aref = nil
@aliases = []
@block_params = nil
@call_seq = nil
Expand All @@ -92,9 +79,6 @@ def initialize(text, name)
@singleton = nil
@token_stream = nil
@visibility = :public

@aref = @@aref
@@aref = @@aref.succ
end

##
Expand All @@ -111,6 +95,15 @@ def add_alias(method)
@aliases << method
end

##
# HTML fragment reference for this method

def aref
type = singleton ? 'c' : 'i'

"method-#{type}-#{CGI.escape name}"
end

##
# The call_seq or the param_seq with method name, if there is no call_seq.
#
Expand Down Expand Up @@ -248,7 +241,7 @@ def parent_name
# Path to this method

def path
"#{@parent.path}##{@aref}"
"#{@parent.path}##{aref}"
end

##
Expand Down
18 changes: 18 additions & 0 deletions lib/rdoc/code_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@
#
# We contain the common stuff for contexts (which are containers) and other
# elements (methods, attributes and so on)
#
# Here's the tree of the CodeObject subclasses:
#
# * RDoc::Context
# * RDoc::TopLevel
# * RDoc::ClassModule
# * RDoc::AnonClass
# * RDoc::NormalClass
# * RDoc::NormalModule
# * RDoc::SingleClass
# * RDoc::AnyMethod
# * RDoc::GhostMethod
# * RDoc::MetaMethod
# * RDoc::Alias
# * RDoc::Attr
# * RDoc::Constant
# * RDoc::Require
# * RDoc::Include

class RDoc::CodeObject

Expand Down
28 changes: 20 additions & 8 deletions lib/rdoc/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,13 @@ def find_attribute_named(name)
@attributes.find { |m| m.name == name }
end

##
# Finds a class method with +name+ in this context

def find_class_method_named(name)
@method_list.find { |meth| meth.singleton && meth.name == name }
end

##
# Finds a constant with +name+ in this context

Expand All @@ -535,7 +542,7 @@ def find_file_named(name)
# Finds an instance method with +name+ in this context

def find_instance_method_named(name)
@method_list.find { |meth| meth.name == name && !meth.singleton }
@method_list.find { |meth| !meth.singleton && meth.name == name }
end

##
Expand All @@ -554,7 +561,14 @@ def find_local_symbol(symbol)
# Finds a instance or module method with +name+ in this context

def find_method_named(name)
@method_list.find { |meth| meth.name == name }
case name
when /\A#/ then
find_instance_method_named name[1..-1]
when /\A::/ then
find_class_method_named name[2..-1]
else
@method_list.find { |meth| meth.name == name }
end
end

##
Expand All @@ -575,7 +589,7 @@ def find_symbol(symbol, method = nil)
result = nil

case symbol
when /^::(.*)/ then
when /^::([A-Z].*)/ then
result = top_level.find_symbol($1)
when /::/ then
modules = symbol.split(/::/)
Expand All @@ -591,8 +605,9 @@ def find_symbol(symbol, method = nil)
end
end
end
end

else
unless result then
# if a method is specified, then we're definitely looking for
# a module, otherwise it could be any symbol
if method then
Expand All @@ -610,10 +625,7 @@ def find_symbol(symbol, method = nil)
end
end

if result and method then
fail unless result.respond_to? :find_local_symbol
result = result.find_local_symbol(method)
end
result = result.find_local_symbol method if result and method

result
end
Expand Down
34 changes: 18 additions & 16 deletions lib/rdoc/markup/to_html_crossref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
#
# See CLASS_REGEXP_STR

METHOD_REGEXP_STR = '(\w+[!?=]?)(?:\([\w.+*/=<>-]*\))?'
METHOD_REGEXP_STR = '([a-z]\w*[!?=]?)(?:\([\w.+*/=<>-]*\))?'

##
# Regular expressions matching text that should potentially have
Expand All @@ -32,11 +32,14 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml

CROSSREF_REGEXP = /(
# A::B::C.meth
#{CLASS_REGEXP_STR}[\.\#]#{METHOD_REGEXP_STR}
#{CLASS_REGEXP_STR}(?:[.#]|::)#{METHOD_REGEXP_STR}
# Stand-alone method (proceeded by a #)
| \\?\##{METHOD_REGEXP_STR}
# Stand-alone method (proceeded by ::)
| ::#{METHOD_REGEXP_STR}
# A::B::C
# The stuff after CLASS_REGEXP_STR is a
# nasty hack. CLASS_REGEXP_STR unfortunately matches
Expand Down Expand Up @@ -86,11 +89,11 @@ def initialize(from_path, context, show_hash)
end

##
# We're invoked when any text matches the CROSSREF pattern (defined in
# MarkUp). If we find the corresponding reference, generate a hyperlink.
# If the name we're looking for contains no punctuation, we look for it up
# the module/class chain. For example, HyperlinkHtml is found, even without
# the Generator:: prefix, because we look for it in module Generator first.
# We're invoked when any text matches the CROSSREF pattern. If we find the
# corresponding reference, generate a hyperlink. If the name we're looking
# for contains no punctuation, we look for it up the module/class chain.
# For example, HyperlinkHtml is found, even without the Generator:: prefix,
# because we look for it in module Generator first.

def handle_special_CROSSREF(special)
name = special.text
Expand All @@ -102,12 +105,9 @@ def handle_special_CROSSREF(special)

return @seen[name] if @seen.include? name

if name[0, 1] == '#' then
lookup = name[1..-1]
name = lookup unless @show_hash
else
lookup = name
end
lookup = name

name = name[0, 1] unless @show_hash if name[0, 1] == '#'

# Find class, module, or method in class or module.
#
Expand All @@ -119,9 +119,11 @@ def handle_special_CROSSREF(special)
# (in which case it would match the last pattern, which just checks
# whether the string as a whole is a known symbol).

if /#{CLASS_REGEXP_STR}[\.\#]#{METHOD_REGEXP_STR}/ =~ lookup then
if /#{CLASS_REGEXP_STR}([.#]|::)#{METHOD_REGEXP_STR}/ =~ lookup then
container = $1
method = $2
type = $2
type = '#' if type == '.'
method = "#{type}#{$3}"
ref = @context.find_symbol container, method
end

Expand All @@ -132,7 +134,7 @@ def handle_special_CROSSREF(special)
elsif lookup =~ /^\\/ then
$'
elsif ref and ref.document_self then
"<a href=\"#{ref.as_href(@from_path)}\">#{name}</a>"
"<a href=\"#{ref.as_href @from_path}\">#{name}</a>"
else
name
end
Expand Down
4 changes: 3 additions & 1 deletion lib/rdoc/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ def self.binary?(file)
false
elsif s.scan(/<%|%>/).length >= 4 || s.index("\x00") then
true
else
elsif 0.respond_to? :fdiv then
s.count("^ -~\t\r\n").fdiv(s.size) > 0.3
else # HACK 1.8.6
(s.count("^ -~\t\r\n").to_f / s.size) > 0.3
end
end

Expand Down
18 changes: 12 additions & 6 deletions lib/rdoc/parser/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1524,24 +1524,29 @@ def skip_optional_do_after_expression
skip_tkspace false
tk = get_tk
case tk
when TkLPAREN, TkfLPAREN
when TkLPAREN, TkfLPAREN then
end_token = TkRPAREN
else
end_token = TkNL
end

b_nest = 0
nest = 0
@scanner.instance_eval{@continue = false}
@scanner.instance_eval { @continue = false }

loop do
case tk
when TkSEMICOLON
break
when TkLPAREN, TkfLPAREN
when TkSEMICOLON then
break if b_nest.zero?
when TkLPAREN, TkfLPAREN then
nest += 1
when TkBEGIN then
b_nest += 1
when TkEND then
b_nest -= 1
when TkDO
break if nest.zero?
when end_token
when end_token then
if end_token == TkRPAREN
nest -= 1
break if @scanner.lex_state == EXPR_END and nest.zero?
Expand All @@ -1553,6 +1558,7 @@ def skip_optional_do_after_expression
end
tk = get_tk
end

skip_tkspace false

get_tk if TkDO === peek_tk
Expand Down
1 change: 0 additions & 1 deletion lib/rdoc/rdoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ def remove_unparseable files
def document(argv)
RDoc::TopLevel.reset
RDoc::Parser::C.reset
RDoc::AnyMethod.reset

@options = RDoc::Options.new
@options.parse argv
Expand Down
10 changes: 10 additions & 0 deletions test/rdoc/test_rdoc_any_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

class RDocAnyMethodTest < XrefTestCase

def test_aref
m = RDoc::AnyMethod.new nil, 'method?'

assert_equal 'method-i-method%3F', m.aref

m.singleton = true

assert_equal 'method-c-method%3F', m.aref
end

def test_arglists
m = RDoc::AnyMethod.new nil, 'method'

Expand Down
16 changes: 15 additions & 1 deletion test/rdoc/test_rdoc_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,14 @@ def test_find_attribute_named
assert_equal 'RW', @c1.find_attribute_named('attr_accessor').rw
end

def test_find_class_method_named
assert_equal nil, @c1.find_class_method_named('none')

m = @c1.find_class_method_named('m')
assert_instance_of RDoc::AnyMethod, m
assert m.singleton
end

def test_find_constant_named
assert_equal nil, @c1.find_constant_named('NONE')
assert_equal ':const', @c1.find_constant_named('CONST').value
Expand All @@ -248,7 +256,7 @@ def test_find_instance_method_named

m = @c1.find_instance_method_named('m')
assert_instance_of RDoc::AnyMethod, m
assert_equal false, m.singleton
refute m.singleton
end

def test_find_local_symbol
Expand Down Expand Up @@ -278,6 +286,12 @@ def test_find_symbol
assert_equal @c2_c3, @c2.find_symbol('C3')
end

def test_find_symbol_method
assert_equal @c1__m, @c1.find_symbol('m')
assert_equal @c1_m, @c1.find_symbol('#m')
assert_equal @c1__m, @c1.find_symbol('::m')
end

def test_spaceship
assert_equal(-1, @c2.<=>(@c3))
assert_equal 0, @c2.<=>(@c2)
Expand Down
Loading

0 comments on commit 75ef9e7

Please sign in to comment.