Skip to content

Commit

Permalink
Patched syntax for Python 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
dabeaz committed Feb 18, 2011
1 parent c234ede commit 124f030
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions ply/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def tokenize(self,text):
# ----------------------------------------------------------------------

def error(self,file,line,msg):
print >>sys.stderr,"%s:%d %s" % (file,line,msg)
print("%s:%d %s" % (file,line,msg),file=sys.stderr)

# ----------------------------------------------------------------------
# lexprobe()
Expand All @@ -193,15 +193,15 @@ def lexprobe(self):
self.lexer.input("identifier")
tok = self.lexer.token()
if not tok or tok.value != "identifier":
print "Couldn't determine identifier type"
print("Couldn't determine identifier type")
else:
self.t_ID = tok.type

# Determine the token type for integers
self.lexer.input("12345")
tok = self.lexer.token()
if not tok or int(tok.value) != 12345:
print "Couldn't determine integer type"
print("Couldn't determine integer type")
else:
self.t_INTEGER = tok.type
self.t_INTEGER_TYPE = type(tok.value)
Expand All @@ -210,7 +210,7 @@ def lexprobe(self):
self.lexer.input("\"filename\"")
tok = self.lexer.token()
if not tok or tok.value != "\"filename\"":
print "Couldn't determine string type"
print("Couldn't determine string type")
else:
self.t_STRING = tok.type

Expand All @@ -227,7 +227,7 @@ def lexprobe(self):
tok = self.lexer.token()
if not tok or tok.value != "\n":
self.t_NEWLINE = None
print "Couldn't determine token for newlines"
print("Couldn't determine token for newlines")
else:
self.t_NEWLINE = tok.type

Expand All @@ -239,7 +239,7 @@ def lexprobe(self):
self.lexer.input(c)
tok = self.lexer.token()
if not tok or tok.value != c:
print "Unable to lex '%s' required for preprocessor" % c
print("Unable to lex '%s' required for preprocessor" % c)

# ----------------------------------------------------------------------
# add_path()
Expand Down Expand Up @@ -737,15 +737,15 @@ def include(self,tokens):
break
i += 1
else:
print "Malformed #include <...>"
print("Malformed #include <...>")
return
filename = "".join([x.value for x in tokens[1:i]])
path = self.path + [""] + self.temp_path
elif tokens[0].type == self.t_STRING:
filename = tokens[0].value[1:-1]
path = self.temp_path + [""] + self.path
else:
print "Malformed #include statement"
print("Malformed #include statement")
return
for p in path:
iname = os.path.join(p,filename)
Expand All @@ -759,10 +759,10 @@ def include(self,tokens):
if dname:
del self.temp_path[0]
break
except IOError,e:
except IOError:
pass
else:
print "Couldn't find '%s'" % filename
print("Couldn't find '%s'" % filename)

# ----------------------------------------------------------------------
# define()
Expand Down Expand Up @@ -794,7 +794,7 @@ def define(self,tokens):
variadic = False
for a in args:
if variadic:
print "No more arguments may follow a variadic argument"
print("No more arguments may follow a variadic argument")
break
astr = "".join([str(_i.value) for _i in a])
if astr == "...":
Expand All @@ -813,7 +813,7 @@ def define(self,tokens):
a[0].value = a[0].value[:-3]
continue
if len(a) > 1 or a[0].type != self.t_ID:
print "Invalid macro argument"
print("Invalid macro argument")
break
else:
mvalue = self.tokenstrip(linetok[1+tokcount:])
Expand All @@ -830,9 +830,9 @@ def define(self,tokens):
self.macro_prescan(m)
self.macros[name.value] = m
else:
print "Bad macro definition"
print("Bad macro definition")
except LookupError:
print "Bad macro definition"
print("Bad macro definition")

# ----------------------------------------------------------------------
# undef()
Expand Down Expand Up @@ -864,7 +864,7 @@ def parse(self,input,source=None,ignore={}):
def token(self):
try:
while True:
tok = self.parser.next()
tok = next(self.parser)
if tok.type not in self.ignore: return tok
except StopIteration:
self.parser = None
Expand All @@ -884,7 +884,7 @@ def token(self):
while True:
tok = p.token()
if not tok: break
print p.source, tok
print(p.source, tok)



Expand Down

0 comments on commit 124f030

Please sign in to comment.