From ad23d39a3e12422c1df9af49cbe75e0d93766f0f Mon Sep 17 00:00:00 2001
From: Daniel Brown <ddb@star.sr.bham.ac.uk>
Date: Tue, 12 Aug 2014 12:44:00 +0100
Subject: [PATCH] fixing parsing of consts when used multiple times in a single
 line, also checks for math operations around const name in equation

---
 pykat/finesse.py | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/pykat/finesse.py b/pykat/finesse.py
index d9d7b4e..043206e 100644
--- a/pykat/finesse.py
+++ b/pykat/finesse.py
@@ -521,10 +521,21 @@ class kat(object):
                 # check if we have a var/constant in this line
                 if line.find('$') >= 0:
                     for key in constants.keys():
-                        if line.find('$'+key+' ') > -1:
-                            constants[key].usedBy.append(line)
-                            line = line.replace('$'+key+' ', str(constants[key].value)+ ' ')
-                        elif line.endswith('$'+key):
+                        # TODO: need to fix this for checking mulitple instances of const in a single line
+                        
+                        chars = [' ', '+', '-', '*', '/', ')']
+
+                        for c in chars:
+                            none_found = False
+                            
+                            while not none_found:
+                                if line.find('$'+key+c) > -1:
+                                    constants[key].usedBy.append(line)
+                                    line = line.replace('$'+key+c, str(constants[key].value)+ c)
+                                else:
+                                    none_found = True
+                        
+                        if line.endswith('$'+key):
                             constants[key].usedBy.append(line)
                             line = line.replace('$'+key, str(constants[key].value))
                         
-- 
GitLab