Skip to content
This repository was archived by the owner on Dec 21, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/ply/yacc.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,17 @@ def restart(self):
def set_defaulted_states(self):
self.defaulted_states = {}
for state, actions in self.action.items():
if not actions:
continue
rules = list(actions.values())
if len(rules) == 1 and rules[0] < 0:
self.defaulted_states[state] = rules[0]
first_rule = rules[0]
if first_rule < 0:
if len(rules) == 1:
self.defaulted_states[state] = first_rule
else:
all_rules = set(rules)
if len(all_rules) == 1:
self.defaulted_states[state] = first_rule

def disable_defaulted_states(self):
self.defaulted_states = {}
Expand Down Expand Up @@ -324,7 +332,7 @@ def parse(self, input=None, lexer=None, debug=False, tracking=False):
if debug:
debug.debug('State : %s', state)

if state not in defaulted_states:
if state not in defaulted_states or errorcount>0:
if not lookahead:
if not lookaheadstack:
lookahead = get_token() # Get the next token
Expand Down
6 changes: 0 additions & 6 deletions tests/yacc_error5.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ def p_statement_assign(t):
'statement : NAME EQUALS expression'
names[t[1]] = t[3]

def p_statement_assign_error(t):
'statement : NAME EQUALS error'
line_start, line_end = t.linespan(3)
pos_start, pos_end = t.lexspan(3)
print("Assignment Error at %d:%d to %d:%d" % (line_start,pos_start,line_end,pos_end))

def p_statement_expr(t):
'statement : expression'
print(t[1])
Expand Down