import re
from typing import OrderedDict


def _parse_docargs(text):
    """Parse the supplied text and return OrderedDict that maps parameter names
    to descriptions.

    Args:
        text: Args section of a Google style docstring.

    Returns:
        dict: OrderedDict that maps parameter names to descriptions.
    """
    pattern = r"^(\w+):(.+)$"
    prog = re.compile(pattern)
    result = OrderedDict()
    name = None

    for line in text.splitlines():
        match = prog.match(line)

        if match:
            # If line matches regex pattern, then add match results to dict.
            name = match.group(1)
            desc = match.group(2).strip()
            result[name] = desc
        elif name:
            # If line does not match regex pattern, then append line to
            # previous argument description.
            result[name] += " " + line.strip()
        else:
            raise ValueError("Expected name: value pair; got '%s'" % line)

    return result