import re


def parse_show_spanning_tree_mst_config(raw_result):
    """
    Parse the 'show spanning-tree mst-config' command raw output.

    :param str raw_result: vtysh raw result string.
    :rtype: dict
    :return: The parsed result of the show spanning-tree \
       mst-config command in a dictionary of the form:
     ::

        {
            'mst_config_id': '70:72:cf:d9:2c:f6',
            'mst_config_revision': '8'
            'no_instances': '2',
            'instance_vlan':
                {'1': ['1','2'],
                '2': ['3','4']}
        }
    """
    mst_conf_re = (
        r'\s*MST\s*config\s*ID\s*:\s*(?P<mst_config_id>[^ ]+)\s*\n'
        r'\s*MST\s*config\s*revision\s*:'
        r'\s*(?P<mst_config_revision>[0-9]+)\s*\n'
        r'\s*MST\s*config\s*digest\s*:\s*(?P<mst_digest>[^ ]+)\s*\n'
        r'\s*Number\s*of\s*instances\s*:\s*(?P<no_instances>[0-9]+)\s*\n'
    )

    instance_re = (
        r'(?P<instance>^[0-9]+)\s*(?P<vlan>.+)\s*'
    )

    error = [
        r'No\s*record\s*found\.',
        r'\s*Spanning-tree\s*is\s*disabled'
    ]

    instance = {}
    result = {}

    for error_str in error:
        re_result = re.search(error_str, raw_result)

        if (re_result):
            result['error'] = str(raw_result)
            return result

    re_result = re.search(mst_conf_re, raw_result)
    assert re_result

    result = re_result.groupdict()

    for line in raw_result.splitlines():
        re_result = re.search(instance_re, line)
        if re_result:
            partial = re_result.groupdict()
            instance[partial['instance']] = partial['vlan'].split(',')

    result['instance_vlan'] = instance

    return result