diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/StreamOperation.py b/suite/auto-sync/src/autosync/cpptranslator/patches/StreamOperation.py index bb5298a292..0f6a2ebf22 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/StreamOperation.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/StreamOperation.py @@ -116,20 +116,19 @@ def get_patch(self, captures: [(Node, str)], src: bytes, **kwargs) -> bytes: """ query = kwargs["ts_cpp_lang"].query(queue_str) root_node = kwargs["tree"].root_node - cap = list( - filter( - lambda x: "typ" in x[1], - query.matches(root_node, end_byte=last_op.start_byte), - ) - )[-1] - typ = get_text_from_node(src, cap[1]["typ"]) - match typ: - case b"int": - res += b"printInt32(" + s_name + b", " + last_op_text + b");" - case b"int64_t": - res += b"printInt64(" + s_name + b", " + last_op_text + b");" - case _: - res += b"SStream_concat0(" + s_name + b", " + last_op_text + b");" + query_result = list(filter(lambda x: "typ" in x[1], query.matches(root_node, end_byte=last_op.start_byte))) + if len(query_result) == 0: + res += b"SStream_concat0(" + s_name + b", " + last_op_text + b");" + else: + cap = query_result[-1] + typ = get_text_from_node(src, cap[1]["typ"]) + match typ: + case b"int": + res += b"printInt32(" + s_name + b", " + last_op_text + b");" + case b"int64_t": + res += b"printInt64(" + s_name + b", " + last_op_text + b");" + case _: + res += b"SStream_concat0(" + s_name + b", " + last_op_text + b");" else: res += b"SStream_concat0(" + s_name + b", " + last_op_text + b");" stream = captures[0][0]