def _format_optionals(optionals, extra_optionals):
    """
    Formats a list of optional clauses into a string containing
    multiple OPTIONALs.
    """
    optional_str = ""
    if optionals:
        for optional in optionals:
            optional_str += """OPTIONAL
            {{
                {}
            }}
            """.format(optional)
    if extra_optionals:
        optional_str += "\n".join(extra_optionals)
    return optional_str