summaryrefslogtreecommitdiff
path: root/projects/hackc/__main__.py
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2022-08-29 20:20:08 +0800
committerFrederick Yin <fkfd@fkfd.me>2022-08-29 20:20:08 +0800
commit51e1667e716ea8c6b20f37cdec1f99eef55eccd6 (patch)
tree3b023734a7337de535923bd0c08cf86cc4a4a647 /projects/hackc/__main__.py
parentca3e66d0cb0825285af7ea34a73355cf34e00a62 (diff)
hackc: tokenizer
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)