forked from VimPlug/jedi
Ifs in two directions.
This commit is contained in:
@@ -42,9 +42,14 @@ def _merge_names_dicts(base_dict, other_dict):
|
||||
|
||||
|
||||
def _flows_finished(grammar, stack):
|
||||
for dfa, newstate, (symbol_number, nodes) in reversed(stack):
|
||||
print('symbol', grammar.number2symbol[symbol_number], nodes)
|
||||
#if symbol_number == symbol2number['suite']:
|
||||
"""
|
||||
if, while, for and try might not be finished, because another part might
|
||||
still be parsed.
|
||||
"""
|
||||
for dfa, newstate, (symbol_number, nodes) in stack:
|
||||
if grammar.number2symbol[symbol_number] in ('if_stmt', 'while_stmt',
|
||||
'for_stmt', 'try_stmt'):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
@@ -479,8 +484,7 @@ class DiffParser(object):
|
||||
|
||||
if typ == tokenize.DEDENT:
|
||||
indents.pop()
|
||||
if omitted_first_indent and not indents and \
|
||||
_flows_finished(self._grammar, stack):
|
||||
if omitted_first_indent and not indents:
|
||||
# We are done here, only thing that can come now is an
|
||||
# endmarker or another dedented code block.
|
||||
yield tokenize.TokenInfo(tokenize.ENDMARKER, '', start_pos, '')
|
||||
|
||||
@@ -60,7 +60,7 @@ class Differ(object):
|
||||
self.parser = ParserWithRecovery(grammar, source)
|
||||
return self.parser.module
|
||||
|
||||
def parse(self, source, copies=0, parsers=0):
|
||||
def parse(self, source, copies=0, parsers=0, allow_error_leafs=False):
|
||||
lines = splitlines(source, keepends=True)
|
||||
diff_parser = DiffParser(self.parser)
|
||||
new_module = diff_parser.update(lines)
|
||||
@@ -69,7 +69,8 @@ class Differ(object):
|
||||
assert diff_parser._parser_count == parsers
|
||||
self.parser.module = new_module
|
||||
self.parser._parsed = new_module
|
||||
assert not _check_error_leafs(new_module)
|
||||
if not allow_error_leafs:
|
||||
assert not _check_error_leafs(new_module)
|
||||
return new_module
|
||||
|
||||
|
||||
@@ -125,8 +126,13 @@ def test_if_simple(differ):
|
||||
if 1:
|
||||
a = 3
|
||||
''')
|
||||
else_ = "else:\n a = ''\n"
|
||||
|
||||
differ.initialize(src + 'a')
|
||||
differ.parse(src + "else:\n a = ''\na", copies=1, parsers=1)
|
||||
differ.parse(src + else_ + "a", copies=0, parsers=1)
|
||||
|
||||
differ.parse(else_, parsers=1, allow_error_leafs=True)
|
||||
differ.parse(src + else_, parsers=1)
|
||||
|
||||
|
||||
def test_func_with_for_and_comment():
|
||||
|
||||
Reference in New Issue
Block a user