def parse_statements(container, single = NORMAL, current_method = nil,
def parse_statements(container, single = NORMAL, current_method = nil,
comment = new_comment(''))
raise 'no' unless RDoc::Comment === comment
comment = RDoc::Encoding.change_encoding comment, @encoding if @encoding
nest = 1
save_visibility = container.visibility
container.visibility = :public unless current_method
non_comment_seen = true
while tk = get_tk do
keep_comment = false
try_parse_comment = false
non_comment_seen = true unless (:on_comment == tk[:kind] or :on_embdoc == tk[:kind])
case tk[:kind]
when :on_nl, :on_ignored_nl, :on_comment, :on_embdoc then
if :on_nl == tk[:kind] or :on_ignored_nl == tk[:kind]
skip_tkspace
tk = get_tk
else
past_tokens = @read.size > 1 ? @read[0..-2] : []
nl_position = 0
past_tokens.reverse.each_with_index do |read_tk, i|
if read_tk =~ /^\n$/ then
nl_position = (past_tokens.size - 1) - i
break
elsif read_tk =~ /^#.*\n$/ then
nl_position = ((past_tokens.size - 1) - i) + 1
break
end
end
comment_only_line = past_tokens[nl_position..-1].all?{ |c| c =~ /^\s+$/ }
unless comment_only_line then
tk = get_tk
end
end
if tk and (:on_comment == tk[:kind] or :on_embdoc == tk[:kind]) then
if non_comment_seen then
# Look for RDoc in a comment about to be thrown away
non_comment_seen = parse_comment container, tk, comment unless
comment.empty?
comment = ''
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/
if comment_body.size > 1 && comment_body =~ /\n\z/ then
skip_tkspace_without_nl # leading spaces
end
tk = get_tk
end
comment = new_comment comment, line_no
unless comment.empty? then
look_for_directives_in container, comment
if container.done_documenting then
throw :eof if RDoc::TopLevel === container
container.ongoing_visibility = save_visibility
end
end
keep_comment = true
else
non_comment_seen = true
end
unget_tk tk
keep_comment = true
container.current_line_visibility = nil
when :on_kw then
case tk[:text]
when 'class' then
parse_class container, single, tk, comment
when 'module' then
parse_module container, single, tk, comment
when 'def' then
parse_method container, single, tk, comment
when 'alias' then
parse_alias container, single, tk, comment unless current_method
when 'yield' then
if current_method.nil? then
warn "Warning: yield outside of method" if container.document_self
else
parse_yield container, single, tk, current_method
end
when 'until', 'while' then
if (tk[:state] & Ripper::EXPR_LABEL) == 0
nest += 1
skip_optional_do_after_expression
end
# Until and While can have a 'do', which shouldn't increase the nesting.
# We can't solve the general case, but we can handle most occurrences by
# ignoring a do at the end of a line.
# 'for' is trickier
when 'for' then
nest += 1
skip_for_variable
skip_optional_do_after_expression
when 'case', 'do', 'if', 'unless', 'begin' then
if (tk[:state] & Ripper::EXPR_LABEL) == 0
nest += 1
end
when 'super' then
current_method.calls_super = true if current_method
when 'rescue' then
parse_rescue
when 'end' then
nest -= 1
if nest == 0 then
container.ongoing_visibility = save_visibility
parse_comment container, tk, comment unless comment.empty?
return
end
end
when :on_const then
unless parse_constant container, tk, comment, current_method then
try_parse_comment = true
end
when :on_ident then
if nest == 1 and current_method.nil? then
keep_comment = parse_identifier container, single, tk, comment
end
case tk[:text]
when "require" then
parse_require container, comment
when "include" then
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
try_parse_comment = nest == 1
end
if try_parse_comment then
non_comment_seen = parse_comment container, tk, comment unless
comment.empty?
keep_comment = false
end
unless keep_comment then
comment = new_comment ''
comment = RDoc::Encoding.change_encoding comment, @encoding if @encoding
container.params = nil
container.block_params = nil
end
consume_trailing_spaces
end
container.params = nil
container.block_params = nil
end