mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-20 03:11:17 +08:00
Small refactoring.
This commit is contained in:
@@ -21,7 +21,7 @@ class Grammar(object):
|
|||||||
|
|
||||||
:param text: A BNF representation of your grammar.
|
:param text: A BNF representation of your grammar.
|
||||||
"""
|
"""
|
||||||
_error_finder_config = None
|
_error_normalizer_config = None
|
||||||
_default_normalizer_config = pep8.PEP8NormalizerConfig()
|
_default_normalizer_config = pep8.PEP8NormalizerConfig()
|
||||||
|
|
||||||
def __init__(self, text, tokenizer, parser=BaseParser, diff_parser=None):
|
def __init__(self, text, tokenizer, parser=BaseParser, diff_parser=None):
|
||||||
@@ -161,7 +161,6 @@ class Grammar(object):
|
|||||||
|
|
||||||
class PythonGrammar(Grammar):
|
class PythonGrammar(Grammar):
|
||||||
_error_normalizer_config = ErrorFinderConfig()
|
_error_normalizer_config = ErrorFinderConfig()
|
||||||
_parser_cls = PythonParser
|
|
||||||
|
|
||||||
def __init__(self, version_info, bnf_text):
|
def __init__(self, version_info, bnf_text):
|
||||||
super(PythonGrammar, self).__init__(
|
super(PythonGrammar, self).__init__(
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ def _get_for_stmt_definition_exprs(for_stmt):
|
|||||||
return list(_iter_definition_exprs_from_lists(exprlist))
|
return list(_iter_definition_exprs_from_lists(exprlist))
|
||||||
|
|
||||||
|
|
||||||
class Context(object):
|
class _Context(object):
|
||||||
def __init__(self, node, add_syntax_error, parent_context=None):
|
def __init__(self, node, add_syntax_error, parent_context=None):
|
||||||
self.node = node
|
self.node = node
|
||||||
self.blocks = []
|
self.blocks = []
|
||||||
@@ -245,7 +245,7 @@ class Context(object):
|
|||||||
self.blocks.pop()
|
self.blocks.pop()
|
||||||
|
|
||||||
def add_context(self, node):
|
def add_context(self, node):
|
||||||
return Context(node, self._add_syntax_error, parent_context=self)
|
return _Context(node, self._add_syntax_error, parent_context=self)
|
||||||
|
|
||||||
def close_child_context(self, child_context):
|
def close_child_context(self, child_context):
|
||||||
self._nonlocal_names_in_subscopes += child_context.finalize()
|
self._nonlocal_names_in_subscopes += child_context.finalize()
|
||||||
@@ -266,7 +266,7 @@ class ErrorFinder(Normalizer):
|
|||||||
parent_scope = node
|
parent_scope = node
|
||||||
else:
|
else:
|
||||||
parent_scope = search_ancestor(node, allowed)
|
parent_scope = search_ancestor(node, allowed)
|
||||||
self._context = Context(parent_scope, self._add_syntax_error)
|
self._context = _Context(parent_scope, self._add_syntax_error)
|
||||||
self._indentation_count = 0
|
self._indentation_count = 0
|
||||||
|
|
||||||
def visit(self, node):
|
def visit(self, node):
|
||||||
|
|||||||
Reference in New Issue
Block a user