diff options
author | David Beazley <dave@dabeaz.com> | 2015-04-22 09:33:51 -0500 |
---|---|---|
committer | David Beazley <dave@dabeaz.com> | 2015-04-22 09:33:51 -0500 |
commit | 33a6424e77539c1b687ad6626c3a6a006dcc7d81 (patch) | |
tree | db39368eb03c3fe780412ddf54409e365f5f840b /ply | |
parent | 8fb06b0c55e91d2d097a4d19782e22664a759830 (diff) | |
download | ply-33a6424e77539c1b687ad6626c3a6a006dcc7d81.tar.gz |
Fixed minor bug in line-number tracking. Fixed failing yacc_error5 test.
Diffstat (limited to 'ply')
-rw-r--r-- | ply/yacc.py | 41 |
1 files changed, 26 insertions, 15 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 |