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.rb365
1 files changed, 108 insertions, 257 deletions
diff --git a/lib/rdoc/parser/ruby.rb b/lib/rdoc/parser/ruby.rb
index 909b02d2af..8599f655ad 100644
--- a/lib/rdoc/parser/ruby.rb
+++ b/lib/rdoc/parser/ruby.rb
@@ -8,17 +8,7 @@
# by Keiju ISHITSUKA (Nippon Rational Inc.)
#
-if ENV['RDOC_USE_PRISM_PARSER']
- require 'rdoc/parser/prism_ruby'
- RDoc::Parser.const_set(:Ruby, RDoc::Parser::PrismRuby)
- puts "========================================================================="
- puts "RDoc is using the experimental Prism parser to generate the documentation"
- puts "========================================================================="
- return
-end
-
-require 'ripper'
-require_relative 'ripper_state_lex'
+$TOKEN_DEBUG ||= nil
##
# Extracts code elements from a source file returning a TopLevel object
@@ -150,6 +140,8 @@ require_relative 'ripper_state_lex'
# Note that by default, the :method: directive will be ignored if there is a
# standard rdocable item following it.
+require 'ripper'
+
class RDoc::Parser::Ruby < RDoc::Parser
parse_files_matching(/\.rbw?$/)
@@ -173,12 +165,19 @@ class RDoc::Parser::Ruby < RDoc::Parser
def initialize(top_level, file_name, content, options, stats)
super
- content = handle_tab_width(content)
+ 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
@size = 0
@token_listeners = nil
- content = RDoc::Encoding.remove_magic_comment content
- @scanner = RDoc::Parser::RipperStateLex.parse(content)
+ @scanner = RDoc::RipperStateLex.parse(content)
@content = content
@scanner_point = 0
@prev_seek = nil
@@ -189,9 +188,6 @@ 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
@@ -248,16 +244,14 @@ class RDoc::Parser::Ruby < RDoc::Parser
comment = RDoc::Encoding.change_encoding comment, @encoding if @encoding
first_line = true
first_comment_tk_kind = nil
- line_no = nil
tk = get_tk
while tk && (:on_comment == tk[:kind] or :on_embdoc == tk[:kind])
- comment_body = retrieve_comment_body(tk)
- if first_line and comment_body =~ /\A#!/ then
+ if first_line and tk[:text] =~ /\A#!/ then
skip_tkspace
tk = get_tk
- elsif first_line and comment_body =~ /\A#\s*-\*-/ then
+ elsif first_line and tk[:text] =~ /\A#\s*-\*-/ then
first_line = false
skip_tkspace
tk = get_tk
@@ -265,13 +259,12 @@ class RDoc::Parser::Ruby < RDoc::Parser
break if first_comment_tk_kind and not first_comment_tk_kind === tk[:kind]
first_comment_tk_kind = tk[:kind]
- line_no = tk[:line_no] if first_line
first_line = false
- comment << comment_body
+ comment << tk[:text]
tk = get_tk
if :on_nl === tk then
- skip_tkspace_without_nl
+ skip_tkspace false
tk = get_tk
end
end
@@ -279,14 +272,14 @@ class RDoc::Parser::Ruby < RDoc::Parser
unget_tk tk
- new_comment comment, line_no
+ new_comment comment
end
##
# Consumes trailing whitespace from the token stream
def consume_trailing_spaces # :nodoc:
- skip_tkspace_without_nl
+ skip_tkspace false
end
##
@@ -313,7 +306,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
container.find_module_named rhs_name
end
- container.add_module_alias mod, rhs_name, constant, @top_level
+ container.add_module_alias mod, constant.name, @top_level if mod
end
##
@@ -358,20 +351,16 @@ class RDoc::Parser::Ruby < RDoc::Parser
given_name << '::'
end
- skip_tkspace_without_nl
+ skip_tkspace false
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
- c = RDoc::NormalModule.new name_t[:text]
- c.store = @store
- new_modules << [prev_container, c]
- c
+ RDoc::Context.new
else
c = prev_container.add_module RDoc::NormalModule, name_t[:text]
c.ignore unless prev_container.document_children
@@ -382,11 +371,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
record_location container
get_tk
- skip_tkspace
- if :on_lparen == peek_tk[:kind] # ProcObjectInConstant::()
- parse_method_or_yield_parameters
- break
- end
+ skip_tkspace false
name_t = get_tk
unless :on_const == name_t[:kind] || :on_ident == name_t[:kind]
raise RDoc::Error, "Invalid class or module definition: #{given_name}"
@@ -398,32 +383,9 @@ class RDoc::Parser::Ruby < RDoc::Parser
end
end
- skip_tkspace_without_nl
+ skip_tkspace false
- return [container, name_t, given_name, new_modules]
- 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
+ return [container, name_t, given_name]
end
##
@@ -441,7 +403,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
res = get_constant
- skip_tkspace_without_nl
+ skip_tkspace false
get_tkread # empty out read buffer
@@ -464,7 +426,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
def get_constant
res = ""
- skip_tkspace_without_nl
+ skip_tkspace false
tk = get_tk
while tk && ((:on_op == tk[:kind] && '::' == tk[:text]) || :on_const == tk[:kind]) do
@@ -477,83 +439,28 @@ class RDoc::Parser::Ruby < RDoc::Parser
end
##
- # Get an included module that may be surrounded by parens
+ # Get a constant that may be surrounded by parens
- def get_included_module_with_optional_parens
- skip_tkspace_without_nl
- get_tkread
- tk = get_tk
- end_token = get_end_token tk
- return '' unless end_token
+ def get_constant_with_optional_parens
+ skip_tkspace false
nest = 0
- continue = false
- only_constant = true
- while tk != nil do
- is_element_of_constant = false
- case tk[:kind]
- when :on_semicolon then
- break if nest == 0
- when :on_lbracket then
- nest += 1
- when :on_rbracket then
- nest -= 1
- when :on_lbrace then
- nest += 1
- when :on_rbrace then
- nest -= 1
- if nest <= 0
- # we might have a.each { |i| yield i }
- unget_tk(tk) if nest < 0
- break
- end
- when :on_lparen then
- nest += 1
- when end_token[:kind] then
- if end_token[:kind] == :on_rparen
- nest -= 1
- break if nest <= 0
- else
- break if nest <= 0
- end
- when :on_rparen then
- nest -= 1
- when :on_comment, :on_embdoc then
- @read.pop
- if :on_nl == end_token[:kind] and "\n" == tk[:text][-1] and
- (!continue or (tk[:state] & Ripper::EXPR_LABEL) != 0) then
- break if !continue and nest <= 0
- end
- when :on_comma then
- continue = true
- when :on_ident then
- continue = false if continue
- when :on_kw then
- case tk[:text]
- when 'def', 'do', 'case', 'for', 'begin', 'class', 'module'
- nest += 1
- when 'if', 'unless', 'while', 'until', 'rescue'
- # postfix if/unless/while/until/rescue must be EXPR_LABEL
- nest += 1 unless (tk[:state] & Ripper::EXPR_LABEL) != 0
- when 'end'
- nest -= 1
- break if nest == 0
- end
- when :on_const then
- is_element_of_constant = true
- when :on_op then
- is_element_of_constant = true if '::' == tk[:text]
- end
- only_constant = false unless is_element_of_constant
- tk = get_tk
+ while :on_lparen == (tk = peek_tk)[:kind] do
+ get_tk
+ skip_tkspace
+ nest += 1
end
- if only_constant
- get_tkread_clean(/\s+/, ' ')
- else
- ''
+ name = get_constant
+
+ while nest > 0
+ skip_tkspace
+ tk = get_tk
+ nest -= 1 if :on_rparen == tk[:kind]
end
+
+ name
end
##
@@ -567,17 +474,17 @@ class RDoc::Parser::Ruby < RDoc::Parser
def get_end_token tk # :nodoc:
case tk[:kind]
when :on_lparen
- token = RDoc::Parser::RipperStateLex::Token.new
- token[:kind] = :on_rparen
- token[:text] = ')'
- token
+ {
+ :kind => :on_rparen,
+ :text => ')'
+ }
when :on_rparen
nil
else
- token = RDoc::Parser::RipperStateLex::Token.new
- token[:kind] = :on_nl
- token[:text] = "\n"
- token
+ {
+ :kind => :on_nl,
+ :text => "\n"
+ }
end
end
@@ -699,9 +606,8 @@ class RDoc::Parser::Ruby < RDoc::Parser
##
# Creates a comment with the correct format
- def new_comment comment, line_no = nil
- c = RDoc::Comment.new comment, @top_level, :ruby
- c.line = line_no
+ def new_comment comment
+ c = RDoc::Comment.new comment, @top_level
c.format = @markup
c
end
@@ -717,7 +623,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
if args.size > 0 then
name = args[0]
rw = "R"
- skip_tkspace_without_nl
+ skip_tkspace false
tk = get_tk
if :on_comma == tk[:kind] then
@@ -798,10 +704,8 @@ class RDoc::Parser::Ruby < RDoc::Parser
al.line = line_no
read_documentation_modifiers al, RDoc::ATTR_MODIFIERS
- if al.document_self or not @track_visibility
- context.add_alias al
- @stats.add_alias al
- end
+ context.add_alias al
+ @stats.add_alias al
al
end
@@ -830,9 +734,9 @@ class RDoc::Parser::Ruby < RDoc::Parser
when end_token
if end_token == :on_rparen
nest -= 1
- break if RDoc::Parser::RipperStateLex.end?(tk) and nest <= 0
+ break if RDoc::RipperStateLex.end?(tk) and nest <= 0
else
- break if RDoc::Parser::RipperStateLex.end?(tk)
+ break if RDoc::RipperStateLex.end?(tk)
end
when :on_comment, :on_embdoc
unget_tk(tk)
@@ -856,13 +760,13 @@ 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,
name_t, given_name, comment
elsif name_t[:kind] == :on_op && name_t[:text] == '<<'
- case name = skip_parentheses { get_class_specification }
+ case name = get_class_specification
when 'self', container.name
read_documentation_modifiers cls, RDoc::CLASS_MODIFIERS
parse_statements container, SINGLE
@@ -969,15 +873,14 @@ class RDoc::Parser::Ruby < RDoc::Parser
line_no = tk[:line_no]
name = tk[:text]
- skip_tkspace_without_nl
+ skip_tkspace false
return unless name =~ /^\w+$/
- new_modules = []
if :on_op == peek_tk[:kind] && '::' == peek_tk[:text] then
unget_tk tk
- container, name_t, _, new_modules = get_class_or_module container, true
+ container, name_t, = get_class_or_module container, ignore_constants
name = name_t[:text]
end
@@ -995,7 +898,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
break if nest == 0
end
end
- skip_tkspace_without_nl
+ skip_tkspace false
is_array_or_hash = true
end
@@ -1004,14 +907,6 @@ 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
@@ -1050,7 +945,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
elsif (:on_kw == tk[:kind] && 'def' == tk[:text]) then
nest += 1
elsif (:on_kw == tk[:kind] && %w{do if unless case begin}.include?(tk[:text])) then
- if (tk[:state] & Ripper::EXPR_LABEL) == 0
+ if (tk[:state] & RDoc::RipperStateLex::EXPR_LABEL) == 0
nest += 1
end
elsif [:on_rparen, :on_rbrace, :on_rbracket].include?(tk[:kind]) ||
@@ -1058,7 +953,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
nest -= 1
elsif (:on_comment == tk[:kind] or :on_embdoc == tk[:kind]) then
unget_tk tk
- if nest <= 0 and RDoc::Parser::RipperStateLex.end?(tk) then
+ if nest <= 0 and RDoc::RipperStateLex.end?(tk) then
body = get_tkread_clean(/^[ \t]+/, '')
read_documentation_modifiers constant, RDoc::CONSTANT_MODIFIERS
break
@@ -1074,7 +969,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
break
end
elsif :on_nl == tk[:kind] then
- if nest <= 0 and RDoc::Parser::RipperStateLex.end?(tk) then
+ if nest <= 0 and RDoc::RipperStateLex.end?(tk) then
unget_tk tk
break
end
@@ -1094,14 +989,13 @@ class RDoc::Parser::Ruby < RDoc::Parser
def parse_comment container, tk, comment
return parse_comment_tomdoc container, tk, comment if @markup == 'tomdoc'
column = tk[:char_no]
- line_no = comment.line.nil? ? tk[:line_no] : comment.line
+ line_no = tk[:line_no]
comment.text = comment.text.sub(/(^# +:?)(singleton-)(method:)/, '\1\3')
singleton = !!$~
co =
if (comment.text = comment.text.sub(/^# +:?method: *(\S*).*?\n/i, '')) && !!$~ then
- line_no += $`.count("\n")
parse_comment_ghost container, comment.text, $1, column, line_no, comment
elsif (comment.text = comment.text.sub(/# +:?(attr(_reader|_writer|_accessor)?): *(\S*).*?\n/i, '')) && !!$~ then
parse_comment_attr container, $1, $3, comment
@@ -1139,10 +1033,10 @@ class RDoc::Parser::Ruby < RDoc::Parser
record_location meth
meth.start_collecting_tokens
- indent = RDoc::Parser::RipperStateLex::Token.new(1, 1, :on_sp, ' ' * column)
- position_comment = RDoc::Parser::RipperStateLex::Token.new(line_no, 1, :on_comment)
+ indent = { :line_no => 1, :char_no => 1, :kind => :on_sp, :text => ' ' * column }
+ position_comment = { :line_no => line_no, :char_no => 1, :kind => :on_comment }
position_comment[:text] = "# File #{@top_level.relative_name}, line #{line_no}"
- newline = RDoc::Parser::RipperStateLex::Token.new(0, 0, :on_nl, "\n")
+ newline = { :line_no => 0, :char_no => 0, :kind => :on_nl, :text => "\n" }
meth.add_tokens [position_comment, newline, indent]
meth.params =
@@ -1182,10 +1076,10 @@ class RDoc::Parser::Ruby < RDoc::Parser
meth.line = line_no
meth.start_collecting_tokens
- indent = RDoc::Parser::RipperStateLex::Token.new(1, 1, :on_sp, ' ' * column)
- position_comment = RDoc::Parser::RipperStateLex::Token.new(line_no, 1, :on_comment)
+ indent = { :line_no => 1, :char_no => 1, :kind => :on_sp, :text => ' ' * column }
+ position_comment = { :line_no => line_no, :char_no => 1, :kind => :on_comment }
position_comment[:text] = "# File #{@top_level.relative_name}, line #{line_no}"
- newline = RDoc::Parser::RipperStateLex::Token.new(0, 0, :on_nl, "\n")
+ newline = { :line_no => 0, :char_no => 0, :kind => :on_nl, :text => "\n" }
meth.add_tokens [position_comment, newline, indent]
meth.call_seq = signature
@@ -1209,7 +1103,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
loop do
skip_tkspace_comment
- name = get_included_module_with_optional_parens
+ name = get_constant_with_optional_parens
unless name.empty? then
obj = container.add klass, name, comment
@@ -1223,22 +1117,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
end
##
- # Parses an +included+ with a block feature of ActiveSupport::Concern.
-
- def parse_included_with_activesupport_concern container, comment # :nodoc:
- skip_tkspace_without_nl
- tk = get_tk
- unless tk[:kind] == :on_lbracket || (tk[:kind] == :on_kw && tk[:text] == 'do')
- unget_tk tk
- return nil # should be a block
- end
-
- parse_statements container
-
- container
- end
-
- ##
# Parses identifiers that can create new methods or change visibility.
#
# Returns true if the comment was not consumed.
@@ -1349,7 +1227,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
add_token tk
add_token_listener self
- skip_tkspace_without_nl
+ skip_tkspace false
comment.text = comment.text.sub(/(^# +:?)(singleton-)(method:)/, '\1\3')
singleton = !!$~
@@ -1366,10 +1244,10 @@ class RDoc::Parser::Ruby < RDoc::Parser
remove_token_listener self
meth.start_collecting_tokens
- indent = RDoc::Parser::RipperStateLex::Token.new(1, 1, :on_sp, ' ' * column)
- position_comment = RDoc::Parser::RipperStateLex::Token.new(line_no, 1, :on_comment)
+ indent = { :line_no => 1, :char_no => 1, :kind => :on_sp, :text => ' ' * column }
+ position_comment = { :line_no => line_no, :char_no => 1, :kind => :on_comment }
position_comment[:text] = "# File #{@top_level.relative_name}, line #{line_no}"
- newline = RDoc::Parser::RipperStateLex::Token.new(0, 0, :on_nl, "\n")
+ newline = { :line_no => 0, :char_no => 0, :kind => :on_nl, :text => "\n" }
meth.add_tokens [position_comment, newline, indent]
meth.add_tokens @token_stream
@@ -1464,21 +1342,15 @@ 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
meth.start_collecting_tokens
- indent = RDoc::Parser::RipperStateLex::Token.new(1, 1, :on_sp, ' ' * column)
- token = RDoc::Parser::RipperStateLex::Token.new(line_no, 1, :on_comment)
+ indent = { :line_no => 1, :char_no => 1, :kind => :on_sp, :text => ' ' * column }
+ token = { :line_no => line_no, :char_no => 1, :kind => :on_comment }
token[:text] = "# File #{@top_level.relative_name}, line #{line_no}"
- newline = RDoc::Parser::RipperStateLex::Token.new(0, 0, :on_nl, "\n")
+ newline = { :line_no => 0, :char_no => 0, :kind => :on_nl, :text => "\n" }
meth.add_tokens [token, newline, indent]
meth.add_tokens @token_stream
@@ -1544,7 +1416,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
def parse_method_name container # :nodoc:
skip_tkspace
name_t = get_tk
- back_tk = skip_tkspace_without_nl
+ back_tk = skip_tkspace(false)
singleton = false
dot = get_tk
@@ -1632,7 +1504,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
def parse_method_or_yield_parameters(method = nil,
modifiers = RDoc::METHOD_MODIFIERS)
- skip_tkspace_without_nl
+ skip_tkspace false
tk = get_tk
end_token = get_end_token tk
return '' unless end_token
@@ -1644,10 +1516,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
case tk[:kind]
when :on_semicolon then
break if nest == 0
- when :on_lbracket then
- nest += 1
- when :on_rbracket then
- nest -= 1
when :on_lbrace then
nest += 1
when :on_rbrace then
@@ -1671,7 +1539,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
when :on_comment, :on_embdoc then
@read.pop
if :on_nl == end_token[:kind] and "\n" == tk[:text][-1] and
- (!continue or (tk[:state] & Ripper::EXPR_LABEL) != 0) then
+ (!continue or (tk[:state] & RDoc::RipperStateLex::EXPR_LABEL) != 0) then
if method && method.block_params.nil? then
unget_tk tk
read_documentation_modifiers method, modifiers
@@ -1705,7 +1573,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
return if method.block_params
- skip_tkspace_without_nl
+ skip_tkspace false
read_documentation_modifiers method, RDoc::METHOD_MODIFIERS
end
@@ -1756,30 +1624,19 @@ class RDoc::Parser::Ruby < RDoc::Parser
# Parses a rescue
def parse_rescue
- skip_tkspace_without_nl
+ skip_tkspace false
while tk = get_tk
case tk[:kind]
when :on_nl, :on_semicolon, :on_comment then
break
when :on_comma then
- skip_tkspace_without_nl
+ skip_tkspace false
get_tk if :on_nl == peek_tk[:kind]
end
- skip_tkspace_without_nl
- end
- end
-
- ##
- # Retrieve comment body without =begin/=end
-
- def retrieve_comment_body(tk)
- if :on_embdoc == tk[:kind]
- tk[:text].gsub(/\A=begin.*\n/, '').gsub(/=end\n?\z/, '')
- else
- tk[:text]
+ skip_tkspace false
end
end
@@ -1793,7 +1650,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
nest = 1
save_visibility = container.visibility
- container.visibility = :public unless current_method
non_comment_seen = true
@@ -1836,20 +1692,17 @@ class RDoc::Parser::Ruby < RDoc::Parser
comment = RDoc::Encoding.change_encoding comment, @encoding if @encoding
end
- line_no = nil
while tk and (:on_comment == tk[:kind] or :on_embdoc == tk[:kind]) do
- comment_body = retrieve_comment_body(tk)
- line_no = tk[:line_no] if comment.empty?
- comment += comment_body
- comment << "\n" unless comment_body =~ /\n\z/
+ comment += tk[:text]
+ comment += "\n" unless "\n" == tk[:text].chars.to_a.last
- if comment_body.size > 1 && comment_body =~ /\n\z/ then
- skip_tkspace_without_nl # leading spaces
+ if tk[:text].size > 1 && "\n" == tk[:text].chars.to_a.last then
+ skip_tkspace false # leading spaces
end
tk = get_tk
end
- comment = new_comment comment, line_no
+ comment = new_comment comment
unless comment.empty? then
look_for_directives_in container, comment
@@ -1891,7 +1744,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
end
when 'until', 'while' then
- if (tk[:state] & Ripper::EXPR_LABEL) == 0
+ if (tk[:state] & RDoc::RipperStateLex::EXPR_LABEL) == 0
nest += 1
skip_optional_do_after_expression
end
@@ -1907,7 +1760,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
skip_optional_do_after_expression
when 'case', 'do', 'if', 'unless', 'begin' then
- if (tk[:state] & Ripper::EXPR_LABEL) == 0
+ if (tk[:state] & RDoc::RipperStateLex::EXPR_LABEL) == 0
nest += 1
end
@@ -1945,8 +1798,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
parse_extend_or_include RDoc::Include, container, comment
when "extend" then
parse_extend_or_include RDoc::Extend, container, comment
- when "included" then
- parse_included_with_activesupport_concern container, comment
end
else
@@ -2030,7 +1881,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
end
loop do
- skip_tkspace_without_nl
+ skip_tkspace false
tk1 = get_tk
if tk1.nil? || :on_comma != tk1[:kind] then
@@ -2155,7 +2006,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] =~ /:?\b([\w-]+):\s*(.*)/
+ return unless tk[:text] =~ /\s*:?([\w-]+):\s*(.*)/
directive = $1.downcase
@@ -2179,7 +2030,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
# See also RDoc::Markup::PreProcess#handle_directive
def read_documentation_modifiers context, allowed
- skip_tkspace_without_nl
+ skip_tkspace(false)
directive, value = read_directive allowed
return unless directive
@@ -2223,16 +2074,13 @@ 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
@@ -2241,9 +2089,12 @@ class RDoc::Parser::Ruby < RDoc::Parser
EOF
- unless code.empty? then
- $stderr.puts code
+ unless bytes.empty? then
$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
@@ -2257,7 +2108,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
# while, until, and for have an optional do
def skip_optional_do_after_expression
- skip_tkspace_without_nl
+ skip_tkspace false
tk = get_tk
b_nest = 0
@@ -2289,7 +2140,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
tk = get_tk
end
- skip_tkspace_without_nl
+ skip_tkspace false
get_tk if peek_tk && :on_kw == peek_tk[:kind] && 'do' == peek_tk[:text]
end
@@ -2298,9 +2149,9 @@ class RDoc::Parser::Ruby < RDoc::Parser
# skip the var [in] part of a 'for' statement
def skip_for_variable
- skip_tkspace_without_nl
+ skip_tkspace false
get_tk
- skip_tkspace_without_nl
+ skip_tkspace false
tk = get_tk
unget_tk(tk) unless :on_kw == tk[:kind] and 'in' == tk[:text]
end
@@ -2319,7 +2170,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
def skip_tkspace_comment(skip_nl = true)
loop do
- skip_nl ? skip_tkspace : skip_tkspace_without_nl
+ skip_tkspace skip_nl
next_tk = peek_tk
return if next_tk.nil? || (:on_comment != next_tk[:kind] and :on_embdoc != next_tk[:kind])
get_tk