Skip to content

Commit

Permalink
Enhanced tracking of positional information in error tokens.
Browse files Browse the repository at this point in the history
  • Loading branch information
dabeaz committed Apr 19, 2012
1 parent 7b14435 commit cc96f69
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions ply/yacc.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,17 +566,25 @@ def parsedebug(self,input=None,lexer=None,debug=None,tracking=0,tokenfunc=None):
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
t = YaccSymbol()
t.type = 'error'
if hasattr(lookahead,"lineno"):
t.lineno = lookahead.lineno
if hasattr(lookahead,"lexpos"):
t.lexpos = lookahead.lexpos
t.value = lookahead
lookaheadstack.append(lookahead)
lookahead = t
else:
symstack.pop()
sym = symstack.pop()
if tracking:
lookahead.lineno = sym.lineno
lookahead.lexpos = sym.lexpos
statestack.pop()
state = statestack[-1] # Potential bug fix

Expand Down Expand Up @@ -839,17 +847,25 @@ def parseopt(self,input=None,lexer=None,debug=0,tracking=0,tokenfunc=None):
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
t = YaccSymbol()
t.type = 'error'
if hasattr(lookahead,"lineno"):
t.lineno = lookahead.lineno
if hasattr(lookahead,"lexpos"):
t.lexpos = lookahead.lexpos
t.value = lookahead
lookaheadstack.append(lookahead)
lookahead = t
else:
symstack.pop()
sym = symstack.pop()
if tracking:
lookahead.lineno = sym.lineno
lookahead.lexpos = sym.lexpos
statestack.pop()
state = statestack[-1] # Potential bug fix

Expand Down Expand Up @@ -1100,6 +1116,8 @@ def parseopt_notrack(self,input=None,lexer=None,debug=0,tracking=0,tokenfunc=Non
t.type = 'error'
if hasattr(lookahead,"lineno"):
t.lineno = lookahead.lineno
if hasattr(lookahead,"lexpos"):
t.lexpos = lookahead.lexpos
t.value = lookahead
lookaheadstack.append(lookahead)
lookahead = t
Expand Down

0 comments on commit cc96f69

Please sign in to comment.