diff options
author | David Beazley <dave@dabeaz.com> | 2016-08-30 15:41:28 -0500 |
---|---|---|
committer | David Beazley <dave@dabeaz.com> | 2016-08-30 15:41:28 -0500 |
commit | 1000526c6d5176ac0c6867d53160b33cb1e070b1 (patch) | |
tree | 7a0709ace0e367474db64a924b54330159aafc97 | |
parent | 5ccbfc7e70392a18fb5defa57e3e18fa477c03e6 (diff) | |
download | ply-1000526c6d5176ac0c6867d53160b33cb1e070b1.tar.gz |
cleanup
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | example/ansic/cparse.py | 2 | ||||
-rw-r--r-- | ply/cpp.py | 13 |
3 files changed, 15 insertions, 3 deletions
@@ -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')") @@ -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 |