import sys from pylox.lox import Lox, LoxRepl DEBUG = False if __name__ == "__main__": args = sys.argv[1:] # arg 0 is the name of this script lox = Lox(debug=DEBUG) if len(args) == 0: LoxRepl(lox).run() elif len(args) == 1: lox.run_file(args[0]) else: print('nah')
description= "Yet another implementation of the Lox interpreter in Python", allow_abbrev=False) parser.add_argument("-c", metavar="STRING", type=str, required=False, help="source string to execute") parser.add_argument("source", metavar="FILE", nargs="?", type=str, default=None, help="the .lox file to interpret") parser.add_argument( "--dbg", choices=tuple(option.name for option in Debug), default=list(), action="append", help="pylox debugging options, multiple --dbg arguments can be passed") args, extra_args = parser.parse_known_args() lox = Lox(reduce(lambda a, b: a | Debug[b], args.dbg, Debug.BACKTRACE)) # Collapse all flags passed. if args.c: lox.run(args.c) elif args.source: lox.run_file(args.source) else: lox.run_interactive()