-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove val ... = save_thm( automatically
import os import re import sys def match_comment_parens(s, start_idx): if s[start_idx:start_idx + 2] == '(*': paren_count = 0 comment_content = "" for i, char in enumerate(s[start_idx:], start=start_idx): if char == '(' and s[i + 1] == '*': paren_count += 1 elif char == '*' and i + 1 < len(s) and s[i + 1] == ')': paren_count -= 1 comment_content += char if paren_count == 0: comment_content += ")" i += 1 while i + 1 < len(s) and s[i + 1].isspace(): i += 1 comment_content += s[i] return comment_content, i + 1 comment_content += char return None return "", start_idx def transform_definition(s): done_before = 0 pattern = re.compile(r"\nval[ \t]+(?:[a-zA-Z0-9][a-zA-Z0-9_']*|_)\s*=\s*save_thm\s*") match = pattern.search(s, done_before) while match: re_start, re_end = match.span() comment_parens, comment_end = match_comment_parens(s, re_end) if s[comment_end] == '(': paren_count = 0 paren_content = "" for i, char in enumerate(s[comment_end:]): if char == '(': paren_count += 1 elif char == ')': paren_count -= 1 paren_content += char if paren_count == 0: break paren_length = len(paren_content) paren_content = paren_content[1:paren_length-1] match2 = re.search(r"\"\s*(.*)\s*\",\s*(.*)\s*", paren_content, re.DOTALL) if comment_parens == "": replacement = f"\nTheorem {match2.group(1)} =\n {match2.group(2)}" else: replacement = f"\n{comment_parens}\nTheorem {match2.group(1)} =\n {match2.group(2)}" if comment_end + paren_length < len(s) and s[comment_end + paren_length] == ';': s = s[:re_start] + replacement + s[comment_end+paren_length+1:] else: s = s[:re_start] + replacement + s[comment_end+paren_length:] done_before = re_start + len(replacement) else: done_before = comment_end match = pattern.search(s, done_before) return s def process_sml_file(filepath): with open(filepath, 'r') as file: content = file.read() transformed_content = transform_definition(content) with open(filepath, 'w') as file: file.write(transformed_content) def find_and_transform_sml_files(directory): for root, _, files in os.walk(directory): for file in files: if (file.endswith("Script.sml")): filepath = os.path.join(root, file) print(f"Processing file: {filepath}") process_sml_file(filepath) if __name__ == "__main__": if len(sys.argv) != 2: print("Usage: python script.py <directory>") sys.exit(1) directory_to_search = sys.argv[1] if not os.path.isdir(directory_to_search): print(f"Error: {directory_to_search} is not a valid directory.") sys.exit(1) find_and_transform_sml_files(directory_to_search)
- Loading branch information
Showing
119 changed files
with
702 additions
and
619 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.