git @ Cat's Eye Technologies Dieter / 5057614
Update code to run under both Python 2 and Python 3. Chris Pressey 1 year, 1 month ago
6 changed file(s) with 20 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
0 *.pyc
1 __pycache__
7474 failed = False
7575 try:
7676 module.typecheck(context)
77 except context.TypingError, e:
77 except context.TypingError as e:
7878 logger.info("caught TypingError " + str(e))
7979 failed = True
80 except Exception, e:
80 except Exception as e:
8181 logger.info("caught Exception " + str(e))
8282 finally:
8383 if not failed:
6363 def dump(self):
6464 for k, v in self.map.iteritems():
6565 if isinstance(v, Type):
66 print k + " : " + str(v) # return string instead?
66 print(k + " : " + str(v)) # return string instead?
6767 else:
68 print k + " : " + v
68 print(k + " : " + v)
6969
7070 def assert_equiv(self, inwhat, s, t):
7171 if not s.unify(t):
1414 Create a new Scanner object that will consume the given
1515 UTF-8 encoded input string.
1616 """
17 self._input = unicode(input, 'utf-8')
17 try:
18 self._input = unicode(input, 'utf-8')
19 except NameError:
20 self._input = input.decode('utf-8')
1821 self._token = None
1922 self.scan()
2023
6871 self._token = self._input[0]
6972 self._input = self._input[1:]
7073 self.toktype = "op"
71 #print "scanned: '" + str(self._token) + "'"
74 # print("scanned: '" + str(self._token) + "'")
7275
7376 def get_token(self):
7477 """
101104 """
102105 Log the given scan error.
103106 """
104 print "error: " + str
107 print("error: " + str)
105108 self.scan()
1515
1616
1717 def load(filename, options):
18 f = open(filename, "r")
19 scanner = Scanner(f.read())
20 f.close()
18 with open(filename, "rb") as f:
19 scanner = Scanner(f.read())
2120 parser = Parser(scanner)
2221 ast = parser.Dieter()
2322 context = TypingContext(None)
2524 logging.basicConfig(level=logging.INFO)
2625 ast.typecheck(context)
2726 if options.dump_ast:
28 print "--- AST: ---"
29 print ast.dump(0)
27 print("--- AST: ---")
28 print(ast.dump(0))
3029 if options.dump_symtab:
31 print "--- Symbol Table: ---"
30 print("--- Symbol Table: ---")
3231 context.dump()
32
3333
3434 def main(argv):
3535 optparser = OptionParser("[python] dieter.py {options} {source.dtr}\n" + __doc__)
11
22 for FILE in eg/*.dtr; do
33 echo $FILE
4 src/dieter.py $FILE || exit 1
4 python2 src/dieter.py $FILE || exit 1
5 python3 src/dieter.py $FILE || exit 1
56 done