[Python-3000-checkins] r55143 - python/branches/p3yk/Parser/asdl.py python/branches/p3yk/Parser/asdl_c.py python/branches/p3yk/Parser/spark.py
fred.drake
python-3000-checkins at python.org
Sat May 5 06:52:21 CEST 2007
Author: fred.drake
Date: Sat May 5 06:52:16 2007
New Revision: 55143
Modified:
python/branches/p3yk/Parser/asdl.py
python/branches/p3yk/Parser/asdl_c.py
python/branches/p3yk/Parser/spark.py
Log:
make this work with the new Python
Modified: python/branches/p3yk/Parser/asdl.py
==============================================================================
--- python/branches/p3yk/Parser/asdl.py (original)
+++ python/branches/p3yk/Parser/asdl.py Sat May 5 06:52:16 2007
@@ -45,7 +45,7 @@
self.value = value
self.lineno = lineno
-class ASDLSyntaxError:
+class ASDLSyntaxError(Exception):
def __init__(self, lineno, token=None, msg=None):
self.lineno = lineno
@@ -128,7 +128,7 @@
"version ::= Id String"
if version.value != "version":
raise ASDLSyntaxError(version.lineno,
- msg="expected 'version', found %" % version)
+ msg="expected 'version', found %" % version)
return V
def p_definition_0(self, (definition,)):
@@ -306,9 +306,9 @@
return
try:
meth(object, *args)
- except Exception, err:
- print "Error visiting", repr(object)
- print err
+ except Exception as err:
+ print("Error visiting", repr(object))
+ print(err)
traceback.print_exc()
# XXX hack
if hasattr(self, 'file'):
@@ -353,8 +353,8 @@
if conflict is None:
self.cons[key] = name
else:
- print "Redefinition of constructor %s" % key
- print "Defined in %s and %s" % (conflict, name)
+ print("Redefinition of constructor %s" % key)
+ print("Defined in %s and %s" % (conflict, name))
self.errors += 1
for f in cons.fields:
self.visit(f, key)
@@ -376,7 +376,7 @@
if t not in mod.types and not t in builtin_types:
v.errors += 1
uses = ", ".join(v.types[t])
- print "Undefined type %s, used in %s" % (t, uses)
+ print("Undefined type %s, used in %s" % (t, uses))
return not v.errors
@@ -388,10 +388,10 @@
tokens = scanner.tokenize(buf)
try:
return parser.parse(tokens)
- except ASDLSyntaxError, err:
- print err
+ except ASDLSyntaxError as err:
+ print(err)
lines = buf.split("\n")
- print lines[err.lineno - 1] # lines starts at 0, files at 1
+ print(lines[err.lineno - 1]) # lines starts at 0, files at 1
if __name__ == "__main__":
import glob
@@ -404,12 +404,12 @@
files = glob.glob(testdir + "/*.asdl")
for file in files:
- print file
+ print(file)
mod = parse(file)
- print "module", mod.name
- print len(mod.dfns), "definitions"
+ print("module", mod.name)
+ print(len(mod.dfns), "definitions")
if not check(mod):
- print "Check failed"
+ print("Check failed")
else:
for dfn in mod.dfns:
- print dfn.type
+ print(dfn.type)
Modified: python/branches/p3yk/Parser/asdl_c.py
==============================================================================
--- python/branches/p3yk/Parser/asdl_c.py (original)
+++ python/branches/p3yk/Parser/asdl_c.py Sat May 5 06:52:16 2007
@@ -741,25 +741,25 @@
if INC_DIR:
p = "%s/%s-ast.h" % (INC_DIR, mod.name)
f = open(p, "wb")
- print >> f, auto_gen_msg
- print >> f, '#include "asdl.h"\n'
+ print(auto_gen_msg, file=f)
+ print('#include "asdl.h"\n', file=f)
c = ChainOfVisitors(TypeDefVisitor(f),
StructVisitor(f),
PrototypeVisitor(f),
)
c.visit(mod)
- print >>f, "PyObject* PyAST_mod2obj(mod_ty t);"
+ print("PyObject* PyAST_mod2obj(mod_ty t);", file=f)
f.close()
if SRC_DIR:
p = os.path.join(SRC_DIR, str(mod.name) + "-ast.c")
f = open(p, "wb")
- print >> f, auto_gen_msg
- print >> f, c_file_msg % parse_version(mod)
- print >> f, '#include "Python.h"'
- print >> f, '#include "%s-ast.h"' % mod.name
- print >> f
- print >>f, "static PyTypeObject* AST_type;"
+ print(auto_gen_msg, file=f)
+ print(c_file_msg % parse_version(mod), file=f)
+ print('#include "Python.h"', file=f)
+ print('#include "%s-ast.h"' % mod.name, file=f)
+ print(file=f)
+ print("static PyTypeObject* AST_type;", file=f)
v = ChainOfVisitors(
PyTypesDeclareVisitor(f),
PyTypesVisitor(f),
@@ -779,7 +779,7 @@
SRC_DIR = ''
opts, args = getopt.getopt(sys.argv[1:], "h:c:")
if len(opts) != 1:
- print "Must specify exactly one output file"
+ print("Must specify exactly one output file")
sys.exit(1)
for o, v in opts:
if o == '-h':
@@ -787,6 +787,6 @@
if o == '-c':
SRC_DIR = v
if len(args) != 1:
- print "Must specify single input file"
+ print("Must specify single input file")
sys.exit(1)
main(args[0])
Modified: python/branches/p3yk/Parser/spark.py
==============================================================================
--- python/branches/p3yk/Parser/spark.py (original)
+++ python/branches/p3yk/Parser/spark.py Sat May 5 06:52:16 2007
@@ -22,8 +22,6 @@
__version__ = 'SPARK-0.7 (pre-alpha-5)'
import re
-import sys
-import string
def _namelist(instance):
namelist, namedict, classlist = [], {}, [instance.__class__]
@@ -57,10 +55,10 @@
rv.append(self.makeRE(name))
rv.append(self.makeRE('t_default'))
- return string.join(rv, '|')
+ return '|'.join(rv)
def error(self, s, pos):
- print "Lexical error at position %s" % pos
+ print("Lexical error at position %s" % pos)
raise SystemExit
def tokenize(self, s):
@@ -79,7 +77,7 @@
def t_default(self, s):
r'( . | \n )+'
- print "Specification error: unmatched input"
+ print("Specification error: unmatched input")
raise SystemExit
#
@@ -172,7 +170,7 @@
def addRule(self, doc, func, _preprocess=1):
fn = func
- rules = string.split(doc)
+ rules = doc.split()
index = []
for i in range(len(rules)):
@@ -296,7 +294,7 @@
return None
def error(self, token):
- print "Syntax error at or near `%s' token" % token
+ print("Syntax error at or near `%s' token" % token)
raise SystemExit
def parse(self, tokens):
@@ -419,8 +417,7 @@
# need to know the entire set of predicted nonterminals
# to do this without accidentally duplicating states.
#
- core = predicted.keys()
- core.sort()
+ core = sorted(predicted.keys())
tcore = tuple(core)
if tcore in self.cores:
self.edges[(k, None)] = self.cores[tcore]
@@ -605,7 +602,7 @@
rule = self.ambiguity(self.newrules[nt])
else:
rule = self.newrules[nt][0]
- #print rule
+ #print(rule)
rhs = rule[1]
attr = [None] * len(rhs)
@@ -624,7 +621,7 @@
rule = choices[0]
if len(choices) > 1:
rule = self.ambiguity(choices)
- #print rule
+ #print(rule)
rhs = rule[1]
attr = [None] * len(rhs)
@@ -826,15 +823,15 @@
def _dump(tokens, sets, states):
for i in range(len(sets)):
- print 'set', i
+ print('set', i)
for item in sets[i]:
- print '\t', item
+ print('\t', item)
for (lhs, rhs), pos in states[item[0]].items:
- print '\t\t', lhs, '::=',
- print string.join(rhs[:pos]),
- print '.',
- print string.join(rhs[pos:])
+ print('\t\t', lhs, '::=', end='')
+ print(' '.join(rhs[:pos]), end='')
+ print('.', end='')
+ print(' '.join(rhs[pos:]))
if i < len(tokens):
- print
- print 'token', str(tokens[i])
- print
+ print()
+ print('token', str(tokens[i]))
+ print()
More information about the Python-3000-checkins
mailing list