From 2ae9d82ac1533894916b04607e40f0b5fd7c749e Mon Sep 17 00:00:00 2001
From: George Marchment <georgemarchment@yahoo.fr>
Date: Fri, 14 Mar 2025 12:02:54 +0100
Subject: [PATCH] Update ternary operator again

---
 src/call.py     | 1 -
 src/code_.py    | 8 +++++---
 src/workflow.py | 6 +++++-
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/call.py b/src/call.py
index 7a11909..41bba12 100644
--- a/src/call.py
+++ b/src/call.py
@@ -175,7 +175,6 @@ class Call(Executor):
                     #    channels = self.origin.get_channels_from_name_inside_level(param)
                     #if(channels==[]):
                     #    channels = self.origin.get_channels_from_name_above_level(param)
-                    #    print(param, channels)
                     #if(channels==[]):
                     #    channels = self.origin.get_channels_from_name_other_blocks_on_same_level(param)
                     if(channels==[]):
diff --git a/src/code_.py b/src/code_.py
index b256be2..98417e0 100644
--- a/src/code_.py
+++ b/src/code_.py
@@ -1,4 +1,4 @@
-from .outils import remove_comments
+from .outils import remove_comments, get_parenthese_count, get_curly_count
 from .bioflowinsighterror import BioFlowInsightError
 import re
 from . import constant
@@ -46,7 +46,7 @@ class Code:
     #This methods rewrite ternary operation into "normal" conditions
     #variable = (condition) ? Expression2 : Expression3;
     def rewrite_ternary_operation_to_normal_condition(self, code):
-        pattern = r"(\w+) *\= *([\w][^?\n]+) *\? *([^:\n]+) *\: *([^\n]+)\n"
+        pattern = r"(\w+) *\= *([^?\n]+) *\? *([^:\n]+) *\: *([^\n]+)\n"
         to_replace = []
         for match in re.finditer(pattern, code):
             variable = match.group(1)
@@ -56,7 +56,9 @@ class Code:
             new = f"if ({condition}) {{\n{variable} = {exp1}\n}}\n\n" 
             new += f"if (!({condition})) {{\n{variable} = {exp2}\n}}\n\n" 
             #else {{\n{variable} = {exp2}\n}}\n"
-            to_replace.append((old, new))
+            #Here we check that it's worked correctly -> that we have done a good parsing
+            if(get_parenthese_count(condition)==0 and get_parenthese_count(exp1)==0 and get_parenthese_count(exp2)==0 and get_curly_count(condition)==0 and get_curly_count(exp1)==0 and get_curly_count(exp2)==0):
+                to_replace.append((old, new))
         for r in to_replace:
             old, new = r
             code = code.replace(old, new)
diff --git a/src/workflow.py b/src/workflow.py
index e4ecebc..eea41a2 100644
--- a/src/workflow.py
+++ b/src/workflow.py
@@ -59,7 +59,11 @@ class Workflow:
                     with open(file, 'r') as f:
                         txt= f.read()
                 else:
-                    raise BioFlowInsightError("Multiple Nextflow files found at the root with no 'main.nf' file: I don't know which one to select")
+                    #If there are multiple files and no main -> we just choose one at random
+                    file = nextflow_files[0]
+                    with open(file, 'r') as f:
+                        txt= f.read()
+                    #raise BioFlowInsightError("Multiple Nextflow files found at the root with no 'main.nf' file: I don't know which one to select")
 
 
         
-- 
GitLab