mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-07 21:34:32 +08:00
Fix diff parser: issue with opening brackets
This commit is contained in:
@@ -608,13 +608,6 @@ class _NodesTree(object):
|
|||||||
break
|
break
|
||||||
|
|
||||||
if node.type == 'endmarker':
|
if node.type == 'endmarker':
|
||||||
# We basically removed the endmarker, but we are not allowed to
|
|
||||||
# remove the newline at the end of the line, otherwise it's
|
|
||||||
# going to be missing.
|
|
||||||
newline_index = max(node.prefix.rfind('\n'), node.prefix.rfind('\r'))
|
|
||||||
if newline_index > -1:
|
|
||||||
new_prefix = node.prefix[:newline_index + 1]
|
|
||||||
# Endmarkers just distort all the checks below. Remove them.
|
|
||||||
break
|
break
|
||||||
|
|
||||||
if node.type == 'error_leaf' and node.token_type in ('DEDENT', 'ERROR_DEDENT'):
|
if node.type == 'error_leaf' and node.token_type in ('DEDENT', 'ERROR_DEDENT'):
|
||||||
@@ -677,6 +670,16 @@ class _NodesTree(object):
|
|||||||
new_nodes.pop()
|
new_nodes.pop()
|
||||||
|
|
||||||
if new_nodes:
|
if new_nodes:
|
||||||
|
if not _ends_with_newline(new_nodes[-1].get_last_leaf()) and not had_valid_suite_last:
|
||||||
|
p = new_nodes[-1].get_next_leaf().prefix
|
||||||
|
# We are not allowed to remove the newline at the end of the
|
||||||
|
# line, otherwise it's going to be missing. This happens e.g.
|
||||||
|
# if a bracket is around before that moves newlines to
|
||||||
|
# prefixes.
|
||||||
|
newline_index = max(p.rfind('\n'), p.rfind('\r'))
|
||||||
|
if newline_index > -1:
|
||||||
|
new_prefix = p[:newline_index + 1]
|
||||||
|
|
||||||
if had_valid_suite_last:
|
if had_valid_suite_last:
|
||||||
last = new_nodes[-1]
|
last = new_nodes[-1]
|
||||||
if last.type == 'decorated':
|
if last.type == 'decorated':
|
||||||
|
|||||||
@@ -1176,9 +1176,9 @@ def test_error_dedent_in_between(differ):
|
|||||||
differ.parse(code1, copies=1, parsers=2)
|
differ.parse(code1, copies=1, parsers=2)
|
||||||
|
|
||||||
|
|
||||||
def test_x(differ):
|
def test_some_other_indentation_issues(differ):
|
||||||
code1 = dedent('''\
|
code1 = dedent('''\
|
||||||
class SocketIO:
|
class C:
|
||||||
x
|
x
|
||||||
def f():
|
def f():
|
||||||
""
|
""
|
||||||
@@ -1198,5 +1198,19 @@ def test_x(differ):
|
|||||||
a
|
a
|
||||||
''')
|
''')
|
||||||
differ.initialize(code1)
|
differ.initialize(code1)
|
||||||
differ.parse(code2, copies=ANY, parsers=ANY, expect_error_leaves=True)
|
differ.parse(code2, copies=2, parsers=1, expect_error_leaves=True)
|
||||||
differ.parse(code1, copies=ANY, parsers=ANY)
|
differ.parse(code1, copies=2, parsers=2)
|
||||||
|
|
||||||
|
|
||||||
|
def test_open_bracket(differ):
|
||||||
|
code1 = dedent('''\
|
||||||
|
class C:
|
||||||
|
1
|
||||||
|
2 # ha
|
||||||
|
''')
|
||||||
|
code2 = insert_line_into_code(code1, 2, ' [str\n')
|
||||||
|
code3 = insert_line_into_code(code2, 4, ' str\n')
|
||||||
|
differ.initialize(code1)
|
||||||
|
differ.parse(code2, copies=1, parsers=1, expect_error_leaves=True)
|
||||||
|
differ.parse(code3, copies=1, parsers=1, expect_error_leaves=True)
|
||||||
|
differ.parse(code1, copies=1, parsers=1)
|
||||||
|
|||||||
Reference in New Issue
Block a user