import re


def _parse_lambda(text):
    """Parse the definition of a lambda function in to a readable string."""
    text = text.split('lambda')[1]
    param, rest = text.split(':')
    param = param.strip()
    # There are three things that could terminate a lambda: an (unparenthesized)
    # comma, a new line and an (unmatched) close paren.
    term_chars = [',', '\n', ')']
    func_text = ''
    inside_paren = 0  # an int rather than a bool to keep track of nesting
    for c in rest:
        if c in term_chars and not inside_paren:
            break
        elif c == ')':  # must be inside paren
            inside_paren -= 1
        elif c == '(':
            inside_paren += 1
        func_text += c

    # Rename the lambda parameter to 'value' so that the resulting
    # "description" makes more sense.
    func_text = re.sub(r'\b{}\b'.format(param), 'value', func_text)

    return func_text