import re


def parse_signature(signature):
    """
    Parses one signature
    :param signature: stanc3 function signature
    :return: return type, fucntion name and list of function argument types
    """
    rest, return_type = signature.rsplit("=>", 1)
    function_name, rest = rest.split("(", 1)
    args = re.findall(r"(?:[(][^()]+[)][^,()]+)|(?:[^,()]+(?:,*[]][^,()]+)?)", rest)
    #  regex parts:        ^^^^^^functor^^^^^^     ^^^^any other arg^^^^^^^
    args = [
        i.lstrip("data").strip() if "data" in i else i.strip()
        for i in args
        if i.strip()
    ]
    return return_type.strip(), function_name.strip(), args