def parse_statements(container, single = NORMAL, current_method = nil,
def parse_statements(container, single = NORMAL, current_method = nil,
comment = '')
nest = 1
save_visibility = container.visibility
non_comment_seen = true
while tk = get_tk do
keep_comment = false
non_comment_seen = true unless TkCOMMENT === tk
case tk
when TkNL then
skip_tkspace
tk = get_tk
if TkCOMMENT === tk then
if non_comment_seen then
# Look for RDoc in a comment about to be thrown away
parse_comment container, tk, comment unless comment.empty?
comment = ''
non_comment_seen = false
end
while TkCOMMENT === tk do
comment << tk.text << "\n"
tk = get_tk # this is the newline
skip_tkspace false # leading spaces
tk = get_tk
end
unless comment.empty? then
look_for_directives_in container, comment
if container.done_documenting then
container.ongoing_visibility = save_visibility
end
end
keep_comment = true
else
non_comment_seen = true
end
unget_tk tk
keep_comment = true
when TkCLASS then
if container.document_children then
parse_class container, single, tk, comment
else
nest += 1
end
when TkMODULE then
if container.document_children then
parse_module container, single, tk, comment
else
nest += 1
end
when TkDEF then
if container.document_self then
parse_method container, single, tk, comment
else
nest += 1
end
when TkCONSTANT then
if container.document_self then
parse_constant container, tk, comment
end
when TkALIAS then
if container.document_self and not current_method then
parse_alias container, single, tk, comment
end
when TkYIELD 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
# 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.
when TkUNTIL, TkWHILE then
nest += 1
skip_optional_do_after_expression
# 'for' is trickier
when TkFOR then
nest += 1
skip_for_variable
skip_optional_do_after_expression
when TkCASE, TkDO, TkIF, TkUNLESS, TkBEGIN then
nest += 1
when TkIDENTIFIER then
if nest == 1 and current_method.nil? then
case tk.name
when 'private', 'protected', 'public', 'private_class_method',
'public_class_method', 'module_function' then
parse_visibility container, single, tk
keep_comment = true
when 'attr' then
parse_attr container, single, tk, comment
when /^attr_(reader|writer|accessor)$/ then
parse_attr_accessor container, single, tk, comment
when 'alias_method' then
parse_alias container, single, tk, comment if
container.document_self
when 'require', 'include' then
# ignore
else
if container.document_self and comment =~ /\A#\#$/ then
case comment
when /^# +:?attr(_reader|_writer|_accessor)?:/ then
parse_meta_attr container, single, tk, comment
else
parse_meta_method container, single, tk, comment
end
end
end
end
case tk.name
when "require" then
parse_require container, comment
when "include" then
parse_include container, comment
end
when TkEND then
nest -= 1
if nest == 0 then
read_documentation_modifiers container, RDoc::CLASS_MODIFIERS
container.ongoing_visibility = save_visibility
parse_comment container, tk, comment unless comment.empty?
return
end
end
comment = '' unless keep_comment
begin
get_tkread
skip_tkspace false
end while peek_tk == TkNL
end
end