def METHOD_NAME() -> Node:
    or_list: list[list[Node]] = []
    result: list[Node] = []
    def wrapped_result() -> Node:
        if or_list == []:
            return wrap(result)
        else:
            or_list.append(result)
            return AnyNode([wrap(i) for i in or_list])
    while tokens:
        t = tokens.pop()
        if t.startswith("(?P<"):
            variable = Variable(METHOD_NAME(), varname=t[4:-1])
            result.append(variable)
        elif t in ("*", "*?"):
            greedy = t == "*"
            result[-1] = Repeat(result[-1], greedy=greedy)
        elif t in ("+", "+?"):
            greedy = t == "+"
            result[-1] = Repeat(result[-1], min_repeat=1, greedy=greedy)
        elif t in ("?", "??"):
            if result == []:
                raise Exception("Nothing to repeat." + repr(tokens))
            else:
                greedy = t == "?"
                result[-1] = Repeat(
                    result[-1], min_repeat=0, max_repeat=1, greedy=greedy
                )
        elif t == "|":
            or_list.append(result)
            result = []
        elif t in ("(", "(?:"):
            result.append(METHOD_NAME())
        elif t == "(?!":
            result.append(Lookahead(METHOD_NAME(), negative=True))
        elif t == "(?=":
            result.append(Lookahead(METHOD_NAME(), negative=False))
        elif t == ")":
            return wrapped_result()
        elif t.startswith("#"):
            pass
        elif t.startswith("{"):
            # TODO: implement!
            raise Exception(f"{t}-style repetition not yet supported")
        elif t.startswith("(?"):
            raise Exception("%r not supported" % t)
        elif t.isspace():
            pass
        else:
            result.append(Regex(t))
    raise Exception("Expecting ')' token")