import re


def gen_book(bookfile):
    """
    Takes an opened SFM file and reads it into a list of lists, such that any
    verse can be indexed by chapter and verse in the format
    `book[chapter][verse]`
    """
    book = []
    for line in bookfile:
        if re.match(r"\\c", line):
            book.append([])
        elif re.match(r"\\v", line):
            book[-1].append(re.sub(r"\\v [0-9]+ ", "", line).strip())
    return book