summaryrefslogtreecommitdiff
path: root/projects/hackc/__main__.py
blob: a7bc06fb3f9408b5638ecc9c7874f58f41276763 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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)