class YARD::Parser::Ruby::Legacy::StatementList

def next_statement

Returns:
  • (Statement) - the next statement
def next_statement
  @state = :first_statement
  @statement_stack = []
  @level = 0
  @block_num = 0
  @done = false
  @current_block = nil
  @comments_line = nil
  @comments_hash_flag = nil
  @statement = TokenList.new
  @block = nil
  @comments = nil
  @last_tk = nil
  @last_ns_tk = nil
  @before_last_tk = nil
  @before_last_ns_tk = nil
  @first_line = nil
  until @done
    tk = @tokens.shift
    break if tk.nil?
    process_token(tk)
    @before_last_tk = @last_tk
    @last_tk = tk # Save last token
    unless [TkSPACE, TkNL, TkEND_OF_SCRIPT].include? tk.class
      @before_last_ns_tk = @last_ns_tk
      @last_ns_tk = tk
    end
  end
  # Return the code block with starting token and initial comments
  # If there is no code in the block, return nil
  @comments = @comments.compact if @comments
  if @block || !@statement.empty?
    sanitize_statement_end
    sanitize_block
    @statement.pop if [TkNL, TkSPACE, TkSEMICOLON].include?(@statement.last.class)
    stmt = Statement.new(@statement, @block, @comments)
    if @comments && @comments_line
      stmt.comments_range = (@comments_line..(@comments_line + @comments.size - 1))
      stmt.comments_hash_flag = @comments_hash_flag
    end
    stmt
  elsif @comments
    @statement << TkCOMMENT.new(@comments_line, 0)
    @statement.first.set_text("# " + @comments.join("\n# "))
    Statement.new(@statement, nil, @comments)
  end
end