summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Beazley <dave@dabeaz.com>2012-04-26 15:16:01 -0500
committerDavid Beazley <dave@dabeaz.com>2012-04-26 15:16:01 -0500
commitc0f9ed554f3425b08b717933f94eb34485e8c993 (patch)
tree65cf0e67b353ed855e3930bf22098caa5d8b44ad
parenta92eae1ccce335597a053bb3fea28586b3997f44 (diff)
downloadply-c0f9ed554f3425b08b717933f94eb34485e8c993.tar.gz
Reverted p_error() API
-rw-r--r--ply/yacc.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/ply/yacc.py b/ply/yacc.py
index 41eeb03..fed7e59 100644
--- a/ply/yacc.py
+++ b/ply/yacc.py
@@ -165,12 +165,14 @@ _errok = None
_token = None
_restart = None
_warnmsg = """PLY: Don't use global functions errok(), token(), and restart() in p_error().
-Instead, define p_error() with two arguments and invoke methods on the supplied parser instance:
+Instead, invoke the methods on the associated parser instance:
- def p_error(p, parser):
+ def p_error(p):
...
# Use parser.errok(), parser.token(), parser.restart()
...
+
+ parser = yacc.yacc()
"""
import warnings
def errok():
@@ -185,16 +187,14 @@ def token():
warnings.warn(_warnmsg)
return _token()
-# Utility function to call the p_error() function with 1 or 2 arguments
+# Utility function to call the p_error() function with some deprecation hacks
def call_errorfunc(errorfunc,token,parser):
global _errok, _token, _restart
_errok = parser.errok
_token = parser.token
_restart = parser.restart
- try:
- return errorfunc(token,parser)
- except TypeError:
- return errorfunc(token)
+ r = errorfunc(token)
+ del _errok, _token, _restart
#-----------------------------------------------------------------------------
# === LR Parsing Engine ===
@@ -2931,8 +2931,8 @@ class ParserReflect(object):
self.files[efile] = 1
argcount = func_code(self.error_func).co_argcount - ismethod
- if argcount not in (1,2):
- self.log.error("%s:%d: p_error() requires 1 or 2 arguments",efile,eline)
+ if argcount != 1:
+ self.log.error("%s:%d: p_error() requires 1 argument",efile,eline)
self.error = 1
# Get the tokens map