fix bad regexes

This commit is contained in:
Maximilian Keßler 2022-02-16 16:57:13 +01:00
parent 7a7e199f91
commit f54b569e26

View file

@ -1,13 +1,14 @@
from constants import ENVIRONMENTS, ALPHABETS, DEPRECATED
import re
import pathlib
from pathlib import Path
def _migrate_lazy_math_alphabet(line: str, letters: str, short: str, alph: str):
for letter in letters:
while True:
m = re.search(r'\\%s%s(?=![a-zA-Z@])' % (short, letter), line)
if r'\fS' in line:
pass
m = re.search(r'\\%s%s(?![a-zA-Z@])' % (short, letter), line)
if m is None:
break
else:
@ -16,7 +17,7 @@ def _migrate_lazy_math_alphabet(line: str, letters: str, short: str, alph: str):
def migrate_lazy_math_alphabets(line: str) -> str:
for short, alph in ALPHABETS:
for short, alph in ALPHABETS.items():
if short == '':
line = _migrate_lazy_math_alphabet(line, 'NZQRCFK', '', alph)
else:
@ -30,7 +31,7 @@ def migrate_deprecated(line: str) -> str:
for old, new in DEPRECATED.items():
while True:
old = old.replace('\\', r'\\')
m = re.search(old + '(?=![a-zA-Z@])', line)
m = re.search(old + '(?![a-zA-Z@])', line)
if m is None:
break
else:
@ -64,6 +65,7 @@ def convert(path: Path):
if __name__ == "__main__":
here = Path('.')
for file in here.rglob('*.tex'):
here = Path('.').resolve()
files = here.rglob('*.tex')
for file in files:
convert(Path(file))