mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-09 22:25:53 +08:00
Fix valid graph asserting for some dedents that are errors
This commit is contained in:
@@ -33,10 +33,11 @@ def _assert_valid_graph(node):
|
|||||||
|
|
||||||
# Ignore INDENT is necessary, because indent/dedent tokens don't
|
# Ignore INDENT is necessary, because indent/dedent tokens don't
|
||||||
# contain value/prefix and are just around, because of the tokenizer.
|
# contain value/prefix and are just around, because of the tokenizer.
|
||||||
if node.type == 'error_leaf' and node.token_type in ('INDENT', 'ERROR_DEDENT'):
|
error_tokens = 'INDENT', 'ERROR_DEDENT', 'DEDENT'
|
||||||
|
if node.type == 'error_leaf' and node.token_type in error_tokens:
|
||||||
return
|
return
|
||||||
while previous_leaf and previous_leaf.type == 'error_leaf' \
|
while previous_leaf and previous_leaf.type == 'error_leaf' \
|
||||||
and previous_leaf.token_type in ('INDENT', 'ERROR_DEDENT'):
|
and previous_leaf.token_type in error_tokens:
|
||||||
assert previous_leaf.end_pos <= node.start_pos, \
|
assert previous_leaf.end_pos <= node.start_pos, \
|
||||||
(previous_leaf, node)
|
(previous_leaf, node)
|
||||||
previous_leaf = previous_leaf.get_previous_leaf()
|
previous_leaf = previous_leaf.get_previous_leaf()
|
||||||
|
|||||||
@@ -884,3 +884,38 @@ Some'random text: yeah
|
|||||||
differ.initialize(code1)
|
differ.initialize(code1)
|
||||||
differ.parse(code2, parsers=1, copies=1, expect_error_leaves=True)
|
differ.parse(code2, parsers=1, copies=1, expect_error_leaves=True)
|
||||||
differ.parse(code1, parsers=1, copies=1)
|
differ.parse(code1, parsers=1, copies=1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_l(differ):
|
||||||
|
code1 = dedent('''\
|
||||||
|
class C:
|
||||||
|
def f(self):
|
||||||
|
def iterate():
|
||||||
|
if 1:
|
||||||
|
yield t
|
||||||
|
else:
|
||||||
|
yield
|
||||||
|
return
|
||||||
|
|
||||||
|
def g():
|
||||||
|
3
|
||||||
|
''')
|
||||||
|
|
||||||
|
code2 = dedent('''\
|
||||||
|
def f(self):
|
||||||
|
def iterate():
|
||||||
|
if 1:
|
||||||
|
yield t
|
||||||
|
hahahaha
|
||||||
|
if 2:
|
||||||
|
else:
|
||||||
|
yield
|
||||||
|
return
|
||||||
|
|
||||||
|
def g():
|
||||||
|
3
|
||||||
|
''')
|
||||||
|
|
||||||
|
differ.initialize(code1)
|
||||||
|
differ.parse(code2, parsers=2, copies=1, expect_error_leaves=True)
|
||||||
|
differ.parse(code1, parsers=1, copies=1)
|
||||||
|
|||||||
Reference in New Issue
Block a user