summaryrefslogtreecommitdiff
path: root/lib/rdoc/parser/ruby.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rdoc/parser/ruby.rb')
-rw-r--r--lib/rdoc/parser/ruby.rb59
1 files changed, 43 insertions, 16 deletions
diff --git a/lib/rdoc/parser/ruby.rb b/lib/rdoc/parser/ruby.rb
index e546fe2141..85f1cd0391 100644
--- a/lib/rdoc/parser/ruby.rb
+++ b/lib/rdoc/parser/ruby.rb
@@ -8,6 +8,9 @@
# by Keiju ISHITSUKA (Nippon Rational Inc.)
#
+require 'ripper'
+require_relative 'ripper_state_lex'
+
##
# Extracts code elements from a source file returning a TopLevel object
# containing the constituent file elements.
@@ -138,9 +141,6 @@
# Note that by default, the :method: directive will be ignored if there is a
# standard rdocable item following it.
-require 'ripper'
-require_relative 'ripper_state_lex'
-
class RDoc::Parser::Ruby < RDoc::Parser
parse_files_matching(/\.rbw?$/)
@@ -164,15 +164,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
def initialize(top_level, file_name, content, options, stats)
super
- if /\t/ =~ content then
- tab_width = @options.tab_width
- content = content.split(/\n/).map do |line|
- 1 while line.gsub!(/\t+/) {
- ' ' * (tab_width*$&.length - $`.length % tab_width)
- } && $~
- line
- end.join("\n")
- end
+ content = handle_tab_width(content)
@size = 0
@token_listeners = nil
@@ -188,6 +180,9 @@ class RDoc::Parser::Ruby < RDoc::Parser
reset
end
+ ##
+ # Return +true+ if +tk+ is a newline.
+
def tk_nl?(tk)
:on_nl == tk[:kind] or :on_ignored_nl == tk[:kind]
end
@@ -400,6 +395,29 @@ class RDoc::Parser::Ruby < RDoc::Parser
end
##
+ # Skip opening parentheses and yield the block.
+ # Skip closing parentheses too when exists.
+
+ def skip_parentheses(&block)
+ left_tk = peek_tk
+
+ if :on_lparen == left_tk[:kind]
+ get_tk
+
+ ret = skip_parentheses(&block)
+
+ right_tk = peek_tk
+ if :on_rparen == right_tk[:kind]
+ get_tk
+ end
+
+ ret
+ else
+ yield
+ end
+ end
+
+ ##
# Return a superclass, which can be either a constant of an expression
def get_class_specification
@@ -771,8 +789,10 @@ class RDoc::Parser::Ruby < RDoc::Parser
al.line = line_no
read_documentation_modifiers al, RDoc::ATTR_MODIFIERS
- context.add_alias al
- @stats.add_alias al
+ if al.document_self or not @track_visibility
+ context.add_alias al
+ @stats.add_alias al
+ end
al
end
@@ -833,7 +853,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
cls = parse_class_regular container, declaration_context, single,
name_t, given_name, comment
elsif name_t[:kind] == :on_op && name_t[:text] == '<<'
- case name = get_class_specification
+ case name = skip_parentheses { get_class_specification }
when 'self', container.name
read_documentation_modifiers cls, RDoc::CLASS_MODIFIERS
parse_statements container, SINGLE
@@ -1435,6 +1455,12 @@ class RDoc::Parser::Ruby < RDoc::Parser
meth = RDoc::AnyMethod.new get_tkread, name
look_for_directives_in meth, comment
meth.singleton = single == SINGLE ? true : singleton
+ if singleton
+ # `current_line_visibility' is useless because it works against
+ # the normal method named as same as the singleton method, after
+ # the latter was defined. Of course these are different things.
+ container.current_line_visibility = :public
+ end
record_location meth
meth.line = line_no
@@ -1758,6 +1784,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
nest = 1
save_visibility = container.visibility
+ container.visibility = :public unless current_method
non_comment_seen = true
@@ -2119,7 +2146,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
if :on_nl == tk[:kind] or (:on_kw == tk[:kind] && 'def' == tk[:text]) then
return
elsif :on_comment == tk[:kind] or :on_embdoc == tk[:kind] then
- return unless tk[:text] =~ /\s*:?([\w-]+):\s*(.*)/
+ return unless tk[:text] =~ /:?\b([\w-]+):\s*(.*)/
directive = $1.downcase