summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Beazley <dave@dabeaz.com>2016-08-30 15:41:28 -0500
committerDavid Beazley <dave@dabeaz.com>2016-08-30 15:41:28 -0500
commit1000526c6d5176ac0c6867d53160b33cb1e070b1 (patch)
tree7a0709ace0e367474db64a924b54330159aafc97
parent5ccbfc7e70392a18fb5defa57e3e18fa477c03e6 (diff)
downloadply-1000526c6d5176ac0c6867d53160b33cb1e070b1.tar.gz
cleanup
-rw-r--r--CHANGES3
-rw-r--r--example/ansic/cparse.py2
-rw-r--r--ply/cpp.py13
3 files changed, 15 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index b3b37a6..b309290 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,8 @@
Version 3.9
---------------------
+08/30/16: beazley
+ Fixed Issue #88. Python3 compatibility with ply/cpp.
+
08/30/16: beazley
Fixed Issue #93. Ply can crash if SyntaxError is raised inside
a production. Not actually sure if the original implementation
diff --git a/example/ansic/cparse.py b/example/ansic/cparse.py
index 2583075..5c6932c 100644
--- a/example/ansic/cparse.py
+++ b/example/ansic/cparse.py
@@ -855,7 +855,7 @@ import profile
# Build the grammar
yacc.yacc()
-#yacc.yacc(method='LALR',write_tables=False,debug=True)
+#yacc.yacc(method='LALR',write_tables=False,debug=False)
#profile.run("yacc.yacc(method='LALR')")
diff --git a/ply/cpp.py b/ply/cpp.py
index 2f6a030..ade2987 100644
--- a/ply/cpp.py
+++ b/ply/cpp.py
@@ -9,6 +9,15 @@
# -----------------------------------------------------------------------------
from __future__ import generators
+import sys
+
+# Some Python 3 compatibility shims
+if sys.version_info.major < 3:
+ STRING_TYPES = (str, unicode)
+else:
+ STRING_TYPES = str
+ xrange = range
+
# -----------------------------------------------------------------------------
# Default preprocessor lexer definitions. These tokens are enough to get
# a basic preprocessor working. Other modules may import these if they want
@@ -590,7 +599,7 @@ class Preprocessor(object):
expr = expr.replace("!"," not ")
try:
result = eval(expr)
- except StandardError:
+ except Exception:
self.error(self.source,tokens[0].lineno,"Couldn't evaluate expression")
result = 0
return result
@@ -781,7 +790,7 @@ class Preprocessor(object):
# ----------------------------------------------------------------------
def define(self,tokens):
- if isinstance(tokens,(str,unicode)):
+ if isinstance(tokens,STRING_TYPES):
tokens = self.tokenize(tokens)
linetok = tokens