aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rdoc/parser
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-26 05:56:26 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-26 05:56:26 +0000
commit98c7058bf7b3eab91c62a77cb10b09f6c8ed368e (patch)
treea90e594c950a1e3160a69f90a9e6215242937ef7 /lib/rdoc/parser
parentee83dc3fe49ac23321a055a2a4b337499d2494eb (diff)
downloadruby-98c7058bf7b3eab91c62a77cb10b09f6c8ed368e.tar.gz
Merge RDoc 6.0.3 from upstream.
It fixed the several bugs that was found after RDoc 6 releasing. From: SHIBATA Hiroshi <hsbt@ruby-lang.org> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62924 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rdoc/parser')
-rw-r--r--lib/rdoc/parser/ripper_state_lex.rb20
-rw-r--r--lib/rdoc/parser/ruby.rb35
2 files changed, 41 insertions, 14 deletions
diff --git a/lib/rdoc/parser/ripper_state_lex.rb b/lib/rdoc/parser/ripper_state_lex.rb
index b7cec84bfc..43f7dc1e9b 100644
--- a/lib/rdoc/parser/ripper_state_lex.rb
+++ b/lib/rdoc/parser/ripper_state_lex.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
require 'ripper'
class RDoc::RipperStateLex
@@ -83,6 +84,15 @@ class RDoc::RipperStateLex
when '&&', '||', '+=', '-=', '*=', '**=',
'&=', '|=', '^=', '<<=', '>>=', '||=', '&&='
@lex_state = EXPR_BEG
+ when '::'
+ case @lex_state
+ when EXPR_ARG, EXPR_CMDARG
+ @lex_state = EXPR_DOT
+ when EXPR_FNAME, EXPR_DOT
+ @lex_state = EXPR_ARG
+ else
+ @lex_state = EXPR_BEG
+ end
else
case @lex_state
when EXPR_FNAME, EXPR_DOT
@@ -109,8 +119,10 @@ class RDoc::RipperStateLex
else
@lex_state = EXPR_BEG
end
- when 'begin'
+ when 'begin', 'case', 'when'
@lex_state = EXPR_BEG
+ when 'return', 'break'
+ @lex_state = EXPR_MID
else
if @lex_state == EXPR_FNAME
@lex_state = EXPR_END
@@ -245,7 +257,7 @@ class RDoc::RipperStateLex
case @lex_state
when EXPR_FNAME
@lex_state = EXPR_ENDFN
- when EXPR_CLASS
+ when EXPR_CLASS, EXPR_CMDARG, EXPR_MID
@lex_state = EXPR_ARG
else
@lex_state = EXPR_CMDARG
@@ -330,8 +342,10 @@ class RDoc::RipperStateLex
@heredoc_queue << retrieve_heredoc_info(tk)
@inner_lex.lex_state = EXPR_END unless RIPPER_HAS_LEX_STATE
when :on_nl, :on_ignored_nl, :on_comment, :on_heredoc_end then
- unless @heredoc_queue.empty?
+ if !@heredoc_queue.empty?
get_heredoc_tk(*@heredoc_queue.shift)
+ elsif tk[:text].nil? # :on_ignored_nl sometimes gives nil
+ tk[:text] = ''
end
when :on_words_beg then
tk = get_words_tk(tk)
diff --git a/lib/rdoc/parser/ruby.rb b/lib/rdoc/parser/ruby.rb
index 8599f655ad..6fe4a89e46 100644
--- a/lib/rdoc/parser/ruby.rb
+++ b/lib/rdoc/parser/ruby.rb
@@ -177,6 +177,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
@size = 0
@token_listeners = nil
+ content = RDoc::Encoding.remove_magic_comment content
@scanner = RDoc::RipperStateLex.parse(content)
@content = content
@scanner_point = 0
@@ -306,7 +307,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
container.find_module_named rhs_name
end
- container.add_module_alias mod, constant.name, @top_level if mod
+ container.add_module_alias mod, rhs_name, constant, @top_level
end
##
@@ -355,12 +356,15 @@ class RDoc::Parser::Ruby < RDoc::Parser
given_name << name_t[:text]
is_self = name_t[:kind] == :on_op && name_t[:text] == '<<'
+ new_modules = []
while !is_self && (tk = peek_tk) and :on_op == tk[:kind] and '::' == tk[:text] do
prev_container = container
container = container.find_module_named name_t[:text]
container ||=
if ignore_constants then
- RDoc::Context.new
+ c = RDoc::NormalModule.new name_t[:text]
+ new_modules << [prev_container, c]
+ c
else
c = prev_container.add_module RDoc::NormalModule, name_t[:text]
c.ignore unless prev_container.document_children
@@ -385,7 +389,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
skip_tkspace false
- return [container, name_t, given_name]
+ return [container, name_t, given_name, new_modules]
end
##
@@ -760,7 +764,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
line_no = tk[:line_no]
declaration_context = container
- container, name_t, given_name = get_class_or_module container
+ container, name_t, given_name, = get_class_or_module container
if name_t[:kind] == :on_const
cls = parse_class_regular container, declaration_context, single,
@@ -877,10 +881,11 @@ class RDoc::Parser::Ruby < RDoc::Parser
return unless name =~ /^\w+$/
+ new_modules = []
if :on_op == peek_tk[:kind] && '::' == peek_tk[:text] then
unget_tk tk
- container, name_t, = get_class_or_module container, ignore_constants
+ container, name_t, _, new_modules = get_class_or_module container, true
name = name_t[:text]
end
@@ -907,6 +912,14 @@ class RDoc::Parser::Ruby < RDoc::Parser
end
get_tk
+ unless ignore_constants
+ new_modules.each do |prev_c, new_module|
+ prev_c.add_module_by_normal_module new_module
+ new_module.ignore unless prev_c.document_children
+ @top_level.add_to_classes_or_modules new_module
+ end
+ end
+
value = ''
con = RDoc::Constant.new name, value, comment
@@ -2074,13 +2087,16 @@ class RDoc::Parser::Ruby < RDoc::Parser
$stderr.puts @file_name
return
end
- bytes = ''
if @scanner_point >= @scanner.size
now_line_no = @scanner[@scanner.size - 1][:line_no]
else
now_line_no = peek_tk[:line_no]
end
+ first_tk_index = @scanner.find_index { |tk| tk[:line_no] == now_line_no }
+ last_tk_index = @scanner.find_index { |tk| tk[:line_no] == now_line_no + 1 }
+ last_tk_index = last_tk_index ? last_tk_index - 1 : @scanner.size - 1
+ code = @scanner[first_tk_index..last_tk_index].map{ |t| t[:text] }.join
$stderr.puts <<-EOF
@@ -2089,12 +2105,9 @@ class RDoc::Parser::Ruby < RDoc::Parser
EOF
- unless bytes.empty? then
+ unless code.empty? then
+ $stderr.puts code
$stderr.puts
- now_line_no = peek_tk[:line_no]
- start_index = @scanner.find_index { |tk| tk[:line_no] == now_line_no }
- end_index = @scanner.find_index { |tk| tk[:line_no] == now_line_no + 1 } - 1
- $stderr.puts @scanner[start_index..end_index].join
end
raise e