diff options
-rw-r--r-- | ply/yacc.py | 41 | ||||
-rw-r--r-- | test/testyacc.py | 2 |
2 files changed, 27 insertions, 16 deletions
diff --git a/ply/yacc.py b/ply/yacc.py index 7dcd6c5..d2138df 100644 --- a/ply/yacc.py +++ b/ply/yacc.py @@ -642,27 +642,34 @@ class LRParser: if sym.type == 'error': # Hmmm. Error is on top of stack, we'll just nuke input # symbol and continue + #--! TRACKING if tracking: sym.endlineno = getattr(lookahead, 'lineno', sym.lineno) sym.endlexpos = getattr(lookahead, 'lexpos', sym.lexpos) + #--! TRACKING lookahead = None continue + + # Create the error symbol for the first time and make it the new lookahead symbol t = YaccSymbol() t.type = 'error' + if hasattr(lookahead, 'lineno'): - t.lineno = lookahead.lineno + t.lineno = t.endlineno = lookahead.lineno if hasattr(lookahead, 'lexpos'): - t.lexpos = lookahead.lexpos + t.lexpos = t.endlexpos = lookahead.lexpos t.value = lookahead lookaheadstack.append(lookahead) lookahead = t else: sym = symstack.pop() + #--! TRACKING if tracking: lookahead.lineno = sym.lineno lookahead.lexpos = sym.lexpos + #--! TRACKING statestack.pop() - state = statestack[-1] # Potential bug fix + state = statestack[-1] continue @@ -935,27 +942,34 @@ class LRParser: if sym.type == 'error': # Hmmm. Error is on top of stack, we'll just nuke input # symbol and continue + #--! TRACKING if tracking: sym.endlineno = getattr(lookahead, 'lineno', sym.lineno) sym.endlexpos = getattr(lookahead, 'lexpos', sym.lexpos) + #--! TRACKING lookahead = None continue + + # Create the error symbol for the first time and make it the new lookahead symbol t = YaccSymbol() t.type = 'error' + if hasattr(lookahead, 'lineno'): - t.lineno = lookahead.lineno + t.lineno = t.endlineno = lookahead.lineno if hasattr(lookahead, 'lexpos'): - t.lexpos = lookahead.lexpos + t.lexpos = t.endlexpos = lookahead.lexpos t.value = lookahead lookaheadstack.append(lookahead) lookahead = t else: sym = symstack.pop() + #--! TRACKING if tracking: lookahead.lineno = sym.lineno lookahead.lexpos = sym.lexpos + #--! TRACKING statestack.pop() - state = statestack[-1] # Potential bug fix + state = statestack[-1] continue @@ -1214,27 +1228,24 @@ class LRParser: if sym.type == 'error': # Hmmm. Error is on top of stack, we'll just nuke input # symbol and continue - if tracking: - sym.endlineno = getattr(lookahead, 'lineno', sym.lineno) - sym.endlexpos = getattr(lookahead, 'lexpos', sym.lexpos) lookahead = None continue + + # Create the error symbol for the first time and make it the new lookahead symbol t = YaccSymbol() t.type = 'error' + if hasattr(lookahead, 'lineno'): - t.lineno = lookahead.lineno + t.lineno = t.endlineno = lookahead.lineno if hasattr(lookahead, 'lexpos'): - t.lexpos = lookahead.lexpos + t.lexpos = t.endlexpos = lookahead.lexpos t.value = lookahead lookaheadstack.append(lookahead) lookahead = t else: sym = symstack.pop() - if tracking: - lookahead.lineno = sym.lineno - lookahead.lexpos = sym.lexpos statestack.pop() - state = statestack[-1] # Potential bug fix + state = statestack[-1] continue diff --git a/test/testyacc.py b/test/testyacc.py index 357dcdc..96d4b0d 100644 --- a/test/testyacc.py +++ b/test/testyacc.py @@ -202,7 +202,7 @@ class YaccErrorWarningTests(unittest.TestCase): "Undefined name 'a'\n" "Syntax error at 'b'\n" "Syntax error at 4:18 to 4:22\n" - "Assignment Error at 2:5 to 5:33\n" + "Assignment Error at 2:5 to 5:27\n" "13\n" )) |