-
-
Save ChristianKuehnel/a01cc4362b07c58281554ab46235a077 to your computer and use it in GitHub Desktop.
Pyhton script to convert matcher Macros names to start with lowercase letter.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import re | |
import os | |
# find matchers starting with upper case letter | |
pattern=re.compile(r"MATCHER(_P)?\((?P<name>[A-Z][^,\W]+)") | |
def process_file(file_path:str): | |
contents=open(file_path,"r").read() | |
for match in pattern.finditer(contents): | |
matcher_name = match.group("name") | |
fixed_name = matcher_name[0].lower() + matcher_name[1:] | |
# Ensure our replace position is not part of a substring, or starts with | |
# ".:>" is uncommon for a matcher | |
replacer=fr"([^a-zA-Z.:>])({matcher_name})([^a-zA-Z.:;])" | |
contents=re.sub(replacer, rf"\1{fixed_name}\3", contents) | |
open(file_path,"w").write(contents) | |
for root, dirs, files in os.walk(os.curdir): | |
for file in files: | |
process_file(os.path.join(root,file)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment