mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-19 19:01:24 +08:00
Create better ways for debugging the diff parser
This commit is contained in:
@@ -17,6 +17,25 @@ from parso.python.tokenize import PythonToken
|
|||||||
from parso.python.token import PythonTokenTypes
|
from parso.python.token import PythonTokenTypes
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
DEBUG_DIFF_PARSER = False
|
||||||
|
|
||||||
|
|
||||||
|
def _assert_valid_graph(node):
|
||||||
|
"""
|
||||||
|
Checks if the parent/children relationship is correct.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
children = node.children
|
||||||
|
except AttributeError:
|
||||||
|
previous_leaf = node.get_previous_leaf()
|
||||||
|
if previous_leaf is not None:
|
||||||
|
assert previous_leaf.end_pos <= node.start_pos, \
|
||||||
|
(previous_leaf, node)
|
||||||
|
return
|
||||||
|
|
||||||
|
for child in children:
|
||||||
|
assert child.parent == node
|
||||||
|
_assert_valid_graph(child)
|
||||||
|
|
||||||
|
|
||||||
def _get_last_line(node_or_leaf):
|
def _get_last_line(node_or_leaf):
|
||||||
@@ -171,7 +190,12 @@ class DiffParser(object):
|
|||||||
% (last_pos, line_length, parso.__version__, ''.join(diff))
|
% (last_pos, line_length, parso.__version__, ''.join(diff))
|
||||||
)
|
)
|
||||||
|
|
||||||
#assert self._module.get_code() == ''.join(new_lines)
|
if DEBUG_DIFF_PARSER:
|
||||||
|
# If there is reasonable suspicion that the diff parser is not
|
||||||
|
# behaving well, this should be enabled.
|
||||||
|
assert self._module.get_code() == ''.join(new_lines)
|
||||||
|
_assert_valid_graph(self._module)
|
||||||
|
|
||||||
LOG.debug('diff parser end')
|
LOG.debug('diff parser end')
|
||||||
return self._module
|
return self._module
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import pytest
|
|||||||
from parso.utils import split_lines
|
from parso.utils import split_lines
|
||||||
from parso import cache
|
from parso import cache
|
||||||
from parso import load_grammar
|
from parso import load_grammar
|
||||||
from parso.python.diff import DiffParser
|
from parso.python.diff import DiffParser, _assert_valid_graph
|
||||||
from parso import parse
|
from parso import parse
|
||||||
|
|
||||||
|
|
||||||
@@ -34,24 +34,6 @@ def _check_error_leaves_nodes(node):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def _assert_valid_graph(node):
|
|
||||||
"""
|
|
||||||
Checks if the parent/children relationship is correct.
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
children = node.children
|
|
||||||
except AttributeError:
|
|
||||||
previous_leaf = node.get_previous_leaf()
|
|
||||||
if previous_leaf is not None:
|
|
||||||
assert previous_leaf.end_pos <= node.start_pos, \
|
|
||||||
(previous_leaf, node)
|
|
||||||
return
|
|
||||||
|
|
||||||
for child in children:
|
|
||||||
assert child.parent == node
|
|
||||||
_assert_valid_graph(child)
|
|
||||||
|
|
||||||
|
|
||||||
class Differ(object):
|
class Differ(object):
|
||||||
grammar = load_grammar()
|
grammar = load_grammar()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user