Skip to content

Commit 75ef9e7

Browse files
committed
Import RDoc 2.5.4
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27396 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 37e59f5 commit 75ef9e7

File tree

14 files changed

+169
-77
lines changed

14 files changed

+169
-77
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Mon Apr 19 13:58:04 2010 Eric Hodel <drbrain@segment7.net>
2+
3+
* lib/rdoc: Update to RDoc 2.5.4. Fixes #3169, #3160, #3023.
4+
15
Mon Apr 19 12:46:15 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
26

37
* lib/timeout.rb (Timeout#timeout): propagate errors to the

lib/rdoc.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def self.const_missing const_name # :nodoc:
383383
##
384384
# RDoc version you are using
385385

386-
VERSION = '2.5.3'
386+
VERSION = '2.5.4'
387387

388388
##
389389
# Name of the dotfile that contains the description of files to be processed

lib/rdoc/any_method.rb

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ class RDoc::AnyMethod < RDoc::CodeObject
4545

4646
attr_reader :aliases
4747

48-
##
49-
# Fragment reference for this method
50-
51-
attr_reader :aref
52-
5348
##
5449
# The method we're aliasing
5550

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

6863
include RDoc::TokenStream
6964

70-
##
71-
# Resets method fragment reference counter
72-
73-
def self.reset
74-
@@aref = 'M000000'
75-
end
76-
77-
reset
78-
7965
def initialize(text, name)
8066
super()
8167

8268
@text = text
8369
@name = name
8470

71+
@aref = nil
8572
@aliases = []
8673
@block_params = nil
8774
@call_seq = nil
@@ -92,9 +79,6 @@ def initialize(text, name)
9279
@singleton = nil
9380
@token_stream = nil
9481
@visibility = :public
95-
96-
@aref = @@aref
97-
@@aref = @@aref.succ
9882
end
9983

10084
##
@@ -111,6 +95,15 @@ def add_alias(method)
11195
@aliases << method
11296
end
11397

98+
##
99+
# HTML fragment reference for this method
100+
101+
def aref
102+
type = singleton ? 'c' : 'i'
103+
104+
"method-#{type}-#{CGI.escape name}"
105+
end
106+
114107
##
115108
# The call_seq or the param_seq with method name, if there is no call_seq.
116109
#
@@ -248,7 +241,7 @@ def parent_name
248241
# Path to this method
249242

250243
def path
251-
"#{@parent.path}##{@aref}"
244+
"#{@parent.path}##{aref}"
252245
end
253246

254247
##

lib/rdoc/code_object.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@
66
#
77
# We contain the common stuff for contexts (which are containers) and other
88
# elements (methods, attributes and so on)
9+
#
10+
# Here's the tree of the CodeObject subclasses:
11+
#
12+
# * RDoc::Context
13+
# * RDoc::TopLevel
14+
# * RDoc::ClassModule
15+
# * RDoc::AnonClass
16+
# * RDoc::NormalClass
17+
# * RDoc::NormalModule
18+
# * RDoc::SingleClass
19+
# * RDoc::AnyMethod
20+
# * RDoc::GhostMethod
21+
# * RDoc::MetaMethod
22+
# * RDoc::Alias
23+
# * RDoc::Attr
24+
# * RDoc::Constant
25+
# * RDoc::Require
26+
# * RDoc::Include
927

1028
class RDoc::CodeObject
1129

lib/rdoc/context.rb

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,13 @@ def find_attribute_named(name)
510510
@attributes.find { |m| m.name == name }
511511
end
512512

513+
##
514+
# Finds a class method with +name+ in this context
515+
516+
def find_class_method_named(name)
517+
@method_list.find { |meth| meth.singleton && meth.name == name }
518+
end
519+
513520
##
514521
# Finds a constant with +name+ in this context
515522

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

537544
def find_instance_method_named(name)
538-
@method_list.find { |meth| meth.name == name && !meth.singleton }
545+
@method_list.find { |meth| !meth.singleton && meth.name == name }
539546
end
540547

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

556563
def find_method_named(name)
557-
@method_list.find { |meth| meth.name == name }
564+
case name
565+
when /\A#/ then
566+
find_instance_method_named name[1..-1]
567+
when /\A::/ then
568+
find_class_method_named name[2..-1]
569+
else
570+
@method_list.find { |meth| meth.name == name }
571+
end
558572
end
559573

560574
##
@@ -575,7 +589,7 @@ def find_symbol(symbol, method = nil)
575589
result = nil
576590

577591
case symbol
578-
when /^::(.*)/ then
592+
when /^::([A-Z].*)/ then
579593
result = top_level.find_symbol($1)
580594
when /::/ then
581595
modules = symbol.split(/::/)
@@ -591,8 +605,9 @@ def find_symbol(symbol, method = nil)
591605
end
592606
end
593607
end
608+
end
594609

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

613-
if result and method then
614-
fail unless result.respond_to? :find_local_symbol
615-
result = result.find_local_symbol(method)
616-
end
628+
result = result.find_local_symbol method if result and method
617629

618630
result
619631
end

lib/rdoc/markup/to_html_crossref.rb

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
2121
#
2222
# See CLASS_REGEXP_STR
2323

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

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

3333
CROSSREF_REGEXP = /(
3434
# A::B::C.meth
35-
#{CLASS_REGEXP_STR}[\.\#]#{METHOD_REGEXP_STR}
35+
#{CLASS_REGEXP_STR}(?:[.#]|::)#{METHOD_REGEXP_STR}
3636
3737
# Stand-alone method (proceeded by a #)
3838
| \\?\##{METHOD_REGEXP_STR}
3939
40+
# Stand-alone method (proceeded by ::)
41+
| ::#{METHOD_REGEXP_STR}
42+
4043
# A::B::C
4144
# The stuff after CLASS_REGEXP_STR is a
4245
# nasty hack. CLASS_REGEXP_STR unfortunately matches
@@ -86,11 +89,11 @@ def initialize(from_path, context, show_hash)
8689
end
8790

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

9598
def handle_special_CROSSREF(special)
9699
name = special.text
@@ -102,12 +105,9 @@ def handle_special_CROSSREF(special)
102105

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

105-
if name[0, 1] == '#' then
106-
lookup = name[1..-1]
107-
name = lookup unless @show_hash
108-
else
109-
lookup = name
110-
end
108+
lookup = name
109+
110+
name = name[0, 1] unless @show_hash if name[0, 1] == '#'
111111

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

122-
if /#{CLASS_REGEXP_STR}[\.\#]#{METHOD_REGEXP_STR}/ =~ lookup then
122+
if /#{CLASS_REGEXP_STR}([.#]|::)#{METHOD_REGEXP_STR}/ =~ lookup then
123123
container = $1
124-
method = $2
124+
type = $2
125+
type = '#' if type == '.'
126+
method = "#{type}#{$3}"
125127
ref = @context.find_symbol container, method
126128
end
127129

@@ -132,7 +134,7 @@ def handle_special_CROSSREF(special)
132134
elsif lookup =~ /^\\/ then
133135
$'
134136
elsif ref and ref.document_self then
135-
"<a href=\"#{ref.as_href(@from_path)}\">#{name}</a>"
137+
"<a href=\"#{ref.as_href @from_path}\">#{name}</a>"
136138
else
137139
name
138140
end

lib/rdoc/parser.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ def self.binary?(file)
7575
false
7676
elsif s.scan(/<%|%>/).length >= 4 || s.index("\x00") then
7777
true
78-
else
78+
elsif 0.respond_to? :fdiv then
7979
s.count("^ -~\t\r\n").fdiv(s.size) > 0.3
80+
else # HACK 1.8.6
81+
(s.count("^ -~\t\r\n").to_f / s.size) > 0.3
8082
end
8183
end
8284

lib/rdoc/parser/ruby.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,24 +1524,29 @@ def skip_optional_do_after_expression
15241524
skip_tkspace false
15251525
tk = get_tk
15261526
case tk
1527-
when TkLPAREN, TkfLPAREN
1527+
when TkLPAREN, TkfLPAREN then
15281528
end_token = TkRPAREN
15291529
else
15301530
end_token = TkNL
15311531
end
15321532

1533+
b_nest = 0
15331534
nest = 0
1534-
@scanner.instance_eval{@continue = false}
1535+
@scanner.instance_eval { @continue = false }
15351536

15361537
loop do
15371538
case tk
1538-
when TkSEMICOLON
1539-
break
1540-
when TkLPAREN, TkfLPAREN
1539+
when TkSEMICOLON then
1540+
break if b_nest.zero?
1541+
when TkLPAREN, TkfLPAREN then
15411542
nest += 1
1543+
when TkBEGIN then
1544+
b_nest += 1
1545+
when TkEND then
1546+
b_nest -= 1
15421547
when TkDO
15431548
break if nest.zero?
1544-
when end_token
1549+
when end_token then
15451550
if end_token == TkRPAREN
15461551
nest -= 1
15471552
break if @scanner.lex_state == EXPR_END and nest.zero?
@@ -1553,6 +1558,7 @@ def skip_optional_do_after_expression
15531558
end
15541559
tk = get_tk
15551560
end
1561+
15561562
skip_tkspace false
15571563

15581564
get_tk if TkDO === peek_tk

lib/rdoc/rdoc.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,6 @@ def remove_unparseable files
353353
def document(argv)
354354
RDoc::TopLevel.reset
355355
RDoc::Parser::C.reset
356-
RDoc::AnyMethod.reset
357356

358357
@options = RDoc::Options.new
359358
@options.parse argv

test/rdoc/test_rdoc_any_method.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
class RDocAnyMethodTest < XrefTestCase
44

5+
def test_aref
6+
m = RDoc::AnyMethod.new nil, 'method?'
7+
8+
assert_equal 'method-i-method%3F', m.aref
9+
10+
m.singleton = true
11+
12+
assert_equal 'method-c-method%3F', m.aref
13+
end
14+
515
def test_arglists
616
m = RDoc::AnyMethod.new nil, 'method'
717

0 commit comments

Comments
 (0)