aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2016-07-03 14:16:44 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2016-07-03 14:16:44 -0400
commit60eb198a2b589ddfae56e8a2fa3d214bf2df6dc8 (patch)
tree9da2d25df7d813ae9848eaf4d6ccdd159436df5b
parent7f01b5bd084eccff8d551ba34c01e6375617cc93 (diff)
downloadexyapps-60eb198a2b589ddfae56e8a2fa3d214bf2df6dc8.tar.gz
Minimal 2to3 pass
-rw-r--r--exyapps/grammar.py2
-rwxr-xr-xexyapps/main.py16
-rw-r--r--exyapps/parsetree.py34
-rw-r--r--exyapps/runtime.py18
4 files changed, 35 insertions, 35 deletions
diff --git a/exyapps/grammar.py b/exyapps/grammar.py
index 8220579..27cf756 100644
--- a/exyapps/grammar.py
+++ b/exyapps/grammar.py
@@ -35,7 +35,7 @@ def resolve_name(rule, tokens, id, args):
if id in [x[0] for x in tokens]:
# It's a token
if args:
- print 'Warning: ignoring parameters on TOKEN %s<<%s>>' % (id, args)
+ print('Warning: ignoring parameters on TOKEN %s<<%s>>' % (id, args))
return parsetree.Terminal(rule, id)
else:
# It's a name, so assume it's a nonterminal
diff --git a/exyapps/main.py b/exyapps/main.py
index 61f3478..e3cdea4 100755
--- a/exyapps/main.py
+++ b/exyapps/main.py
@@ -67,7 +67,7 @@ def generate(inputfilename, outputfilename=None, dump=0, **flags):
if f == opt:
break
else:
- print >>sys.stderr, 'Warning: unrecognized option', f
+ print('Warning: unrecognized option', f, file=sys.stderr)
# Add command line options to the set
for f in flags.keys():
@@ -96,13 +96,13 @@ def main() :
import getopt
optlist, args = getopt.getopt(sys.argv[1:], 'f:', ['help', 'dump', 'use-devel-grammar'])
if not args or len(args) > 2:
- print >>sys.stderr, 'Usage:'
- print >>sys.stderr, ' python', sys.argv[0], '[flags] input.g [output.py]'
- print >>sys.stderr, 'Flags:'
- print >>sys.stderr, (' --dump' + ' '*40)[:35] + 'Dump out grammar information'
- print >>sys.stderr, (' --use-devel-grammar' + ' '*40)[:35] + 'Use the devel grammar parser from yapps_grammar.py instead of the stable grammar from grammar.py'
+ print('Usage:', file=sys.stderr)
+ print(' python', sys.argv[0], '[flags] input.g [output.py]', file=sys.stderr)
+ print('Flags:', file=sys.stderr)
+ print((' --dump' + ' '*40)[:35] + 'Dump out grammar information', file=sys.stderr)
+ print((' --use-devel-grammar' + ' '*40)[:35] + 'Use the devel grammar parser from yapps_grammar.py instead of the stable grammar from grammar.py', file=sys.stderr)
for flag, _, doc in yapps_options:
- print >>sys.stderr, (' -f' + flag + ' '*40)[:35] + doc
+ print((' -f' + flag + ' '*40)[:35] + doc, file=sys.stderr)
return 1
else:
# Read in the options and create a list of flags
@@ -119,7 +119,7 @@ def main() :
elif opt == ('--use-devel-grammar', ''):
use_devel_grammar = 1
else:
- print >>sys.stderr, 'Warning: unrecognized option', opt[0], opt[1]
+ print('Warning: unrecognized option', opt[0], opt[1], file=sys.stderr)
if use_devel_grammar:
import yapps_grammar as g2
diff --git a/exyapps/parsetree.py b/exyapps/parsetree.py
index 964a74e..a709314 100644
--- a/exyapps/parsetree.py
+++ b/exyapps/parsetree.py
@@ -63,7 +63,7 @@ class Generator:
n = t
self.ignore[n] = s
if n in self.tokens.keys() and self.tokens[n] != t:
- print >>sys.stderr, 'Warning: token %s defined more than once.' % n
+ print('Warning: token %s defined more than once.' % n, file=sys.stderr)
self.tokens[n] = t
self.terminals.append(n)
@@ -259,20 +259,20 @@ class Generator:
"""Display the grammar in somewhat human-readable form."""
self.calculate()
for r in self.goals:
- print ' _____' + '_'*len(r)
- print ('___/Rule '+r+'\\' + '_'*80)[:79]
+ print(' _____' + '_'*len(r))
+ print(('___/Rule '+r+'\\' + '_'*80)[:79])
queue = [self.rules[r]]
while queue:
top = queue[0]
del queue[0]
- print 'Rule', repr(top), 'of class', top.__class__.__name__
+ print('Rule', repr(top), 'of class', top.__class__.__name__)
top.first.sort()
top.follow.sort()
eps = []
if top.accepts_epsilon: eps = ['(null)']
- print ' FIRST:', ', '.join(top.first+eps)
- print ' FOLLOW:', ', '.join(top.follow)
+ print(' FIRST:', ', '.join(top.first+eps))
+ print(' FOLLOW:', ', '.join(top.follow))
for x in top.get_children(): queue.append(x)
def repr_ignore(self):
@@ -428,7 +428,7 @@ class NonTerminal(Node):
self.accepts_epsilon = self.target.accepts_epsilon
gen.changed()
except KeyError: # Oops, it's nonexistent
- print >>sys.stderr, 'Error: no rule <%s>' % self.name
+ print('Error: no rule <%s>' % self.name, file=sys.stderr)
self.target = self
def __str__(self):
@@ -556,12 +556,12 @@ class Choice(Node):
tokens_seen = tokens_seen + testset
if removed:
if not testset:
- print >>sys.stderr, 'Error in rule', self.rule+':'
+ print('Error in rule', self.rule+':', file=sys.stderr)
else:
- print >>sys.stderr, 'Warning in rule', self.rule+':'
- print >>sys.stderr, ' *', self
- print >>sys.stderr, ' * These tokens could be matched by more than one clause:'
- print >>sys.stderr, ' *', ' '.join(removed)
+ print('Warning in rule', self.rule+':', file=sys.stderr)
+ print(' *', self, file=sys.stderr)
+ print(' * These tokens could be matched by more than one clause:', file=sys.stderr)
+ print(' *', ' '.join(removed), file=sys.stderr)
if testset:
if not tokens_unseen: # context sensitive scanners only!
@@ -620,7 +620,7 @@ class Option(Wrapper):
def output(self, gen, indent):
if self.child.accepts_epsilon:
- print >>sys.stderr, 'Warning in rule', self.rule+': contents may be empty.'
+ print('Warning in rule', self.rule+': contents may be empty.', file=sys.stderr)
gen.write(indent, "if %s:\n" %
gen.peek_test(self.first, self.child.first))
self.child.output(gen, indent+INDENT)
@@ -649,8 +649,8 @@ class Plus(Wrapper):
def output(self, gen, indent):
if self.child.accepts_epsilon:
- print >>sys.stderr, 'Warning in rule', self.rule+':'
- print >>sys.stderr, ' * The repeated pattern could be empty. The resulting parser may not work properly.'
+ print('Warning in rule', self.rule+':', file=sys.stderr)
+ print(' * The repeated pattern could be empty. The resulting parser may not work properly.', file=sys.stderr)
gen.write(indent, "while 1:\n")
self.child.output(gen, indent+INDENT)
union = self.first[:]
@@ -682,8 +682,8 @@ class Star(Wrapper):
def output(self, gen, indent):
if self.child.accepts_epsilon:
- print >>sys.stderr, 'Warning in rule', self.rule+':'
- print >>sys.stderr, ' * The repeated pattern could be empty. The resulting parser probably will not work properly.'
+ print('Warning in rule', self.rule+':', file=sys.stderr)
+ print(' * The repeated pattern could be empty. The resulting parser probably will not work properly.', file=sys.stderr)
gen.write(indent, "while %s:\n" %
gen.peek_test(self.follow, self.child.first))
self.child.output(gen, indent+INDENT)
diff --git a/exyapps/runtime.py b/exyapps/runtime.py
index 6c984b8..67af730 100644
--- a/exyapps/runtime.py
+++ b/exyapps/runtime.py
@@ -184,7 +184,7 @@ class Scanner(object):
file,line,p = pos
if file != self.filename:
if self.stack: return self.stack.print_line_with_pointer(pos,length=length,out=out)
- print >>out, "(%s: not in input buffer)" % file
+ print("(%s: not in input buffer)" % file, file=out)
return
text = self.input
@@ -207,7 +207,7 @@ class Scanner(object):
break
spos = cr+1
else:
- print >>out, "(%s:%d not in input buffer)" % (file,origline)
+ print("(%s:%d not in input buffer)" % (file,origline), file=out)
return
# Now try printing part of the line
@@ -236,8 +236,8 @@ class Scanner(object):
p = p - 7
# Now print the string, along with an indicator
- print >>out, '> ',text
- print >>out, '> ',' '*p + '^'
+ print('> ',text, file=out)
+ print('> ',' '*p + '^', file=out)
def grab_input(self):
"""Get more input if possible."""
@@ -425,14 +425,14 @@ def print_error(err, scanner, max_ctx=None):
pos = scanner.get_pos()
file_name, line_number, column_number = pos
- print >>sys.stderr, '%s:%d:%d: %s' % (file_name, line_number, column_number, err.msg)
+ print('%s:%d:%d: %s' % (file_name, line_number, column_number, err.msg), file=sys.stderr)
scanner.print_line_with_pointer(pos)
context = err.context
token = None
while context:
- print >>sys.stderr, 'while parsing %s%s:' % (context.rule, tuple(context.args))
+ print('while parsing %s%s:' % (context.rule, tuple(context.args)), file=sys.stderr)
if context.token:
token = context.token
if token:
@@ -446,8 +446,8 @@ def print_error(err, scanner, max_ctx=None):
def wrap_error_reporter(parser, rule, *args,**kw):
try:
return getattr(parser, rule)(*args,**kw)
- except SyntaxError, e:
+ except SyntaxError as e:
print_error(e, parser._scanner)
except NoMoreTokens:
- print >>sys.stderr, 'Could not complete parsing; stopped around here:'
- print >>sys.stderr, parser._scanner
+ print('Could not complete parsing; stopped around here:', file=sys.stderr)
+ print(parser._scanner, file=sys.stderr)