10
0
mirror of https://gitlab.com/scemama/irpf90.git synced 2024-12-25 05:43:33 +01:00

Fixed regexp

This commit is contained in:
Anthony Scemama 2017-09-18 15:14:18 +02:00
parent de308abded
commit cd4be303cc

View File

@ -359,9 +359,12 @@ def form(text):
###################################################################### ######################################################################
def add_operators(text): def add_operators(text):
re_incr = re.compile(r"(\s*)(.*)(\+=)(.*$)",re.S) re_incr = re.compile(r"(\s*)(.*)(\+=)(.*$)", re.S)
re_decr = re.compile(r"(\s*)(.*)(-=)(.*$)",re.S) re_decr = re.compile(r"(\s*)(.*)(-=)(.*$)", re.S)
re_mult = re.compile(r"(\s*)(.*)(\*=)(.*$)",re.S) re_mult = re.compile(r"(\s*)(.*)(\*=)(.*$)", re.S)
re_incr_if = re.compile(r"(.*)(\))(\s*)(.*)(\+=)(.*$)", re.S)
re_decr_if = re.compile(r"(.*)(\))(\s*)(.*)(-=)(.*$)", re.S)
re_mult_if = re.compile(r"(.*)(\))(\s*)(.*)(\*=)(.*$)", re.S)
'''Change additional operators''' '''Change additional operators'''
result = [] result = []
for line in text: for line in text:
@ -371,16 +374,20 @@ def add_operators(text):
ls.startswith('print*') or \ ls.startswith('print*') or \
ls.startswith('write('): ls.startswith('write('):
pass pass
elif "+=" in buffer: elif buffer.lstrip().startswith("if "):
if buffer.lstrip().startswith("if "): if "+=" in buffer:
re_incr = re.compile(r"(.*)(\))(\s*)(.*)(\+=)(.*$)",re.S) line.text = re.sub(re_incr_if, r'\1\2\4=\4+(\6)', buffer)
line.text = re.sub(re_incr,r'\1\2\4=\4+(\6)', buffer)
else:
line.text = re.sub(re_incr,r'\1\2=\2+(\4)', buffer)
elif "-=" in buffer: elif "-=" in buffer:
line.text = re.sub(re_decr,r'\1\2=\2-(\4)', buffer) line.text = re.sub(re_incr_if, r'\1\2\4=\4-(\6)', buffer)
elif "*=" in buffer: elif "*=" in buffer:
line.text = re.sub(re_mult,r'\1\2=\2*(\4)', buffer) line.text = re.sub(re_incr_if, r'\1\2\4=\4*(\6)', buffer)
else:
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) result.append(line)
return result return result