import re


def parse_netlist_to_sections(raw_netlist):
    """
    Take raw text from a netlist file and turn it into lists of lines grouped
    by section.

    Sections look like this:
        SCOPES:
        ELABORATED NODES:
        ...etc.

    Returns a dict.
    Keys are the name of the section.
    Values are an array of lines that make up that section.
    """
    # This regex matches lines that start with a caps letter, contain caps and
    # spaces, and are followed by a colon, then any characters
    section_regex = '[A-Z][A-Z ]*:.*'
    section_finder = re.compile(section_regex)
    sections = {}
    title = None
    section = []
    for line in raw_netlist.split('\n'):
        if section_finder.match(line):
            if not section:
                section = None
            if title:
                sections[title] = section
            section = []
            title, data = line.split(':')
            if data:
                section = data.strip()
        else:
            section.append(line)
    if title:
        sections[title] = section
    return sections