diff options
author | David Beazley <dave@dabeaz.com> | 2016-08-30 16:12:45 -0500 |
---|---|---|
committer | David Beazley <dave@dabeaz.com> | 2016-08-30 16:12:45 -0500 |
commit | 11913b112e4a63317d82fa8d3c1a3e87a22c83c8 (patch) | |
tree | 03b4b163cc79f29e15757f6d560e897a2071ae1c | |
parent | 5ca447eb64e2717dda18a302ae52500484b6176f (diff) | |
download | ply-11913b112e4a63317d82fa8d3c1a3e87a22c83c8.tar.gz |
Published parser state on parser objects
-rw-r--r-- | CHANGES | 12 | ||||
-rw-r--r-- | ply/yacc.py | 9 |
2 files changed, 21 insertions, 0 deletions
@@ -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. diff --git a/ply/yacc.py b/ply/yacc.py index c1bea17..6842832 100644 --- a/ply/yacc.py +++ b/ply/yacc.py @@ -497,6 +497,7 @@ class LRParser: try: # Call the grammar rule with our special slice object del symstack[-plen:] + self.state = state p.callable(pslice) del statestack[-plen:] #--! DEBUG @@ -539,6 +540,7 @@ class LRParser: 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])) @@ -595,6 +597,7 @@ class LRParser: 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 @@ -814,6 +817,7 @@ class LRParser: 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) @@ -853,6 +857,7 @@ class LRParser: try: # Call the grammar rule with our special slice object + self.state = state p.callable(pslice) symstack.append(sym) state = goto[statestack[-1]][pname] @@ -898,6 +903,7 @@ class LRParser: 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 @@ -1108,6 +1114,7 @@ class LRParser: 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) @@ -1142,6 +1149,7 @@ class LRParser: try: # Call the grammar rule with our special slice object + self.state = state p.callable(pslice) symstack.append(sym) state = goto[statestack[-1]][pname] @@ -1187,6 +1195,7 @@ class LRParser: 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 |