def METHOD_NAME(tokens, name_map, names_referenced):
    """
    Takes an iterable of tokens and remaps any names found within using the
    `name_map` dictionary. Names not found in the map are an error.
    """
    for token in tokens:
        if token.ttype is ttypes.Name:
            try:
                name = name_map[token.value]
            except KeyError:
                raise UnknownColumnError(f"Unknown column: {token.value}")
            names_referenced.add(token.value)
            yield sqlparse.sql.Token(ttypes.Name, name)
        else:
            yield token