def p_measurement(self, p):
        """measurement : MEASURE qarg ARROW carg ';'
        | carg '=' MEASURE qarg ';'"""
        if p[1] == 'measure':
            qreg = p[2]
            creg = p[4]
        else:
            qreg = p[4]
            creg = p[1]

        if len(qreg) != len(creg):
            raise QasmException(
                f'mismatched register sizes {len(qreg)} -> {len(creg)} for measurement '
                f'at line {p.lineno(1)}'
            )

        p[0] = [
            ops.MeasurementGate(num_qubits=1, key=creg[i]).on(qreg[i]) for i in range(len(qreg))
        ]
measurement : MEASURE qarg ARROW carg ';'
        | carg '=' MEASURE qarg ';'
cirq-core/cirq/contrib/qasm_import/_parser.py