mirror of
https://github.com/davidhalter/parso.git
synced 2026-03-01 21:07:28 +08:00
Refactor the initialization of contexts a bit so a varity of nodes can be taken as input.
This commit is contained in:
@@ -261,12 +261,16 @@ class ErrorFinder(Normalizer):
|
|||||||
self._version = self._grammar.version_info
|
self._version = self._grammar.version_info
|
||||||
|
|
||||||
def initialize(self, node):
|
def initialize(self, node):
|
||||||
allowed = 'classdef', 'funcdef', 'file_input'
|
def create_context(node):
|
||||||
if node.type in allowed:
|
if node is None:
|
||||||
parent_scope = node
|
return None
|
||||||
else:
|
|
||||||
parent_scope = search_ancestor(node, allowed)
|
parent_context = create_context(node.parent)
|
||||||
self._context = _Context(parent_scope, self._add_syntax_error)
|
if node.type in ('classdef', 'funcdef', 'file_input'):
|
||||||
|
return _Context(node, self._add_syntax_error, parent_context)
|
||||||
|
return parent_context
|
||||||
|
|
||||||
|
self._context = create_context(node) or _Context(node, 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