summaryrefslogtreecommitdiff
path: root/ply
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 /ply
parent5ccbfc7e70392a18fb5defa57e3e18fa477c03e6 (diff)
downloadply-1000526c6d5176ac0c6867d53160b33cb1e070b1.tar.gz
cleanup
Diffstat (limited to 'ply')
-rw-r--r--ply/cpp.py13
1 files changed, 11 insertions, 2 deletions
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