summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml2
-rw-r--r--ANNOUNCE8
-rw-r--r--CHANGES19
-rw-r--r--README.md4
-rw-r--r--example/ansic/cparse.py2
-rw-r--r--ply/__init__.py2
-rw-r--r--ply/cpp.py13
-rw-r--r--ply/lex.py9
-rw-r--r--ply/yacc.py62
-rw-r--r--setup.py2
10 files changed, 83 insertions, 40 deletions
diff --git a/.travis.yml b/.travis.yml
index e5733f3..874e3df 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,5 +6,5 @@ python:
- "3.3"
- "3.4"
install:
- - "pip install . --use-mirrors"
+ - "pip install . "
script: "cd test && python testlex.py && python testyacc.py"
diff --git a/ANNOUNCE b/ANNOUNCE
index ef5774c..15fcb41 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,11 +1,11 @@
-October 2, 2015
+August 31, 2016
- Announcing : PLY-3.8 (Python Lex-Yacc)
+ Announcing : PLY-3.9 (Python Lex-Yacc)
http://www.dabeaz.com/ply
-I'm pleased to announce PLY-3.7--a pure Python implementation of the
-common parsing tools lex and yacc. PLY-3.7 is a minor bug fix
+I'm pleased to announce PLY-3.9--a pure Python implementation of the
+common parsing tools lex and yacc. PLY-3.9 is a minor bug fix
release. It supports both Python 2 and Python 3.
If you are new to PLY, here are a few highlights:
diff --git a/CHANGES b/CHANGES
index e9c8348..b309290 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,22 @@
+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
+ worked as documented at all. Yacc has been modified to follow
+ the spec as outlined in the CHANGES noted for 11/27/07 below.
+
+08/30/16: beazley
+ Fixed Issue #97. Failure with code validation when the original
+ source files aren't present. Validation step now ignores
+ the missing file.
+
+08/30/16: beazley
+ Minor fixes to version numbers.
+
Version 3.8
---------------------
10/02/15: beazley
diff --git a/README.md b/README.md
index d435377..402ffba 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
-PLY (Python Lex-Yacc) Version 3.8
+PLY (Python Lex-Yacc) Version 3.9
-Copyright (C) 2001-2015,
+Copyright (C) 2001-2016
David M. Beazley (Dabeaz LLC)
All rights reserved.
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/__init__.py b/ply/__init__.py
index 2461a44..6e53cdd 100644
--- a/ply/__init__.py
+++ b/ply/__init__.py
@@ -1,5 +1,5 @@
# PLY package
# Author: David Beazley (dave@dabeaz.com)
-__version__ = '3.7'
+__version__ = '3.9'
__all__ = ['lex','yacc']
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
diff --git a/ply/lex.py b/ply/lex.py
index 8a3eed9..0f3e464 100644
--- a/ply/lex.py
+++ b/ply/lex.py
@@ -1,7 +1,7 @@
# -----------------------------------------------------------------------------
# ply: lex.py
#
-# Copyright (C) 2001-2015,
+# Copyright (C) 2001-2016
# David M. Beazley (Dabeaz LLC)
# All rights reserved.
#
@@ -31,7 +31,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -----------------------------------------------------------------------------
-__version__ = '3.8'
+__version__ = '3.9'
__tabversion__ = '3.8'
import re
@@ -830,7 +830,10 @@ class LexerReflect(object):
# -----------------------------------------------------------------------------
def validate_module(self, module):
- lines, linen = inspect.getsourcelines(module)
+ try:
+ lines, linen = inspect.getsourcelines(module)
+ except IOError:
+ return
fre = re.compile(r'\s*def\s+(t_[a-zA-Z_0-9]*)\(')
sre = re.compile(r'\s*(t_[a-zA-Z_0-9]*)\s*=')
diff --git a/ply/yacc.py b/ply/yacc.py
index e7f36aa..41f4795 100644
--- a/ply/yacc.py
+++ b/ply/yacc.py
@@ -1,7 +1,7 @@
# -----------------------------------------------------------------------------
# ply: yacc.py
#
-# Copyright (C) 2001-2015,
+# Copyright (C) 2001-2016
# David M. Beazley (Dabeaz LLC)
# All rights reserved.
#
@@ -67,7 +67,7 @@ import inspect
import base64
import warnings
-__version__ = '3.8'
+__version__ = '3.9'
__tabversion__ = '3.8'
#-----------------------------------------------------------------------------
@@ -497,8 +497,8 @@ class LRParser:
try:
# Call the grammar rule with our special slice object
del symstack[-plen:]
- del statestack[-plen:]
p.callable(pslice)
+ del statestack[-plen:]
#--! DEBUG
debug.info('Result : %s', format_result(pslice[0]))
#--! DEBUG
@@ -507,14 +507,16 @@ class LRParser:
statestack.append(state)
except SyntaxError:
# If an error was set. Enter error recovery state
- lookaheadstack.append(lookahead)
- symstack.pop()
- statestack.pop()
+ lookaheadstack.append(lookahead) # Save the current lookahead token
+ symstack.extend(targ[1:-1]) # Put the production slice back on the stack
+ statestack.pop() # Pop back one state (before the reduce)
state = statestack[-1]
sym.type = 'error'
+ sym.value = 'error'
lookahead = sym
errorcount = error_count
self.errorok = False
+
continue
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -546,14 +548,15 @@ class LRParser:
statestack.append(state)
except SyntaxError:
# If an error was set. Enter error recovery state
- lookaheadstack.append(lookahead)
- symstack.pop()
- statestack.pop()
+ lookaheadstack.append(lookahead) # Save the current lookahead token
+ statestack.pop() # Pop back one state (before the reduce)
state = statestack[-1]
sym.type = 'error'
+ sym.value = 'error'
lookahead = sym
errorcount = error_count
self.errorok = False
+
continue
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -811,21 +814,23 @@ class LRParser:
try:
# Call the grammar rule with our special slice object
del symstack[-plen:]
- del statestack[-plen:]
p.callable(pslice)
+ del statestack[-plen:]
symstack.append(sym)
state = goto[statestack[-1]][pname]
statestack.append(state)
except SyntaxError:
# If an error was set. Enter error recovery state
- lookaheadstack.append(lookahead)
- symstack.pop()
- statestack.pop()
+ lookaheadstack.append(lookahead) # Save the current lookahead token
+ symstack.extend(targ[1:-1]) # Put the production slice back on the stack
+ statestack.pop() # Pop back one state (before the reduce)
state = statestack[-1]
sym.type = 'error'
+ sym.value = 'error'
lookahead = sym
errorcount = error_count
self.errorok = False
+
continue
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -854,14 +859,15 @@ class LRParser:
statestack.append(state)
except SyntaxError:
# If an error was set. Enter error recovery state
- lookaheadstack.append(lookahead)
- symstack.pop()
- statestack.pop()
+ lookaheadstack.append(lookahead) # Save the current lookahead token
+ statestack.pop() # Pop back one state (before the reduce)
state = statestack[-1]
sym.type = 'error'
+ sym.value = 'error'
lookahead = sym
errorcount = error_count
self.errorok = False
+
continue
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -1102,21 +1108,23 @@ class LRParser:
try:
# Call the grammar rule with our special slice object
del symstack[-plen:]
- del statestack[-plen:]
p.callable(pslice)
+ del statestack[-plen:]
symstack.append(sym)
state = goto[statestack[-1]][pname]
statestack.append(state)
except SyntaxError:
# If an error was set. Enter error recovery state
- lookaheadstack.append(lookahead)
- symstack.pop()
- statestack.pop()
+ lookaheadstack.append(lookahead) # Save the current lookahead token
+ symstack.extend(targ[1:-1]) # Put the production slice back on the stack
+ statestack.pop() # Pop back one state (before the reduce)
state = statestack[-1]
sym.type = 'error'
+ sym.value = 'error'
lookahead = sym
errorcount = error_count
self.errorok = False
+
continue
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -1140,14 +1148,15 @@ class LRParser:
statestack.append(state)
except SyntaxError:
# If an error was set. Enter error recovery state
- lookaheadstack.append(lookahead)
- symstack.pop()
- statestack.pop()
+ lookaheadstack.append(lookahead) # Save the current lookahead token
+ statestack.pop() # Pop back one state (before the reduce)
state = statestack[-1]
sym.type = 'error'
+ sym.value = 'error'
lookahead = sym
errorcount = error_count
self.errorok = False
+
continue
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -1982,7 +1991,7 @@ class LRTable(object):
import cPickle as pickle
except ImportError:
import pickle
-
+
if not os.path.exists(filename):
raise ImportError
@@ -2979,7 +2988,10 @@ class ParserReflect(object):
fre = re.compile(r'\s*def\s+(p_[a-zA-Z_0-9]*)\(')
for module in self.modules:
- lines, linen = inspect.getsourcelines(module)
+ try:
+ lines, linen = inspect.getsourcelines(module)
+ except IOError:
+ continue
counthash = {}
for linen, line in enumerate(lines):
diff --git a/setup.py b/setup.py
index db1b748..948e2cf 100644
--- a/setup.py
+++ b/setup.py
@@ -17,7 +17,7 @@ PLY is extremely easy to use and provides very extensive error checking.
It is compatible with both Python 2 and Python 3.
""",
license="""BSD""",
- version = "3.8",
+ version = "3.9",
author = "David Beazley",
author_email = "dave@dabeaz.com",
maintainer = "David Beazley",