From bc137dc4a147496c3b473e8a5995bd7cd4660785 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Wed, 9 Dec 2009 16:48:48 +0100 Subject: [PATCH] Added +=, -=, *= operators --- src/preprocessed_text.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/preprocessed_text.py b/src/preprocessed_text.py index 9bb3c5f..9d7a3b9 100644 --- a/src/preprocessed_text.py +++ b/src/preprocessed_text.py @@ -252,6 +252,24 @@ def form(text): return Free_form return Fixed_form +###################################################################### +def add_operators(text): + re_incr = re.compile(r"(\s*)(.*)(\+=)(.*$)",re.S) + re_decr = re.compile(r"(\s*)(.*)(-=)(.*$)",re.S) + re_mult = re.compile(r"(\s*)(.*)(\*=)(.*$)",re.S) + '''Change additional operators''' + result = [] + for line in text: + buffer = line.text + if "+=" in buffer: + line.text = re.sub(re_incr,r'\1\2=\2+(\4)', buffer) + elif "-=" in buffer: + line.text = re.sub(re_decr,r'\1\2=\2-(\4)', buffer) + elif "*=" in buffer: + line.text = re.sub(re_mult,r'\1\2=\2*(\4)', buffer) + result.append(line) + return result + ###################################################################### def remove_comments(text,form): '''Remove all comments''' @@ -717,6 +735,7 @@ def create_preprocessed_text(filename): result = remove_ifdefs(result) result = remove_comments(result,fortran_form) result = remove_continuation(result,fortran_form) + result = add_operators(result) result = change_includes(result) result = change_single_line_ifs(result) result = process_old_style_do(result)