def find_open_and_close_braces(line_index, start, brace, lines):
    """
    Take the line where we want to start and the index where we want to start
    and find the first instance of matched open and close braces of the same
    type as brace in file file.

    :param: line (int): the index of the line we want to start searching at
    :param: start (int): the index in the line we want to start searching at
    :param: brace (string): one of the type of brace we are looking for ({, },
        [, or ])
    :param lines ([string, string, ...]): the array of lines in the file we
        are looking in.

    :return: (start, start_line, end, end_line): (int, int, int): the index
        of the start and end of whatever braces we are looking for, and the
        line number that the end is on (since it may be different than the line
        we started on)
    """
    if brace in ['[', ']']:
        open_brace = '['
        close_brace = ']'
    elif brace in ['{', '}']:
        open_brace = '{'
        close_brace = '}'
    elif brace in ['(', ')']:
        open_brace = '('
        close_brace = ')'
    else:
        return -1, -1, -1, -1
    open_braces = []
    line = lines[line_index]
    ret_open_index = line.find(open_brace, start)
    line_index_cpy = line_index
    while ret_open_index == -1:
        line_index = line_index + 1
        if line_index >= len(lines):
            return 0, line_index_cpy, 0, line_index_cpy
        line = lines[line_index]
        ret_open_index = line.find(open_brace)
    open_braces.append(open_brace)
    ret_open_line = line_index
    open_index = ret_open_index
    close_index = ret_open_index
    while len(open_braces) > 0:
        if open_index == -1 and close_index == -1:
            line_index = line_index + 1
            if line_index >= len(lines):
                return (ret_open_index, ret_open_line, ret_open_index,
                    ret_open_line)
            line = lines[line_index]
            close_index = line.find(close_brace)
            open_index = line.find(open_brace)
        else:
            if close_index != -1:
                close_index = line.find(close_brace, close_index + 1)
            if open_index != -1:
                open_index = line.find(open_brace, open_index + 1)
        if close_index != -1:
            open_braces.pop()
            if len(open_braces) == 0 and (open_index > close_index or 
                open_index == -1):
                break
        if open_index != -1:
            open_braces.append(open_brace)
    ret_close_index = close_index
    return ret_open_index, ret_open_line, ret_close_index, line_index
