Move the iter_errors and normalizer methods to grammar.py.

This commit is contained in:
Dave Halter
2017-08-06 15:32:50 +02:00
parent 3e39a04bb1
commit 90edb2d0cf
9 changed files with 47 additions and 40 deletions

View File

@@ -22,7 +22,6 @@ class NodeOrLeaf(object):
The base class for nodes and leaves.
"""
__slots__ = ()
default_normalizer_config = None
def get_root_node(self):
"""
@@ -154,28 +153,6 @@ class NodeOrLeaf(object):
e.g. a statement.
"""
def _get_normalizer(self, normalizer_config, grammar):
if normalizer_config is None:
normalizer_config = self.default_normalizer_config
if normalizer_config is None:
raise ValueError("You need to specify a normalizer, because "
"there's no default normalizer for this tree.")
return normalizer_config.create_normalizer(grammar)
def _normalize(self, grammar, normalizer_config=None):
"""
TODO this is not public, yet.
The returned code will be normalized, e.g. PEP8 for Python.
"""
normalizer = self._get_normalizer(normalizer_config, grammar)
return normalizer.walk(self)
def _get_normalizer_issues(self, grammar, normalizer_config=None):
normalizer = self._get_normalizer(normalizer_config, grammar)
normalizer.walk(self)
return normalizer.issues
class Leaf(NodeOrLeaf):
__slots__ = ('value', 'parent', 'line', 'indent', 'prefix')