def findmatching(words, pos, w1='left parenthesis', w2='right parenthesis',
    forward=True):
    """
    Find matching parantheses.

    :param words: list, to be searched in
    :param pos: int, position of ( we want to find a match for

    :return: int, position of matching ) bracket; if there is no match, return len(s)
    """
    if forward:
        count = 1
        ps = pos + 1
        while count > 0 and ps < len(words):
            this_string = ' '.join(words[ps:])
            if this_string.startswith(w1):
                count += 1
            if this_string.startswith(w2):
                count -= 1
            if count == 0:
                break
            ps += 1
        return ps + len(w2.split()) - 1
    else:
        count = 1
        ps = pos - 1
        while count > 0 and ps >= 0:
            this_string = ' '.join(words[:ps + 1])
            if this_string.endswith(w2):
                count += 1
            if this_string.endswith(w1):
                count -= 1
            if count == 0:
                break
            ps -= 1
        return ps - len(w1.split()) + 1
