forked from VimPlug/jedi
classes and functions are new statements and should never get removed by the error recovery.
This commit is contained in:
@@ -216,6 +216,7 @@ class Parser(object):
|
|||||||
# No success finding a transition
|
# No success finding a transition
|
||||||
print('err', tokenize.tok_name[typ], repr(value), start_pos, len(stack), index)
|
print('err', tokenize.tok_name[typ], repr(value), start_pos, len(stack), index)
|
||||||
self._stack_removal(grammar, stack, index + 1, value, start_pos)
|
self._stack_removal(grammar, stack, index + 1, value, start_pos)
|
||||||
|
return value not in ('def', 'class')
|
||||||
|
|
||||||
def _stack_removal(self, grammar, stack, start_index, value, start_pos):
|
def _stack_removal(self, grammar, stack, start_index, value, start_pos):
|
||||||
def clear_names(children):
|
def clear_names(children):
|
||||||
|
|||||||
@@ -166,7 +166,8 @@ class Parser(object):
|
|||||||
# Done parsing, but another token is input
|
# Done parsing, but another token is input
|
||||||
raise ParseError("too much input", type, value, start_pos)
|
raise ParseError("too much input", type, value, start_pos)
|
||||||
else:
|
else:
|
||||||
self.error_recovery(self.grammar, self.stack, type, value, start_pos)
|
if self.error_recovery(self.grammar, self.stack, type,
|
||||||
|
value, start_pos):
|
||||||
break
|
break
|
||||||
|
|
||||||
def classify(self, type, value, start_pos):
|
def classify(self, type, value, start_pos):
|
||||||
|
|||||||
@@ -211,6 +211,9 @@ del _compile
|
|||||||
|
|
||||||
tabsize = 8
|
tabsize = 8
|
||||||
|
|
||||||
|
ALWAYS_BREAK_TOKEN = (';', 'import', 'from', 'class', 'def', 'try', 'except',
|
||||||
|
'finally', 'while', 'return')
|
||||||
|
|
||||||
|
|
||||||
def source_tokens(source, line_offset=0):
|
def source_tokens(source, line_offset=0):
|
||||||
"""Generate tokens from a the source code (string)."""
|
"""Generate tokens from a the source code (string)."""
|
||||||
@@ -318,6 +321,8 @@ def generate_tokens(readline, line_offset=0):
|
|||||||
yield Token(STRING, token, spos, prefix)
|
yield Token(STRING, token, spos, prefix)
|
||||||
elif initial in namechars: # ordinary name
|
elif initial in namechars: # ordinary name
|
||||||
yield Token(NAME, token, spos, prefix)
|
yield Token(NAME, token, spos, prefix)
|
||||||
|
if token in ALWAYS_BREAK_TOKEN:
|
||||||
|
paren_level = 0
|
||||||
elif initial == '\\' and line[start:] == '\\\n': # continued stmt
|
elif initial == '\\' and line[start:] == '\\\n': # continued stmt
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user