-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update "val foo_def = Define ...
" to use Definition syntax
#1057
Open
dnezam
wants to merge
10
commits into
master
Choose a base branch
from
new-define
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+10,974
−7,280
Conversation
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
dnezam
added
the
test failing
regression test failed on the latest commit of this pull request
label
Sep 23, 2024
Assume that content after ` starts on a new line; thus we don't remove whitespace on the left. Python code used: ```py import os import re import sys def transform_definition(content): pattern = r"^val[ \t]+([a-zA-Z0-9][a-zA-Z0-9_']*)\s*=\s*Define\s*`\n([^`]+?)\s*`;?" replacement = r"Definition \1:\n\2\nEnd" transformed_content = re.sub(pattern, replacement, content, flags=re.MULTILINE) return transformed_content def process_sml_file(filepath): with open(filepath, 'r') as file: content = file.read() transformed_content = transform_definition(content) # Overwriting the file with transformed 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__": # Check if the directory is passed as an argument 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) # Start the search and transformation process find_and_transform_sml_files(directory_to_search) ```
Used Python code: ```py import os import re import sys def transform_definition(content): # Only Define with content surrounded by ` starting in the same line should # remain at this point; for those we set the initial indentation to 2 pattern = r"^val[ \t]+([a-zA-Z0-9][a-zA-Z0-9_']*)\s*=\s*Define\s*`[ \t]*([^`]+?)\s*`;?" replacement = r"Definition \1:\n \2\nEnd" transformed_content = re.sub(pattern, replacement, content, flags=re.MULTILINE) return transformed_content def process_sml_file(filepath): with open(filepath, 'r') as file: content = file.read() transformed_content = transform_definition(content) # Overwriting the file with transformed 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__": # Check if the directory is passed as an argument 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) # Start the search and transformation process find_and_transform_sml_files(directory_to_search) ```
dnezam
removed
the
test failing
regression test failed on the latest commit of this pull request
label
Sep 23, 2024
dnezam
added
the
test failing
regression test failed on the latest commit of this pull request
label
Sep 23, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Since there are so many changes, it is a bit hard to check everything manually, which is why I included the code I used in the respective commits.