diff --git a/jedi/parser/pgen2/parse.py b/jedi/parser/pgen2/parse.py index 75bcbe8b..b81630cb 100644 --- a/jedi/parser/pgen2/parse.py +++ b/jedi/parser/pgen2/parse.py @@ -144,6 +144,7 @@ class Parser(object): type, value, context) else: self.error_recovery(type, value, context) + break def classify(self, type, value, context): """Turn a token into a label. (Internal)""" @@ -201,5 +202,16 @@ class Parser(object): index = i self.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(self.stack))): + symbol, _, _, _ = node + + # `suite` can sometimes be only simple_stmt, not stmt. + if symbol in (self.grammar.symbol2number['file_input'], + self.grammar.symbol2number['suite']): + index = i + break + self.stack[index + 1:] = [] # No success finding a transition - raise ParseError("bad input", type, value, context) + #raise ParseError("bad input", type, value, context) diff --git a/jedi/parser/representation.py b/jedi/parser/representation.py index 03f7cf77..7c558db5 100644 --- a/jedi/parser/representation.py +++ b/jedi/parser/representation.py @@ -534,7 +534,7 @@ class Scope(Simple, DocstringMixin): if is_node(c, 'simple_stmt'): names += chain.from_iterable( [s.get_defined_names() for s in c.children - if isinstance(s, (ExprStmt, Import, KeywordStatement))]) + if isinstance(s, (ExprStmt, Import))]) elif isinstance(c, (Function, Class)): names.append(c.name) return names