Adapt code to run under both Python 2 and Python 3.
Chris Pressey
2 years ago
16 | 16 |
|
17 | 17 |
|
18 | 18 |
def load(filename, options):
|
19 | |
f = open(filename, "r")
|
|
19 |
f = open(filename, "rb")
|
20 | 20 |
scanner = Scanner(f.read())
|
21 | 21 |
f.close()
|
22 | 22 |
parser = ClassBaseParser(scanner, stdlib)
|
23 | 23 |
parser.parse()
|
24 | 24 |
if options.dump_ast:
|
25 | |
print "---AST---"
|
26 | |
print str(stdlib)
|
|
25 |
print("---AST---")
|
|
26 |
print(str(stdlib))
|
27 | 27 |
|
28 | 28 |
|
29 | 29 |
def main(argv):
|
12 | 12 |
A lexical scanner.
|
13 | 13 |
"""
|
14 | 14 |
|
15 | |
def __init__(self, input):
|
|
15 |
def __init__(self, input_):
|
16 | 16 |
"""
|
17 | 17 |
Create a new Scanner object that will consume the given
|
18 | 18 |
UTF-8 encoded input string.
|
19 | 19 |
"""
|
20 | |
self._input = unicode(input, 'utf-8')
|
|
20 |
self._input = input_.decode('utf-8')
|
21 | 21 |
self._token = None
|
22 | 22 |
self.scan()
|
23 | 23 |
|
|
88 | 88 |
"""
|
89 | 89 |
Log the given scan error.
|
90 | 90 |
"""
|
91 | |
print "error: " + str
|
|
91 |
print("error: " + str)
|
92 | 92 |
self.scan()
|
6 | 6 |
Pre-built AST representing built-in Unlikely classes.
|
7 | 7 |
"""
|
8 | 8 |
|
9 | |
import ast
|
|
9 |
from .ast import ClassBase
|
10 | 10 |
|
11 | |
stdlib = ast.ClassBase()
|
|
11 |
stdlib = ClassBase()
|
12 | 12 |
|
13 | 13 |
continuation = stdlib.add_class_defn_by_name("Continuation", None,
|
14 | 14 |
["saturated", "abstract"])
|
4 | 4 |
|
5 | 5 |
-> Functionality "Parse Unlikely Program" is implemented by
|
6 | 6 |
-> shell command
|
7 | |
-> "python src/coldwater.py %(test-body-file)"
|
|
7 |
-> "python2 src/coldwater.py %(test-body-file)"
|
|
8 |
|
|
9 |
-> Functionality "Parse Unlikely Program" is implemented by
|
|
10 |
-> shell command
|
|
11 |
-> "python3 src/coldwater.py %(test-body-file)"
|
8 | 12 |
|
9 | 13 |
Here is a syntactically correct program.
|
10 | 14 |
|