Skip to content

Commit

Permalink
Published parser state on parser objects
Browse files Browse the repository at this point in the history
  • Loading branch information
dabeaz committed Aug 30, 2016
1 parent 5ca447e commit 11913b1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
Version 3.9
---------------------
08/30/16: beazley
Exposed the parser state number as the parser.state attribute
in productions and error functions. For example:

def p_somerule(p):
'''
rule : A B C
'''
print('State:', p.parser.state)

May address issue #65 (publish current state in error callback).

08/30/16: beazley
Fixed Issue #88. Python3 compatibility with ply/cpp.

Expand Down
9 changes: 9 additions & 0 deletions ply/yacc.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ def parsedebug(self, input=None, lexer=None, debug=False, tracking=False, tokenf
try:
# Call the grammar rule with our special slice object
del symstack[-plen:]
self.state = state
p.callable(pslice)
del statestack[-plen:]
#--! DEBUG
Expand Down Expand Up @@ -539,6 +540,7 @@ def parsedebug(self, input=None, lexer=None, debug=False, tracking=False, tokenf

try:
# Call the grammar rule with our special slice object
self.state = state
p.callable(pslice)
#--! DEBUG
debug.info('Result : %s', format_result(pslice[0]))
Expand Down Expand Up @@ -595,6 +597,7 @@ def parsedebug(self, input=None, lexer=None, debug=False, tracking=False, tokenf
if self.errorfunc:
if errtoken and not hasattr(errtoken, 'lexer'):
errtoken.lexer = lexer
self.state = state
tok = call_errorfunc(self.errorfunc, errtoken, self)
if self.errorok:
# User must have done some kind of panic
Expand Down Expand Up @@ -814,6 +817,7 @@ def parseopt(self, input=None, lexer=None, debug=False, tracking=False, tokenfun
try:
# Call the grammar rule with our special slice object
del symstack[-plen:]
self.state = state
p.callable(pslice)
del statestack[-plen:]
symstack.append(sym)
Expand Down Expand Up @@ -853,6 +857,7 @@ def parseopt(self, input=None, lexer=None, debug=False, tracking=False, tokenfun

try:
# Call the grammar rule with our special slice object
self.state = state
p.callable(pslice)
symstack.append(sym)
state = goto[statestack[-1]][pname]
Expand Down Expand Up @@ -898,6 +903,7 @@ def parseopt(self, input=None, lexer=None, debug=False, tracking=False, tokenfun
if self.errorfunc:
if errtoken and not hasattr(errtoken, 'lexer'):
errtoken.lexer = lexer
self.state = state
tok = call_errorfunc(self.errorfunc, errtoken, self)
if self.errorok:
# User must have done some kind of panic
Expand Down Expand Up @@ -1108,6 +1114,7 @@ def parseopt_notrack(self, input=None, lexer=None, debug=False, tracking=False,
try:
# Call the grammar rule with our special slice object
del symstack[-plen:]
self.state = state
p.callable(pslice)
del statestack[-plen:]
symstack.append(sym)
Expand Down Expand Up @@ -1142,6 +1149,7 @@ def parseopt_notrack(self, input=None, lexer=None, debug=False, tracking=False,

try:
# Call the grammar rule with our special slice object
self.state = state
p.callable(pslice)
symstack.append(sym)
state = goto[statestack[-1]][pname]
Expand Down Expand Up @@ -1187,6 +1195,7 @@ def parseopt_notrack(self, input=None, lexer=None, debug=False, tracking=False,
if self.errorfunc:
if errtoken and not hasattr(errtoken, 'lexer'):
errtoken.lexer = lexer
self.state = state
tok = call_errorfunc(self.errorfunc, errtoken, self)
if self.errorok:
# User must have done some kind of panic
Expand Down

0 comments on commit 11913b1

Please sign in to comment.