From 3a7e2f2af82bf4c4f21144cea3860ea15054e322 Mon Sep 17 00:00:00 2001 From: Boyan Date: Wed, 27 Nov 2024 00:54:54 +0100 Subject: [PATCH] Dictionary to handle functions instead of beefy if block --- ucompile | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/ucompile b/ucompile index 9e1fc61..7140d98 100755 --- a/ucompile +++ b/ucompile @@ -154,7 +154,12 @@ def c_compile(file_name, args): def main(): - SUPPORTED_LANGS = [".c", ".py", ".java", ".hs"] + SUPPORTED_LANGS = { + ".c": c_compile, + ".py": python_compile, + ".java": java_compile, + ".hs": haskell_compile, + } parser = argparse.ArgumentParser( prog="UCompiler", description="Compiles based on language", epilog="LOL" ) @@ -200,16 +205,8 @@ def main(): args.tests_dir = args.tests if args.tests else "." - if file_ext == ".c": - c_compile(file_name, args) - elif file_ext == ".py": - python_compile(file_name, args) - elif file_ext == ".java": - java_compile(file_name, args) - elif file_ext == ".hs": - haskell_compile(file_name, args) + SUPPORTED_LANGS[file_ext](file_name, args) - print(args) return