Skip to content
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

Remove ml(t)Define #1060

Merged
merged 3 commits into from
Sep 30, 2024
Merged

Remove ml(t)Define #1060

merged 3 commits into from
Sep 30, 2024

Conversation

dnezam
Copy link
Contributor

@dnezam dnezam commented Sep 28, 2024

No description provided.

import os
import re
import sys

def transform_definition(content):
    pattern = r"^val[ \t]+([a-zA-Z0-9][a-zA-Z0-9_']*)\s*=\s*mlDefine\s*`\n([^`]+?)\s*`;?"

    replacement = r"Definition \1:\n\2\nEnd\nval r = translate \1;"

    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)
@myreen myreen merged commit 71062c5 into master Sep 30, 2024
1 check was pending
@myreen myreen deleted the remove-mldefine branch September 30, 2024 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants