Update code to run under both Python 2 and Python 3.
Chris Pressey
1 year, 1 month ago
74 | 74 |
failed = False
|
75 | 75 |
try:
|
76 | 76 |
module.typecheck(context)
|
77 | |
except context.TypingError, e:
|
|
77 |
except context.TypingError as e:
|
78 | 78 |
logger.info("caught TypingError " + str(e))
|
79 | 79 |
failed = True
|
80 | |
except Exception, e:
|
|
80 |
except Exception as e:
|
81 | 81 |
logger.info("caught Exception " + str(e))
|
82 | 82 |
finally:
|
83 | 83 |
if not failed:
|
63 | 63 |
def dump(self):
|
64 | 64 |
for k, v in self.map.iteritems():
|
65 | 65 |
if isinstance(v, Type):
|
66 | |
print k + " : " + str(v) # return string instead?
|
|
66 |
print(k + " : " + str(v)) # return string instead?
|
67 | 67 |
else:
|
68 | |
print k + " : " + v
|
|
68 |
print(k + " : " + v)
|
69 | 69 |
|
70 | 70 |
def assert_equiv(self, inwhat, s, t):
|
71 | 71 |
if not s.unify(t):
|
14 | 14 |
Create a new Scanner object that will consume the given
|
15 | 15 |
UTF-8 encoded input string.
|
16 | 16 |
"""
|
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')
|
18 | 21 |
self._token = None
|
19 | 22 |
self.scan()
|
20 | 23 |
|
|
68 | 71 |
self._token = self._input[0]
|
69 | 72 |
self._input = self._input[1:]
|
70 | 73 |
self.toktype = "op"
|
71 | |
#print "scanned: '" + str(self._token) + "'"
|
|
74 |
# print("scanned: '" + str(self._token) + "'")
|
72 | 75 |
|
73 | 76 |
def get_token(self):
|
74 | 77 |
"""
|
|
101 | 104 |
"""
|
102 | 105 |
Log the given scan error.
|
103 | 106 |
"""
|
104 | |
print "error: " + str
|
|
107 |
print("error: " + str)
|
105 | 108 |
self.scan()
|
15 | 15 |
|
16 | 16 |
|
17 | 17 |
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())
|
21 | 20 |
parser = Parser(scanner)
|
22 | 21 |
ast = parser.Dieter()
|
23 | 22 |
context = TypingContext(None)
|
|
25 | 24 |
logging.basicConfig(level=logging.INFO)
|
26 | 25 |
ast.typecheck(context)
|
27 | 26 |
if options.dump_ast:
|
28 | |
print "--- AST: ---"
|
29 | |
print ast.dump(0)
|
|
27 |
print("--- AST: ---")
|
|
28 |
print(ast.dump(0))
|
30 | 29 |
if options.dump_symtab:
|
31 | |
print "--- Symbol Table: ---"
|
|
30 |
print("--- Symbol Table: ---")
|
32 | 31 |
context.dump()
|
|
32 |
|
33 | 33 |
|
34 | 34 |
def main(argv):
|
35 | 35 |
optparser = OptionParser("[python] dieter.py {options} {source.dtr}\n" + __doc__)
|
1 | 1 |
|
2 | 2 |
for FILE in eg/*.dtr; do
|
3 | 3 |
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
|
5 | 6 |
done
|