summaryrefslogtreecommitdiff
path: root/projects/hackc/__main__.py
diff options
context:
space:
mode:
Diffstat (limited to 'projects/hackc/__main__.py')
-rw-r--r--projects/hackc/__main__.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/projects/hackc/__main__.py b/projects/hackc/__main__.py
new file mode 100644
index 0000000..a7bc06f
--- /dev/null
+++ b/projects/hackc/__main__.py
@@ -0,0 +1,29 @@
+from pathlib import Path
+from argparse import ArgumentParser
+import os
+from .parser import Parser
+
+
+def compile_jack(input_path: Path, verbose: bool):
+ try:
+ filenames = os.listdir(input_path)
+ files = [Path(input_path / f) for f in filenames]
+ jack_files = filter(lambda f: f.suffix == ".jack", files)
+ except NotADirectoryError:
+ jack_files = [Path(input_path)]
+ except:
+ # TODO: error
+ return
+
+ for input_fn in jack_files:
+ parser = Parser(input_fn)
+ parser.tokenize()
+ parser.print_tokens()
+
+
+if __name__ == "__main__":
+ parser = ArgumentParser("hackc")
+ parser.add_argument("-v", "--verbose", action="store_true", help="verbose mode")
+ parser.add_argument("input_path", help="Jack file or directory")
+ args = parser.parse_args()
+ compile_jack(Path(args.input_path), args.verbose)