summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-19 05:08:28 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-19 05:08:28 +0000
commit75ef9e79d6f872d9155cfa69d717b0c693be7fc9 (patch)
tree97fa40e34793b267292d9d769150292a43f3838e /lib
parent37e59f5583c781e98f41608251e094377237a133 (diff)
Import RDoc 2.5.4
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27396 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/rdoc.rb2
-rw-r--r--lib/rdoc/any_method.rb29
-rw-r--r--lib/rdoc/code_object.rb18
-rw-r--r--lib/rdoc/context.rb28
-rw-r--r--lib/rdoc/markup/to_html_crossref.rb34
-rw-r--r--lib/rdoc/parser.rb4
-rw-r--r--lib/rdoc/parser/ruby.rb18
-rw-r--r--lib/rdoc/rdoc.rb1
8 files changed, 83 insertions, 51 deletions
diff --git a/lib/rdoc.rb b/lib/rdoc.rb
index c415b43739..da4fb72782 100644
--- a/lib/rdoc.rb
+++ b/lib/rdoc.rb
@@ -383,7 +383,7 @@ module RDoc
##
# 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
diff --git a/lib/rdoc/any_method.rb b/lib/rdoc/any_method.rb
index f3f83363cd..db59403e22 100644
--- a/lib/rdoc/any_method.rb
+++ b/lib/rdoc/any_method.rb
@@ -46,11 +46,6 @@ class RDoc::AnyMethod < RDoc::CodeObject
attr_reader :aliases
##
- # Fragment reference for this method
-
- attr_reader :aref
-
- ##
# The method we're aliasing
attr_accessor :is_alias_for
@@ -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
@@ -92,9 +79,6 @@ class RDoc::AnyMethod < RDoc::CodeObject
@singleton = nil
@token_stream = nil
@visibility = :public
-
- @aref = @@aref
- @@aref = @@aref.succ
end
##
@@ -112,6 +96,15 @@ class RDoc::AnyMethod < RDoc::CodeObject
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.
#
# Use this for displaying a method's argument lists.
@@ -248,7 +241,7 @@ class RDoc::AnyMethod < RDoc::CodeObject
# Path to this method
def path
- "#{@parent.path}##{@aref}"
+ "#{@parent.path}##{aref}"
end
##
diff --git a/lib/rdoc/code_object.rb b/lib/rdoc/code_object.rb
index 5574194d00..ea1a5eaffc 100644
--- a/lib/rdoc/code_object.rb
+++ b/lib/rdoc/code_object.rb
@@ -6,6 +6,24 @@ require 'rdoc/text'
#
# 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
diff --git a/lib/rdoc/context.rb b/lib/rdoc/context.rb
index 4cf0c1914f..d55c5a9164 100644
--- a/lib/rdoc/context.rb
+++ b/lib/rdoc/context.rb
@@ -511,6 +511,13 @@ class RDoc::Context < RDoc::CodeObject
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
def find_constant_named(name)
@@ -535,7 +542,7 @@ class RDoc::Context < RDoc::CodeObject
# 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
##
@@ -554,7 +561,14 @@ class RDoc::Context < RDoc::CodeObject
# 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
##
@@ -575,7 +589,7 @@ class RDoc::Context < RDoc::CodeObject
result = nil
case symbol
- when /^::(.*)/ then
+ when /^::([A-Z].*)/ then
result = top_level.find_symbol($1)
when /::/ then
modules = symbol.split(/::/)
@@ -591,8 +605,9 @@ class RDoc::Context < RDoc::CodeObject
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
@@ -610,10 +625,7 @@ class RDoc::Context < RDoc::CodeObject
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
diff --git a/lib/rdoc/markup/to_html_crossref.rb b/lib/rdoc/markup/to_html_crossref.rb
index 1f62ee04f9..44e71486fb 100644
--- a/lib/rdoc/markup/to_html_crossref.rb
+++ b/lib/rdoc/markup/to_html_crossref.rb
@@ -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
@@ -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
@@ -86,11 +89,11 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
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
@@ -102,12 +105,9 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
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.
#
@@ -119,9 +119,11 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
# (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
@@ -132,7 +134,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
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
diff --git a/lib/rdoc/parser.rb b/lib/rdoc/parser.rb
index 01e24e5d4b..9cfda127d9 100644
--- a/lib/rdoc/parser.rb
+++ b/lib/rdoc/parser.rb
@@ -75,8 +75,10 @@ class RDoc::Parser
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
diff --git a/lib/rdoc/parser/ruby.rb b/lib/rdoc/parser/ruby.rb
index b1684a6900..e9cdc0b83e 100644
--- a/lib/rdoc/parser/ruby.rb
+++ b/lib/rdoc/parser/ruby.rb
@@ -1524,24 +1524,29 @@ class RDoc::Parser::Ruby < RDoc::Parser
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?
@@ -1553,6 +1558,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
end
tk = get_tk
end
+
skip_tkspace false
get_tk if TkDO === peek_tk
diff --git a/lib/rdoc/rdoc.rb b/lib/rdoc/rdoc.rb
index bdc4fa0205..9c39354c6c 100644
--- a/lib/rdoc/rdoc.rb
+++ b/lib/rdoc/rdoc.rb
@@ -353,7 +353,6 @@ The internal error was:
def document(argv)
RDoc::TopLevel.reset
RDoc::Parser::C.reset
- RDoc::AnyMethod.reset
@options = RDoc::Options.new
@options.parse argv