10
0
mirror of https://gitlab.com/scemama/irpf90.git synced 2024-12-30 16:15:41 +01:00

Fixed regexp

This commit is contained in:
Anthony Scemama 2017-09-18 10:58:11 +02:00
parent 3eef718b68
commit 737074beee
4 changed files with 16 additions and 9 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -389,6 +389,9 @@ 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)
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'''
result = []
for line in text:
@ -398,16 +401,20 @@ def add_operators(text):
ls.startswith('print*') or \
ls.startswith('write('):
pass
elif "+=" in buffer:
if buffer.lstrip().startswith("if "):
re_incr = re.compile(r"(.*)(\))(\s*)(.*)(\+=)(.*$)", re.S)
line.text = re.sub(re_incr, r'\1\2\4=\4+(\6)', buffer)
else:
elif buffer.lstrip().startswith("if "):
if "+=" in buffer:
line.text = re.sub(re_incr_if, r'\1\2\4=\4+(\6)', buffer)
elif "-=" in buffer:
line.text = re.sub(re_incr_if, r'\1\2\4=\4-(\6)', buffer)
elif "*=" in 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)
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