diff --git a/HISTORY.md b/HISTORY.md index fe04fe2..94ed6d5 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -32,6 +32,9 @@ Castile 0.5 * Established an abstract base class for compiler backends. * Fixed a bug where tagged values were being tagged again during a cast from a union type to another union type. +* ArgumentParser is used instead of OptionParser to parse + command-line arguments. `--version` added, `--test` (and + remaining doctests in source modules) removed. Castile 0.4 ----------- diff --git a/TODO.md b/TODO.md index c7e6ef7..d74f0d7 100644 --- a/TODO.md +++ b/TODO.md @@ -30,8 +30,6 @@ Test framework: collect the backend-independent tests into a single file, and only test it once. Run all the *other* tests on every backend. -Also make sure that doctests are run by test script. - ### Design ### Don't output final value. Command-line arguments passed to `main`. (`sysmain`?) diff --git a/src/castile/context.py b/src/castile/context.py index 180a157..c51a685 100644 --- a/src/castile/context.py +++ b/src/castile/context.py @@ -3,19 +3,6 @@ class CastileContextError(ValueError): class ScopedContext(object): - """ - >>> d = ScopedContext({ 'a': 2, 'b': 3 }) - >>> e = ScopedContext({ 'c': 4 }, parent=d) - >>> e['c'] - 4 - >>> e['b'] - 3 - >>> 'a' in e - True - >>> 'e' in e - False - - """ def __init__(self, dict, parent=None, level=None): self._dict = dict self.parent = parent @@ -47,14 +34,3 @@ def __contains__(self, key): def __repr__(self): return 'ScopedContext(%r,parent=%r)' % (self._dict, self.parent) - - -if __name__ == "__main__": - import sys - import doctest - (fails, something) = doctest.testmod() - if fails == 0: - print("All tests passed.") - sys.exit(0) - else: - sys.exit(1) diff --git a/src/castile/main.py b/src/castile/main.py index 849c760..a38711c 100644 --- a/src/castile/main.py +++ b/src/castile/main.py @@ -6,7 +6,7 @@ import sys -from optparse import OptionParser +from argparse import ArgumentParser from castile.parser import Parser from castile.eval import Program @@ -16,35 +16,35 @@ def main(argv): - optparser = OptionParser(__doc__.strip()) - optparser.add_option("-a", "--show-ast", - action="store_true", dest="show_ast", default=False, - help="show parsed AST instead of evaluating") - optparser.add_option("-c", "--compile-to", metavar='BACKEND', - dest="compile_to", default=None, - help="compile to given backend code instead " - "of evaluating directly (available backends: " - "c, javascript, ruby, stackmac)") - optparser.add_option("-p", "--parse-only", - action="store_true", dest="parse_only", - default=False, - help="parse the input program only and exit") - optparser.add_option("-t", "--test", - action="store_true", dest="test", default=False, - help="run test cases and exit") - optparser.add_option("-Y", "--no-typecheck", - action="store_false", dest="typecheck", default=True, - help="do not typecheck the program") - (options, args) = optparser.parse_args(argv[1:]) - if options.test: - import doctest - (fails, something) = doctest.testmod() - if fails == 0: - print("All tests passed.") - sys.exit(0) - else: - sys.exit(1) - with open(args[0], 'r') as f: + argparser = ArgumentParser() + + argparser.add_argument('input_files', nargs='+', metavar='FILENAME', type=str, + help='Source files containing the Castile program' + ) + argparser.add_argument("-a", "--show-ast", + action="store_true", dest="show_ast", default=False, + help="show parsed AST instead of evaluating" + ) + argparser.add_argument("-c", "--compile-to", metavar='BACKEND', + dest="compile_to", default=None, + help="compile to given backend code instead " + "of evaluating directly (available backends: " + "c, javascript, ruby, stackmac)" + ) + argparser.add_argument("-p", "--parse-only", + action="store_true", dest="parse_only", + default=False, + help="parse the input program only and exit" + ) + argparser.add_argument("-Y", "--no-typecheck", + action="store_false", dest="typecheck", default=True, + help="do not typecheck the program" + ) + argparser.add_argument('--version', action='version', version="%(prog)s 0.5") + + options = argparser.parse_args(argv[1:]) + + with open(options.input_files[0], 'r') as f: p = Parser(f.read()) ast = p.program() if options.show_ast: