summaryrefslogtreecommitdiff
path: root/lib/rdoc
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2021-12-04 18:05:37 +0900
committergit <svn-admin@ruby-lang.org>2021-12-09 18:16:05 +0900
commit2e50989ad39a1085e04a901d072e7a2a77d1dc8f (patch)
tree7c901a9bb9001fd327f173b8753cb370a44b3c71 /lib/rdoc
parentfa806cf233938af64ce928a37d2641dd762da87a (diff)
[ruby/rdoc] Resolve class and method of the same name correctly
https://github.com/ruby/rdoc/commit/1e16284fe5
Diffstat (limited to 'lib/rdoc')
-rw-r--r--lib/rdoc/cross_reference.rb48
1 files changed, 28 insertions, 20 deletions
diff --git a/lib/rdoc/cross_reference.rb b/lib/rdoc/cross_reference.rb
index 4a6abfa3ac..ef8e21bde8 100644
--- a/lib/rdoc/cross_reference.rb
+++ b/lib/rdoc/cross_reference.rb
@@ -19,7 +19,7 @@ class RDoc::CrossReference
#
# See CLASS_REGEXP_STR
- METHOD_REGEXP_STR = '([a-z]\w*[!?=]?|%|===?|\[\]=?|<<|>>|\+@|-@|-|\+|\*)(?:\([\w.+*/=<>-]*\))?'
+ METHOD_REGEXP_STR = '([A-Za-z]\w*[!?=]?|%|===?|\[\]=?|<<|>>|\+@|-@|-|\+|\*)(?:\([\w.+*/=<>-]*\))?'
##
# Regular expressions matching text that should potentially have
@@ -34,12 +34,6 @@ class RDoc::CrossReference
# A::B::C.meth
#{CLASS_REGEXP_STR}(?:[.#]|::)#{METHOD_REGEXP_STR}
- # Stand-alone method (preceded by a #)
- | \\?\##{METHOD_REGEXP_STR}
-
- # Stand-alone method (preceded by ::)
- | ::#{METHOD_REGEXP_STR}
-
# A::B::C
# The stuff after CLASS_REGEXP_STR is a
# nasty hack. CLASS_REGEXP_STR unfortunately matches
@@ -56,6 +50,12 @@ class RDoc::CrossReference
# marker.
| #{CLASS_REGEXP_STR}(?=[@\s).?!,;<\000]|\z)
+ # Stand-alone method (preceded by a #)
+ | \\?\##{METHOD_REGEXP_STR}
+
+ # Stand-alone method (preceded by ::)
+ | ::#{METHOD_REGEXP_STR}
+
# Things that look like filenames
# The key thing is that there must be at least
# one special character (period, slash, or
@@ -82,12 +82,12 @@ class RDoc::CrossReference
# A::B::C.meth
#{CLASS_REGEXP_STR}(?:[.#]|::)#{METHOD_REGEXP_STR}
- # Stand-alone method
- | \\?#{METHOD_REGEXP_STR}
-
# A::B::C
| #{CLASS_REGEXP_STR}(?=[@\s).?!,;<\000]|\z)
+ # Stand-alone method
+ | \\?#{METHOD_REGEXP_STR}
+
# Things that look like filenames
| (?:\.\.\/)*[-\/\w]+[_\/.][-\w\/.]+
@@ -115,15 +115,8 @@ class RDoc::CrossReference
@seen = {}
end
- ##
- # Returns a reference to +name+.
- #
- # If the reference is found and +name+ is not documented +text+ will be
- # returned. If +name+ is escaped +name+ is returned. If +name+ is not
- # found +text+ is returned.
-
- def resolve name, text
- return @seen[name] if @seen.include? name
+ def resolve_method name
+ ref = nil
if /#{CLASS_REGEXP_STR}([.#]|::)#{METHOD_REGEXP_STR}/o =~ name then
type = $2
@@ -165,12 +158,27 @@ class RDoc::CrossReference
end
end
+ ref
+ end
+
+ ##
+ # Returns a reference to +name+.
+ #
+ # If the reference is found and +name+ is not documented +text+ will be
+ # returned. If +name+ is escaped +name+ is returned. If +name+ is not
+ # found +text+ is returned.
+
+ def resolve name, text
+ return @seen[name] if @seen.include? name
+
ref = case name
when /^\\(#{CLASS_REGEXP_STR})$/o then
@context.find_symbol $1
else
@context.find_symbol name
- end unless ref
+ end
+
+ ref = resolve_method name unless ref
# Try a page name
ref = @store.page name if not ref and name =~ /^[\w.]+$/