summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Beazley <dave@dabeaz.com>2015-04-22 09:33:51 -0500
committerDavid Beazley <dave@dabeaz.com>2015-04-22 09:33:51 -0500
commit33a6424e77539c1b687ad6626c3a6a006dcc7d81 (patch)
treedb39368eb03c3fe780412ddf54409e365f5f840b
parent8fb06b0c55e91d2d097a4d19782e22664a759830 (diff)
downloadply-33a6424e77539c1b687ad6626c3a6a006dcc7d81.tar.gz
Fixed minor bug in line-number tracking. Fixed failing yacc_error5 test.
-rw-r--r--ply/yacc.py41
-rw-r--r--test/testyacc.py2
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"
))