def parse_enclosed_expression(source, start, opening_token):
    """Parse an expression enclosed by a token and its counterpart.

    Args:
        source (str): Source code of a Bazel BUILD file, for example.
        start (int): Index at which an expression starts.
        opening_token (str): A character '(' or '[' that opens an expression.

    Returns:
        expression (str): The whole expression that contains the opening and closing tokens.

    Raises:
        NotImplementedError: If parsing is not implemented for the given opening token.
    """
    if opening_token == '(':
        closing_token = ')'
    elif opening_token == '[':
        closing_token = ']'
    else:
        raise NotImplementedError("No closing token defined for %s." % opening_token)

    start2 = source.find(opening_token, start)
    assert start2 > start, "Could not locate the opening token %s." % opening_token
    open_tokens = 0
    end = None

    for end_idx, char in enumerate(source[start2:], start2):
        if char == opening_token:
            open_tokens += 1
        elif char == closing_token:
            open_tokens -= 1

        if open_tokens == 0:
            end = end_idx + 1
            break

    assert end, "Could not locate the closing token %s." % closing_token

    expression = source[start:end]

    return expression