def add_gate_to_line(local_qasm_line, gate_symbol, qubit_index):
    """
    Add in parallel the application of a gate on a qubit.
    Args:
        local_qasm_line: The existing line of QASM to add the gate in.
        gate_symbol: The symbol representing the gate.
        qubit_index: The index of the target qubit.

    Returns: The same line of QASM with the gate added.
    """

    # if another operation is already called on this qubit, we have to put the new gate on a new line
    if "[" + str(qubit_index) + "]" in local_qasm_line \
            or "[" + str(qubit_index) + "," in local_qasm_line \
            or "," + str(qubit_index) + "," in local_qasm_line \
            or "," + str(qubit_index) + "]" in local_qasm_line:
        local_qasm_line += "\n{} q[{}]\n".format(gate_symbol, qubit_index)

    # if the line is not empty, we need to consider what's already present
    elif local_qasm_line != "":
        # a bracket indicates this line is parallelized with the { gate | gate | gate } syntax
        if "{" in local_qasm_line:
            # remove } from the line and add it back at the end
            local_qasm_line = local_qasm_line.rstrip("}| \n") + \
                              " | " + \
                              "{} q[{}]".format(gate_symbol, qubit_index) + \
                              "}\n"

        # no bracket means we have to add the parallelization syntax ourselves
        else:
            local_qasm_line = "{" + local_qasm_line.rstrip("\n") + \
                              " | " + \
                              "{} q[{}]".format(gate_symbol, qubit_index) + "}\n"

    # else, if the line IS empty, we can just put this gate in directly
    else:
        local_qasm_line = "{} q[{}]\n".format(gate_symbol, qubit_index)
    return local_qasm_line