Parser error recovery simplified. Just fall back to scopes, if somethings wrong.

This commit is contained in:
Dave Halter
2014-11-04 09:40:32 +01:00
parent 8c775e0a18
commit c6c2768dda
2 changed files with 13 additions and 23 deletions

View File

@@ -73,6 +73,7 @@ class NameFinder(object):
names = scope.names_dict[str(self.name_str)]
except KeyError:
return []
names = [name for name in names if name.is_definition()]
names = pr.filter_after_position(names, position)

View File

@@ -103,30 +103,19 @@ class Parser(object):
allows using different grammars (even non-Python). However, error
recovery is purely written for Python.
"""
if value == '\n': # Statement is not finished.
# Now remove the whole statement.
for i, (dfa, state, node) in reversed(list(enumerate(stack))):
symbol, _, _, _ = node
# For now just discard everything that is not a suite or
# file_input, if we detect an error.
for i, (dfa, state, node) in reversed(list(enumerate(stack))):
symbol, _, _, _ = node
# `suite` can sometimes be only simple_stmt, not stmt.
if symbol in (grammar.symbol2number['simple_stmt'],
grammar.symbol2number['stmt']):
index = i
self._stack_removal(stack, index)
else:
# For now just discard everything that is not a suite or
# file_input, if we detect an error.
for i, (dfa, state, node) in reversed(list(enumerate(stack))):
symbol, _, _, _ = node
# `suite` can sometimes be only simple_stmt, not stmt.
if symbol in (grammar.symbol2number['file_input'],
grammar.symbol2number['suite']):
index = i
break
self._stack_removal(stack, index + 1)
# No success finding a transition
#raise ParseError("bad input", type, value, context)
# `suite` can sometimes be only simple_stmt, not stmt.
if symbol in (grammar.symbol2number['file_input'],
grammar.symbol2number['suite']):
index = i
break
self._stack_removal(stack, index + 1)
# No success finding a transition
#raise ParseError("bad input", type, value, context)
def _stack_removal(self, stack, start_index):
def clear_names(children):