Пример #1
0
 def _test_myfrontend_bad (self, filename):
     source = open(os.path.join(self.path, filename)).read()
     try:
         mybuiltins.myfrontend(source, mybuiltins.initial_environment())
         self.failUnless(False, "The previous line should have thrown an "
                         "exception.")
     except MyFrontExceptions.MyFrontCompileTimeError, ct_err:
         embedded_exception = ct_err.args[0][1]
         self.failUnless(type(embedded_exception) ==
                         MyFrontExceptions.MyFrontSyntaxError)
         # XXX I don't know how brittle this is if we ever change
         # the syntax error message:
         msg = embedded_exception.args[0].split()
         line_index = msg.index('line') + 1
         line_no = int(msg[line_index][:-1])
         column_index = msg.index('column') + 1
         column_no = int(msg[column_index][:-1])
         unexpected_index = msg.index('unexpected') + 1
         unexpected_str = eval(msg[unexpected_index][:-1])
         source_line = source.split("\n")[line_no - 1]
         source_str = source_line[column_no:column_no +
                                  len(unexpected_str)]
         if __DEBUG__:
             print line_no, column_no, `source_line`,
             print `source_line[column_no - 1:]`, `unexpected_str`
         self.failUnlessEqual(source_str, unexpected_str)
Пример #2
0
def main (*args):
    for arg in args:
        print "_" * 70
        source = open(arg).read()
        ast, env0 = mybuiltins.myfrontend(source, mybuiltins.initial_environment())
        co0, env1 = mybuiltins.mybackend(ast, env0)
        dis.dis(co0)
        print "_" * 60
        co1 = compile(source, arg, "exec")
        dis.dis(co1)
Пример #3
0
 def handle_source (source, filename = "<string>"):
     ast, env = myfrontend(source, {"filename" : filename})
     uglier_printer.handle(ast)
     outstring = ugly_printer.handle(ast)
     print "outstring: ", outstring
     return myfrontend(outstring, env)[0] == ast # T(~T(T(s))) == T(s)