diff --git a/src/constant.py b/src/constant.py index 8f0885a560bc378d1b4fcbff96ce67b1e7098e56..95b8d3f1cbc2e9c5df0645a720e5884547a8453e 100644 --- a/src/constant.py +++ b/src/constant.py @@ -64,7 +64,7 @@ EMIT_ALONE = r"(\w+)\s*\.\s*(output|out)[^\w]" EMIT_ALONE_2 = r"(\w+)\s*\.\s*(output|out)[^\w]" EMIT_EQUALS = r"\w+\s*=\s*((\w+)\s*\.\s*(output|out))[^\w]" EMIT_NAME = r'(\w+)\s*\.\s*(output|out)\s*\.\s*(\w+)' -EMIT_OPERATION = r"(\w+)\s*\.\s*(output|out)\s*[^\w]" +EMIT_OPERATION = r"((\w+)\s*\.\s*(output|out))\s*[^\w]" EMIT_TAB = r'(\w+)\s*\.\s*(output|out)\s*\[\s*(\d+)\s*\]' TUPLE_EMIT = r'\( *\w+( *\, *\w+)+ *\) *= *'+EMIT_ALONE diff --git a/src/operation.py b/src/operation.py index 3cb360b4df00903e3d8b47757a8c27bd65e60bb5..ef5b570cf530ff1bab93e2ce159a41c261db6ca9 100644 --- a/src/operation.py +++ b/src/operation.py @@ -384,18 +384,15 @@ class Operation(Executor): #TODO -> check this #I've changed this to avoid problems like this : "ch_svdb_dbs.out_occs.toList()" for match in re.finditer(constant.EMIT_OPERATION, operation+" "): - full_code, name_called = match.group(0), match.group(1) - #Check that it's a the begining of the operation - operation_until_out = operation[:operation.find("out")] - if(operation_until_out==full_code[:full_code.find("out")]): - self.add_origin_emits(full_code, name_called, "") - case_operation_starts_with_emit = True + full_code, name_called = match.group(1), match.group(2) + self.add_origin_emits(full_code, name_called, "") + #Remove the emit from the operation code -> so we don't extract it agian + operation = operation.replace(full_code, "") if(not case_operation_starts_with_emit): - #================================ #Case channel1 = channel2.something #================================ @@ -471,22 +468,7 @@ class Operation(Executor): self.add_origin(name) - ##================================ - ##join/ phase/ cross/ combine - ##================================ - #pattern= r'\.\s*(join|phase|cross|combine)\s*\(([^\)]+)\)' - #for match in re.finditer(pattern, operation): - # name = match.group(2).strip() - # #Case channel - # if(bool(re.fullmatch(r'\w+', name))): - # self.add_origin(name) - # else: - # #check and add if it's an emitted value - # emited = self.check_is_emit(name) - # if(not emited): - # raise Exception(f"I don't know what i'm looking at {name} in {self.get_code()}") - #================================ #merge/ mix/ concat/ spread/ join/ phase/ cross/ combine #================================ @@ -530,33 +512,7 @@ class Operation(Executor): self.add_origin(c.get_name()) #TODO update this -> it's an operation itselfs warnings.warn(f"I don't know what i'm looking at '{name}' in '{self.get_code()}'\n") - - ##================================ - ##merge/ mix/ concat - ##================================ - #pattern= r'\.\s*(merge|mix|concat)\s*\((\s*\w+\s*\,\s*(\w+\s*\,\s*)*\w+\s*|\s*(\w+)\s*)\)' - #for match in re.finditer(pattern, operation): - # temp=match.group(2) - # temp= temp.split(',') - # for t in temp: - # t= t.strip() - # #Here we create the channel from the name -> checks if it already exists in the workflow - # name = t - # if(bool(re.fullmatch(r'\w+', name))): - # self.add_origin(name) - # - ##================================ - ##spread - ##================================ - #pattern= r'\.\s*spread\s*\(([\s\w\.(),\"\'\{\}\[\]+-]+)\)' - #for match in re.finditer(pattern, operation): - # #Here we create the channel from the name -> checks if it already exists in the workflow - # name = match.group(1).strip() - # if(bool(re.fullmatch(r'\w+', name))): - # self.add_origin(name) - - #self.origins = list(set(origin)) - + @@ -958,11 +914,20 @@ class Operation(Executor): #This is just one value if(len(c.get_all_conditions())>1): raise Exception("This shoudn't happen") - for condition in c.get_all_conditions(): - new_body+=f"if({condition.get_value().strip()}) {{\n{temporary_channel} = {calls[c][0]}\n}}\n" - new_body+=temporary_channel - code = code.replace(origin, new_body) + conditions = c.get_all_conditions() + if(conditions!=[]): + for condition in conditions: + new_body+=f"if({condition.get_value().strip()}) {{\n{temporary_channel} = {calls[c][0]}\n}}\n" + else: + values = set(calls[c]) + if(len(values)>1): + raise Exception("This souldn't happen") + for val in values: + new_body+=f"\n{temporary_channel} = {val}" + #new_body+=temporary_channel + code = code.replace(origin, temporary_channel) temporary_index+=1 + to_add.append(new_body) to_add.reverse() for c in to_add: