forked from VimPlug/jedi
fixed parser change problems
This commit is contained in:
@@ -150,14 +150,12 @@ class NoErrorTokenizer(object):
|
|||||||
self.in_flow = False
|
self.in_flow = False
|
||||||
elif self.new_indent:
|
elif self.new_indent:
|
||||||
self.parser_indent = indent
|
self.parser_indent = indent
|
||||||
|
self.new_indent = False
|
||||||
|
|
||||||
if not self.in_flow:
|
if not self.in_flow:
|
||||||
if tok in FLOWS or tok in breaks:
|
if tok in FLOWS or tok in breaks:
|
||||||
self.in_flow = tok in FLOWS
|
self.in_flow = tok in FLOWS
|
||||||
if not self.is_decorator and not self.in_flow:
|
if not self.is_decorator and not self.in_flow:
|
||||||
print tok, c
|
|
||||||
if 6230 < c[2][0] < 6290:
|
|
||||||
print tok, c
|
|
||||||
close()
|
close()
|
||||||
self.is_decorator = '@' == tok
|
self.is_decorator = '@' == tok
|
||||||
if not self.is_decorator:
|
if not self.is_decorator:
|
||||||
@@ -165,6 +163,8 @@ class NoErrorTokenizer(object):
|
|||||||
self.new_indent = True
|
self.new_indent = True
|
||||||
|
|
||||||
if tok != '@':
|
if tok != '@':
|
||||||
|
if self.first_stmt and not self.new_indent:
|
||||||
|
self.parser_indent = indent
|
||||||
self.first_stmt = False
|
self.first_stmt = False
|
||||||
return c
|
return c
|
||||||
|
|
||||||
|
|||||||
@@ -373,7 +373,6 @@ def find_name(scope, name_str, position=None, search_global=False,
|
|||||||
comparison_func = lambda name: (name.start_pos)
|
comparison_func = lambda name: (name.start_pos)
|
||||||
|
|
||||||
for nscope, name_list in scope_generator:
|
for nscope, name_list in scope_generator:
|
||||||
print nscope, name_list
|
|
||||||
break_scopes = []
|
break_scopes = []
|
||||||
# here is the position stuff happening (sorting of variables)
|
# here is the position stuff happening (sorting of variables)
|
||||||
for name in sorted(name_list, key=comparison_func, reverse=True):
|
for name in sorted(name_list, key=comparison_func, reverse=True):
|
||||||
|
|||||||
@@ -112,21 +112,23 @@ class CachedFastParser(type):
|
|||||||
class ParserNode(object):
|
class ParserNode(object):
|
||||||
def __init__(self, parser, code, parent=None):
|
def __init__(self, parser, code, parent=None):
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.parser = parser
|
|
||||||
self.code = code
|
self.code = code
|
||||||
self.hash = hash(code)
|
self.hash = hash(code)
|
||||||
|
|
||||||
self.children = []
|
self.children = []
|
||||||
self._old_children = []
|
self._old_children = []
|
||||||
# must be created before new things are added to it.
|
# must be created before new things are added to it.
|
||||||
|
self.save_contents(parser)
|
||||||
|
|
||||||
|
def save_contents(self, parser):
|
||||||
|
self.parser = parser
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# with fast_parser we have either 1 subscope or only statements.
|
# with fast_parser we have either 1 subscope or only statements.
|
||||||
self._content_scope = self.parser.module.subscopes[0]
|
self._content_scope = self.parser.module.subscopes[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
self._content_scope = self.parser.module
|
self._content_scope = self.parser.module
|
||||||
self.save_contents()
|
|
||||||
|
|
||||||
def save_contents(self):
|
|
||||||
scope = self._content_scope
|
scope = self._content_scope
|
||||||
self._contents = {}
|
self._contents = {}
|
||||||
for c in SCOPE_CONTENTS:
|
for c in SCOPE_CONTENTS:
|
||||||
@@ -159,7 +161,10 @@ class ParserNode(object):
|
|||||||
try:
|
try:
|
||||||
el = module.statements[0]
|
el = module.statements[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
el = module.imports[0]
|
try:
|
||||||
|
el = module.imports[0]
|
||||||
|
except IndexError:
|
||||||
|
el = module.returns[0]
|
||||||
return el.start_pos[1]
|
return el.start_pos[1]
|
||||||
|
|
||||||
def _set_items(self, parser, set_parent=False):
|
def _set_items(self, parser, set_parent=False):
|
||||||
@@ -172,6 +177,9 @@ class ParserNode(object):
|
|||||||
for i in items:
|
for i in items:
|
||||||
i.parent = scope
|
i.parent = scope
|
||||||
content += items
|
content += items
|
||||||
|
if str(parser.module.name) == 'ordering':
|
||||||
|
#print scope.subscopes
|
||||||
|
pass
|
||||||
scope.is_generator |= parser.module.is_generator
|
scope.is_generator |= parser.module.is_generator
|
||||||
|
|
||||||
def add_node(self, node):
|
def add_node(self, node):
|
||||||
@@ -330,15 +338,14 @@ class FastParser(use_metaclass(CachedFastParser)):
|
|||||||
nodes += self.current_node._old_children
|
nodes += self.current_node._old_children
|
||||||
|
|
||||||
# check if code_part has already been parsed
|
# check if code_part has already been parsed
|
||||||
print '#'*45,self._line_offset, p and p.end_pos, '\n', code_part
|
#print '#'*45,self._line_offset, p and p.end_pos, '\n', code_part
|
||||||
p, node = self._get_parser(code_part, nodes)
|
p, node = self._get_parser(code_part, nodes)
|
||||||
|
|
||||||
if is_first:
|
if is_first:
|
||||||
if self.current_node is None:
|
if self.current_node is None:
|
||||||
self.current_node = ParserNode(p, code)
|
self.current_node = ParserNode(p, code)
|
||||||
else:
|
else:
|
||||||
self.current_node.parser = p
|
self.current_node.save_contents(p)
|
||||||
self.current_node.save_contents()
|
|
||||||
else:
|
else:
|
||||||
if node is None:
|
if node is None:
|
||||||
self.current_node = \
|
self.current_node = \
|
||||||
@@ -349,12 +356,13 @@ class FastParser(use_metaclass(CachedFastParser)):
|
|||||||
|
|
||||||
is_first = False
|
is_first = False
|
||||||
else:
|
else:
|
||||||
print '#'*45, self._line_offset, p.end_pos, 'theheck\n', code_part
|
#print '#'*45, self._line_offset, p.end_pos, 'theheck\n', code_part
|
||||||
|
pass
|
||||||
|
|
||||||
self._line_offset += lines
|
self._line_offset += lines
|
||||||
self._start += len(code_part) + 1 # +1 for newline
|
self._start += len(code_part) + 1 # +1 for newline
|
||||||
|
|
||||||
print(self.parsers[0].module.get_code())
|
#print(self.parsers[0].module.get_code())
|
||||||
#for p in self.parsers:
|
#for p in self.parsers:
|
||||||
# print(p.module.get_code())
|
# print(p.module.get_code())
|
||||||
# print(p.module.start_pos, p.module.end_pos)
|
# print(p.module.start_pos, p.module.end_pos)
|
||||||
|
|||||||
Reference in New Issue
Block a user