Esempio n. 1
0
    def _parse_and_check_mod(self, filename):
        with open(filename, 'r') as f:
            text = f.read()

        debug_file = TEST_CODE_SUBDIR + DEBUG_SUBJECT_FILE
        if filename == debug_file:
            log.enter_debug_file()
        else:
            log.exit_debug_file()

        log.debug("--- v File : " + filename + " v ---\n" + text +
                  "--- ^ File text ^ ---")

        untyped_ast = ast.parse(text)

        log.debug((log_center("v Untyped AST v") + str(untyped_ast) +
                   log_center("^ Untyped AST ^")), DEBUG_UNTYPED_AST)

        typedecs = parse_type_decs(filename)

        log.debug((log_center("v TypeDecs v") + str(typedecs) +
                   log_center("^ TypeDecs ^")), DEBUG_TYPEDECS)

        typed_ast = TypeDecASTModule(untyped_ast, typedecs)

        log.debug((log_center("v TypedAST v") + str(typed_ast) +
                   log_center("^ TypedAST ^")), DEBUG_TYPED_AST)

        return check_mod(typed_ast.tree)
Esempio n. 2
0
    def _parse_and_check_mod(self, filename):
        with open(filename, 'r') as f:
            text = f.read()

        debug_file = TEST_CODE_SUBDIR + DEBUG_SUBJECT_FILE
        if filename == debug_file:
            log.enter_debug_file()
        else:
            log.exit_debug_file()

        log.debug("--- v File : " + filename + " v ---\n" + text + "--- ^ File text ^ ---")

        untyped_ast = ast.parse(text)

        log.debug((log_center("v Untyped AST v") + str(untyped_ast) +
                   log_center("^ Untyped AST ^")), DEBUG_UNTYPED_AST)

        typedecs = parse_type_decs(filename)

        log.debug((log_center("v TypeDecs v") + str(typedecs) +
                   log_center("^ TypeDecs ^")), DEBUG_TYPEDECS)

        typed_ast = TypeDecASTModule(untyped_ast, typedecs)

        log.debug((log_center("v TypedAST v") + str(typed_ast) +
                   log_center("^ TypedAST ^")), DEBUG_TYPED_AST)

        return check_mod(typed_ast.tree)
Esempio n. 3
0
File: pyty.py Progetto: jruberg/Pyty
parser.add_option_group(i_group)

(opt, args) = parser.parse_args()

if opt.filename and not opt.expr and not opt.type and not opt.infer_expr:
    file_name = opt.filename

    try:
        # FIXME: this is copied from unit_test_core, should be abstracted
        # away somewhere, but don't know the best way to deal with logging.
        with open(file_name, 'r') as f:
            text = f.read()
        untyped_ast = ast.parse(text)
        typedecs = parse_type_decs(file_name)
        typed_ast = TypeDecASTModule(untyped_ast, typedecs)
        if check_mod(typed_ast.tree):
            print "Typechecked correctly!"
        else:
            print "Did not typecheck."

    except IOError as e:
        print "File not found: %s" % e.filename

elif opt.expr and opt.type and not opt.filename and not opt.infer_expr:
    e = ast.parse(opt.expr).body[0].value
    t = PType.from_str(opt.type)
    template = ("YES! -- %s typechecks as type %s" if check_expr(e, t, {}) else
                "NO! --- %s does not typecheck as type %s")
    print template % (opt.expr, t)

elif opt.infer_expr and not opt.filename and not opt.expr and not opt.type:
Esempio n. 4
0
parser.add_option_group(i_group)

(opt, args) = parser.parse_args()

if opt.filename and not opt.expr and not opt.type and not opt.infer_expr:
    file_name = opt.filename

    try:
        # FIXME: this is copied from unit_test_core, should be abstracted
        # away somewhere, but don't know the best way to deal with logging.
        with open(file_name, 'r') as f:
            text = f.read()
        untyped_ast = ast.parse(text)
        typedecs = parse_type_decs(file_name)
        typed_ast = TypeDecASTModule(untyped_ast, typedecs)
        if check_mod(typed_ast.tree):
            print "Typechecked correctly!"
        else:
            print "Did not typecheck."

    except IOError as e:
        print "File not found: %s" % e.filename

elif opt.expr and opt.type and not opt.filename and not opt.infer_expr:
    e = ast.parse(opt.expr).body[0].value
    t = PType.from_str(opt.type)
    template = ("YES! -- %s typechecks as type %s" if check_expr(e, t, {}) else
                "NO! --- %s does not typecheck as type %s")
    print template % (opt.expr, t)

elif opt.infer_expr and not opt.filename and not opt.expr and not opt.type: