mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-11 15:11:59 +08:00
Fix diff parser: If funcs are not copied, errors shouldn't either
This commit is contained in:
@@ -638,21 +638,23 @@ class _NodesTree(object):
|
|||||||
working_stack = new_working_stack
|
working_stack = new_working_stack
|
||||||
had_valid_suite_last = True
|
had_valid_suite_last = True
|
||||||
|
|
||||||
elif (last_node.type in ('error_leaf', 'error_node') or
|
if new_nodes:
|
||||||
_is_flow_node(new_nodes[-1])):
|
last_node = new_nodes[-1]
|
||||||
# Error leafs/nodes don't have a defined start/end. Error
|
if (last_node.type in ('error_leaf', 'error_node') or
|
||||||
# nodes might not end with a newline (e.g. if there's an
|
_is_flow_node(new_nodes[-1])):
|
||||||
# open `(`). Therefore ignore all of them unless they are
|
# Error leafs/nodes don't have a defined start/end. Error
|
||||||
# succeeded with valid parser state.
|
# nodes might not end with a newline (e.g. if there's an
|
||||||
# If we copy flows at the end, they might be continued
|
# open `(`). Therefore ignore all of them unless they are
|
||||||
# after the copy limit (in the new parser).
|
# succeeded with valid parser state.
|
||||||
# In this while loop we try to remove until we find a newline.
|
# If we copy flows at the end, they might be continued
|
||||||
new_nodes.pop()
|
# after the copy limit (in the new parser).
|
||||||
while new_nodes:
|
# In this while loop we try to remove until we find a newline.
|
||||||
last_node = new_nodes[-1]
|
|
||||||
if last_node.get_last_leaf().type == 'newline':
|
|
||||||
break
|
|
||||||
new_nodes.pop()
|
new_nodes.pop()
|
||||||
|
while new_nodes:
|
||||||
|
last_node = new_nodes[-1]
|
||||||
|
if last_node.get_last_leaf().type == 'newline':
|
||||||
|
break
|
||||||
|
new_nodes.pop()
|
||||||
|
|
||||||
if new_nodes:
|
if new_nodes:
|
||||||
if had_valid_suite_last:
|
if had_valid_suite_last:
|
||||||
|
|||||||
@@ -852,3 +852,35 @@ def test_error_dedent_issues(differ):
|
|||||||
differ.initialize(code1)
|
differ.initialize(code1)
|
||||||
differ.parse(code2, parsers=5, copies=1, expect_error_leaves=True)
|
differ.parse(code2, parsers=5, copies=1, expect_error_leaves=True)
|
||||||
differ.parse(code1, parsers=1, copies=0)
|
differ.parse(code1, parsers=1, copies=0)
|
||||||
|
|
||||||
|
|
||||||
|
def test_random_text_insertion(differ):
|
||||||
|
code1 = dedent('''\
|
||||||
|
class C:
|
||||||
|
def f():
|
||||||
|
return node
|
||||||
|
|
||||||
|
def g():
|
||||||
|
try:
|
||||||
|
1
|
||||||
|
except KeyError:
|
||||||
|
2
|
||||||
|
''')
|
||||||
|
|
||||||
|
code2 = dedent('''\
|
||||||
|
class C:
|
||||||
|
def f():
|
||||||
|
return node
|
||||||
|
Some'random text: yeah
|
||||||
|
for push in plan.dfa_pushes:
|
||||||
|
|
||||||
|
def g():
|
||||||
|
try:
|
||||||
|
1
|
||||||
|
except KeyError:
|
||||||
|
2
|
||||||
|
''')
|
||||||
|
|
||||||
|
differ.initialize(code1)
|
||||||
|
differ.parse(code2, parsers=1, copies=1, expect_error_leaves=True)
|
||||||
|
differ.parse(code1, parsers=1, copies=1)
|
||||||
|
|||||||
Reference in New Issue
Block a user